| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1387 人关注过本帖
标题:[求助]两张表之间的问题
只看楼主 加入收藏
lunly
Rank: 1
等 级:新手上路
帖 子:295
专家分:0
注 册:2007-1-17
收藏
得分:0 

SL_KC.DataBindings.Clear();
DJ1.DataBindings.Clear();
RQs.Value = DateTime.Now;
SM.DataBindings.Clear();
BM.DataBindings.Clear();
GYS1.DataBindings.Clear();
GYS.DataBindings.Clear();
string us = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\My Documents\\huixinERP\\obj\\Release\\data\\path.mdb";
string sele12 = "SELECT * from users where ID='" + ZH.Text + "'and Passwork='" + MM.Text +"'";
string ll = path.Text;
string la = "SELECT * from KC_YLC where 品牌='" + PP.Text +"' and 克重="+KZ.Text+ "and 原料种类='" + YLZL.Text+"'and 规格='"+GG.Text+"'";
OleDbConnection con = new OleDbConnection(us);
OleDbDataAdapter dat = new OleDbDataAdapter(sele12, con);
DataSet datas = new DataSet();
con.Open();
dat.Fill(datas, "users");
con.Close();
SM.DataBindings.Add("Text", datas, "users.姓名");
BM.DataBindings.Add("Text", datas, "users.部门");
OleDbConnection con1 = new OleDbConnection(ll);
OleDbDataAdapter dat1 = new OleDbDataAdapter(la, con1);
DataSet datap = new DataSet();
con1.Open();
dat1.Fill(datap, "KC_YLC");
con1.Close();
DJ1.DataBindings.Add("Text",datap,"KC_YLC.单价");
GYS1.DataBindings.Add("Text", datap, "KC_YLC.供应商");
if (BM.Text == "资财部")
{
if (SL.Text != "" && SL1.Text != "")
{
int a = Convert.ToInt32(SL.Text);
int b = Convert.ToInt32(SL1.Text);
int ab = a - b;
if (ab < 0)
{
MessageBox.Show("请输入正确数量", "提示", MessageBoxButtons.OK);
}
if (ab >=0)
{
if (a > 0)
{
int ac = Convert.ToInt32(SLWD.Text) + Convert.ToInt32(SL1.Text);
int ad = Convert.ToInt32(SL0.Text) - ac;
string sql = path.Text;
string le = "已成工入库,采购单号为(" + BH.Text + ")数量为(" + SL1.Text + ") 此采购单还有(" + ad + ")未到货";
string sele = "UPDATE CG SET 已到货数量=" + ac + ",未到货数量=" + ad + " where 采购编号=" + BH.Text + "and 已到货='未'";
string sele1 = "INSERT INTO RK_YLC (原料种类,入库编号,品牌,克重,规格,数量,单位,单价,日期,登记人,供应商";
string sele2 = ") VALUES ( '" + YLZL.Text + "'," + RKBH.Text + ",'" + PP.Text + "',"+KZ.Text+",'" + GG.Text + "'," + SL1.Text + ",'" + DW.Text + "','" + DJ.Text + "','" + RQs.Text + "','" + SM.Text + "','"+GYS.Text+"'";
if (BZ.Text != "")
{
sele1 += ",备注";
sele2 += ",'" + BZ.Text + "'";
}
string sele3 = sele1 + sele2 + ")";
OleDbConnection conn = new OleDbConnection(sql);
conn.Open();
OleDbCommand comm = new OleDbCommand(sele, conn);
comm.ExecuteNonQuery();
OleDbCommand comm1 = new OleDbCommand(sele3, conn);
comm1.ExecuteNonQuery();
conn.Close();
MessageBox.Show(le, "完成", MessageBoxButtons.OK);
}
if (ab == 0)
{
string sqq = path.Text;
string sqq1 = "UPDATE CG SET 已到货='是',到货日期='" + RQs.Text + "' where 采购编号=" + BH.Text;
OleDbConnection con2 = new OleDbConnection(sqq);
con2.Open();
OleDbCommand comm4 = new OleDbCommand(sqq1, con2);
comm4.ExecuteNonQuery();
con2.Close();
}

if (DJ.Text==DJ1.Text&&GYS1.Text==GYS.Text)
{
SL_KC.DataBindings.Add("Text", datap, "KC_YLC.数量");
int v = Convert.ToInt32(SL1.Text) + Convert.ToInt32(SL_KC.Text);
SL_KC.Text = Convert.ToString(v);
string lc = "UPDATE KC_YLC SET 数量=" + SL_KC.Text + ",日期='" + RQs.Text + "' where 品牌='" + PP.Text + "' and 克重="+KZ.Text+" and 原料种类='" + YLZL.Text + "' and 规格='" + GG.Text + "' and 单价="+DJ1.Text;
OleDbConnection connn1 = new OleDbConnection(ll);
connn1.Open();
OleDbCommand comj = new OleDbCommand(lc, connn1);
comj.ExecuteNonQuery();
connn1.Close();
}
else
{
string lc = "INSERT INTO KC_YLC (供应商,品牌,克重,原料种类,规格,单位,数量,单价,日期) VALUES('";
lc +=GYS.Text+"','"+ PP.Text +"', "+KZ.Text+",'" + YLZL.Text + "','" + GG.Text + "','" + DW.Text + "'," + SL1.Text + "," + DJ.Text + ",'" + RQ1.Text + "')";
OleDbConnection connn1 = new OleDbConnection(ll);
connn1.Open();
OleDbCommand comj = new OleDbCommand(lc, connn1);
comj.ExecuteNonQuery();
connn1.Close();
}
}
}
else
{
MessageBox.Show("请输入正确数量", "提示", MessageBoxButtons.OK);
}
}
else
{
MessageBox.Show("请输入正确的帐号与密码", "提示", MessageBoxButtons.OK);
}
string sqlm = path.Text;
string selem = "SELECT 采购编号,申请日期,原料种类,品牌,克重,规格,已到货数量,未到货数量,数量,单价,申请人 from CG where 已到货='未'";
OleDbConnection connm = new OleDbConnection(sqlm);
OleDbDataAdapter dataa = new OleDbDataAdapter(selem, connm);
DataSet dataset1 = new DataSet();
connm.Open();
dataa.Fill(dataset1, "CG");
int baa = Convert.ToInt32(RKBH.Text);
baa += 1;
RKBH.Text = Convert.ToString(baa);
string selen = "UPDATE RKBH SET 入库编号=" + RKBH.Text;
OleDbCommand comms = new OleDbCommand(selen, connm);
comms.ExecuteNonQuery();
connm.Close();
dataGrid2.SetDataBinding(dataset1, "CG");
YLZL.Text = "";
PP.Text = "";
GG.Text = "";
SL.Text = "";
DW.Text = "";
DJ.Text = "";
BH.Text = "";
KZ.Text = "";

照这个去做准没错


2007-01-22 14:29
yigedaizi
Rank: 1
等 级:新手上路
帖 子:123
专家分:0
注 册:2006-11-24
收藏
得分:0 

谢谢bygg 也谢谢大家。好了。
平时都是只做一张表的练习。这次发现了什么是要学习的了。感觉自己写的东西就是一团乱啊。


layman on C#
2007-01-22 15:59
老兵
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-1-21
收藏
得分:0 
以下是引用YSKING在2007-1-22 12:34:30的发言:
在数据库中存储与该商品相关的数量,也就是添加一个字段。然后进货时如果货物一样,就只更新数量不就行了

假设我要查询某一天的进货清单及进货数量怎么办?


2007-01-22 16:46
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
楼主,希望你多用用类之类的东西,你看一下你写的那个代码,里面出现了多少次数据库的连接.....呵呵..加油!

飘过~~
2007-01-22 17:54
lunly
Rank: 1
等 级:新手上路
帖 子:295
专家分:0
注 册:2007-1-17
收藏
得分:0 
bygg说得对,像这种仓库库存的,入库时点一下就得打开二个表导出,对比,导入/更新.多做多学,一起成功呵呵

2007-01-23 09:02
快速回复:[求助]两张表之间的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017363 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved