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 = "";
照这个去做准没错