private void btnPayback_Click(object sender, EventArgs e) { if(nudAmt.Value == 0) { MessageBox.Show("金额不能0"); return; } if(tbMark.Text.Trim() == "") { MessageBox.Show("备注不能为空"); return; } //MessageBox.Show(_id); GlobalVar.DBHelper.AddInsert("debtdetail", "main_seqnbr,billseq,opr,type,amount,mark,seqnbr"); DataTable tbl = new DataTable(); tbl.Init("debtdetail", "main_seqnbr,billseq,opr,type,amount,mark,seqnbr"); DataRow r = tbl.NewRow(); r.SetField<long>("seqnbr", DateTime.Now.Ticks); r.SetField<string>("opr", GlobalVar.LogInfo.WorkCode); r.SetField<string>("type", "B");//还款 r.SetField<string>("billseq", ""); r.SetField<string>("main_seqnbr", _mainseqnbr); r.SetField<string>("mark", tbMark.Text.Trim()); r.SetField<string>("amount", nudAmt.Value.ToString()); tbl.Rows.Add(r); GlobalVar.DBHelper.Update(tbl); DialogResult = DialogResult.OK; }
private void btnAdd_Click(object sender, EventArgs e) { DataTable tbl = new DataTable(); string fields = "productid,name,innerid,price,cost,colornum,position,storenum,packagenum,size,opr"; tbl.Init("products", fields); DataRow row = tbl.NewRow(); if (IntiRow(row) == false) return; tbl.Rows.Add(row); GlobalVar.DBHelper.AddInsert(tbl.TableName, fields); if(GlobalVar.DBHelper.Update(tbl) == 1) { MessageBox.Show("添加成功"); DialogResult = DialogResult.OK; }else { MessageBox.Show("添加失败,请检查日志!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void DoAction(StrDictionary sd) { int num = Convert.ToInt32(sd["num"]); string fields = "mark,num,seqnbr,type,productid,finalstore,opr,customer"; GlobalVar.DBHelper.AddInsert("storenumhistory", fields); GlobalVar.DBHelper.AddUpdate("products", "id,storenum", "id"); DefaultAction.StoreChangeFrm frm = new DefaultAction.StoreChangeFrm(num); if (frm.ShowDialog() == DialogResult.OK) { DataTable his = new DataTable(); DataTable upt = new DataTable(); his.Init("storenumhistory", fields); upt.Init("products", "id,storenum,actcnt"); //Products表更新 DataRow r = upt.NewRow(); decimal final = frm.Value; if (frm.OprType == 'I')//进货 final = num + frm.Value; else if (frm.OprType == 'O')//出货 final = num - frm.Value; r.SetField<string>("id", sd["data"]); r.SetField<decimal>("storenum", final); upt.Rows.Add(r); r.AcceptChanges(); r.SetModified(); DataSet ds = new DataSet(); int want = 2;//理想影响条数 r = his.NewRow(); //storenumhistory 表增加记录 r.SetField<string>("mark", frm.Mark); r.SetField<decimal>("finalstore", final); if (frm.OprType == 'M') r.SetField<decimal>("num", num); else r.SetField<decimal>("num", frm.Value); r.SetField<long>("seqnbr", DateTime.Now.Ticks); r.SetField<char>("type", frm.OprType); r.SetField<string>("productid", sd["data"]); r.SetField<string>("opr", GlobalVar.LogInfo.WorkCode); r.SetField<string>("customer", frm.Customer); his.Rows.Add(r); ds.Tables.Add(his); ds.Tables.Add(upt); int rst = GlobalVar.DBHelper.Update(ds, "storenumhistory,products"); try { GlobalVar.DBHelper.ExcuteNonQuery("update products set actcnt=actcnt+1 where id=" + sd["data"]); } catch (Exception) { } GlobalVar.Container.InvokeScript("updateStoreNum", new object[] { final, rst == want }); } }
private DataTable FilterForsingle(DataTable tbl) { DataTable rst = new DataTable(); StrDictionary sd = new StrDictionary(); rst.Init("", "item,price"); foreach (DataRow r in tbl.Rows) { string item = r.Field<string>("innerid"); if (String.IsNullOrEmpty(item)) item = r.Field<string>("productid"); item += " - "; item += r.Field<string>("colornum"); if (sd.ContainsKey(item) == false) { sd[item] = ""; DataRow nr = rst.NewRow(); nr.SetField<string>("item", item); nr.SetField<decimal>("price", r.Field<decimal>("saleprice")); rst.Rows.Add(nr); } } return rst; }
public void DoAction(StrDictionary sd) { GlobalVar.DBHelper.BeginBatch(); string oriId = null;//原id //修改订单,先将之前的信息冲掉 if (sd["oprtype"].Equals("modify")) { //保存原id GlobalVar.DBHelper.AddCustomParam("@seqnbr", sd["seqnbr"]); oriId = Convert.ToString(GlobalVar.DBHelper.ExcuteForUnique("select id from bills where seqnbr=@seqnbr", true)); if (!restoreBalance(sd["seqnbr"])) { MessageBox.Show("修改订单失败"); GlobalVar.DBHelper.EndBatch(true);//异常强制回滚 return; } }else if(sd["oprtype"].Equals("delete")) { //删除账单,并回滚库存及相关记录 bool success = restoreBalance(sd["seqnbr"]); GlobalVar.DBHelper.EndBatch(!success); GlobalVar.Container.InvokeScript(sd["invoke"],new object[]{success}); return; } string oprcode = sd["operator"]; GlobalVar.DBHelper.AddInsert("billitem", "productid,num,type,saleoff,mark,seqnbr,saleprice,c_num"); GlobalVar.DBHelper.AddInsert("bills", "id,seqnbr,payer,purunit,mobile,pid,operator,pagecode,type"); //billitem表 EasyUITable etb = new EasyUITable(); etb.Parse(sd["data"]); DateTime dtNow = DateTime.Now; long billseq = dtNow.Ticks; if (sd.ContainsKey("seqnbr") && sd["seqnbr"] != null && !sd["seqnbr"].Equals(String.Empty)) { billseq = Convert.ToInt64(sd["seqnbr"]); } etb.Table.Columns.Add("seqnbr"); foreach (DataRow r in etb.Table.Rows) { r.SetField<long>("seqnbr", billseq); r.AcceptChanges(); r.SetAdded(); } etb.Table.TableName = "billitem"; //bills 表 DataTable tbBill = new DataTable(); tbBill.Init("bills", "id,seqnbr,operator,mobile,payer,pid,purunit,pagecode,type"); DataRow row = tbBill.NewRow(); if (oriId != null) row.SetField<long>("id", Convert.ToInt64(oriId)); row.SetField<long>("seqnbr", billseq); row.SetField<string>("operator", oprcode); row.SetField<string>("mobile", sd["mobile"]); row.SetField<string>("payer", sd["payer"]); row.SetField<string>("purunit", sd["purunit"]); row.SetField<string>("pid", sd["pid"]); row.SetField<string>("pagecode", sd["pagecode"]); row.SetField<string>("type", sd["type"]); tbBill.Rows.Add(row); //products 表 string idset = GetIdSet(etb.Table, "productid"); DataTable tbProd = new DataTable("products"); GlobalVar.DBHelper.AddSelectWithLimit("products", "id,storenum", "id IN " + idset); GlobalVar.DBHelper.AddUpdate("products", "id,storenum,size,position", "id"); GlobalVar.DBHelper.Fill(ref tbProd); //storehistory表 GlobalVar.DBHelper.AddInsert("storenumhistory", "mark,num,billseqnbr,seqnbr,type,productid,finalstore,opr,customer"); DataTable tblHis = new DataTable(); tblHis.Init("storenumhistory", "mark,num,billseqnbr,seqnbr,type,productid,finalstore,opr,customer"); //账务明细表 GlobalVar.DBHelper.AddInsert("debtdetail", "main_seqnbr,billseq,opr,mark,seqnbr,amount,type"); DataTable tblDebt = new DataTable(); tblDebt.Init("debtdetail", "main_seqnbr,billseq,seqnbr,opr,mark,date,amount,type"); DataRow debtrow = tblDebt.NewRow(); debtrow.SetField<string>("opr", oprcode); debtrow.SetField<long>("seqnbr", dtNow.Ticks); debtrow.SetField<string>("amount", sd["amount"]); debtrow.SetField<string>("type", sd["type"]); debtrow.SetField<string>("main_seqnbr", billseq.ToString()); debtrow.SetField<string>("billseq", billseq.ToString()); if (sd["pid"] != "0") { string mainSeqnbr = GlobalVar.DBHelper.ExcuteForUnique<string>("select seqnbr from bills where id=" + sd["pid"]); debtrow.SetField<string>("main_seqnbr", mainSeqnbr); } tblDebt.Rows.Add(debtrow); //平衡货品数量 Balance(etb.Table, tbProd, tblHis, sd, billseq); DataSet ds = new DataSet(); ds.Tables.AddRange(new DataTable[] { etb.Table, tbProd, tbBill, tblHis, tblDebt }); //新增账单数据 更新货品数据 int ret = GlobalVar.DBHelper.Update(ds, "billitem,products,bills,storenumhistory,debtdetail"); //int ret = GlobalVar.DBHelper.Update(ds, "billitem,bills,debtdetail"); if (ret == -1) { GlobalVar.DBHelper.EndBatch(true); GlobalVar.Container.InvokeScript("resultCallback", new object[] { false }); return; } //若更新主单,需同时更新关联的子单 /*if (oriPid != null) { try { GlobalVar.DBHelper.AddCustomParam("@seqnbr", billseq); string newPid = Convert.ToString(GlobalVar.DBHelper.ExcuteForUnique("select id from bills where seqnbr=@seqnbr", true)); GlobalVar.DBHelper.AddCustomParam("@newPid", newPid); GlobalVar.DBHelper.AddCustomParam("@oldPid", oriPid); GlobalVar.DBHelper.ExcuteNonQuery("update bills set pid=@newPid where pid=@oldPid"); GlobalVar.DBHelper.AddCustomParam("@newSeqnbr", dtNow.Ticks); GlobalVar.DBHelper.AddCustomParam("@oldSeqnbr", sd["seqnbr"]); GlobalVar.DBHelper.ExcuteNonQuery("update debtdetail set main_seqnbr=@newSeqnbr where main_seqnbr=@oldSeqnbr"); } catch (Exception e) { GlobalVar.DBHelper.EndBatch(true); GlobalVar.Container.InvokeScript("resultCallback", new object[] { false }); return; } }*/ bool noErr = Utility.ProcessSqlError(ds); GlobalVar.DBHelper.EndBatch(noErr == false); //账单录入版暂不进行打印 //if (noErr) // BillPrinter.Print(etb.Table, sd); GlobalVar.Container.InvokeScript("resultCallback", new object[] { noErr }); }
public void DoAction(StrDictionary sd) { string name = sd["name"]; string psw = sd["psw"]; string oripsw = sd["oripsw"]; if (oripsw.Equals(GlobalVar.LogInfo.Password) == false) { GlobalVar.Container.InvokeScript("cb", new object[] { "密码不正确!" }); return; } if (name != GlobalVar.LogInfo.Name) { GlobalVar.DBHelper.AddCustomParam("@name", name); object n = GlobalVar.DBHelper.ExcuteForUnique("select count(name) from members where name=@name"); if (Convert.ToInt32(n) == 1) { GlobalVar.Container.InvokeScript("cb", new object[] { "用户名已存在!" }); return; } } DataTable tbl = new DataTable(); tbl.Init("members", "name,password,code"); DataRow r = tbl.NewRow(); r.SetField<string>("name", name); r.SetField<string>("password", psw); r.SetField<string>("code", GlobalVar.LogInfo.WorkCode); tbl.Rows.Add(r); r.AcceptChanges(); r.SetModified(); GlobalVar.DBHelper.AddUpdate("members", "name,password", "code"); if (GlobalVar.DBHelper.Update(tbl) != 1) GlobalVar.Container.InvokeScript("cb", new object[] { "用户信息无更新" }); else { GlobalVar.LogInfo.Name = name; GlobalVar.LogInfo.Password = psw; GlobalVar.MainFrame.Visible = false; GlobalVar.MainFrame.Visible = true; GlobalVar.Container.InvokeScript("cb", new object[] { "更新成功" }); } }
public void DoAction(StrDictionary sd) { GlobalVar.DBHelper.AddUpdate("storenumhistory", "customer,mark", "id"); DataTable tbl = new DataTable(); tbl.Init("storenumhistory","customer,mark,id"); DataRow r = tbl.NewRow(); r.SetField<string>("id", sd["id"]); r.SetField<string>("customer", sd["customer"]); r.SetField<string>("mark", sd["mark"]); tbl.Rows.Add(r); r.AcceptChanges(); r.SetModified(); int i = GlobalVar.DBHelper.Update(tbl); GlobalVar.Container.InvokeScript(sd["invoke"], new object[] { i == 1 }); }
public void DoAction(StrDictionary sd) { GlobalVar.DBHelper.AddDelete("products", "id"); GlobalVar.DBHelper.AddInsert("members", "name"); DataSet ds = new DataSet(); DataTable delTbl = new DataTable("products"); DataTable addTbl = new DataTable("members"); delTbl.Init("products", "id"); addTbl.Init("members", "name"); DataRow dr = delTbl.NewRow(); dr.SetField<Int64>("id", 32); delTbl.Rows.Add(dr); delTbl.AcceptChanges(); dr.Delete(); DataRow dr1 = addTbl.NewRow(); dr1.SetField<string>("name", "测试"); addTbl.Rows.Add(dr1); ds.Tables.Add(delTbl); ds.Tables.Add(addTbl); GlobalVar.DBHelper.BeginBatch(); try { GlobalVar.DBHelper.Update(ds, "members,products"); } catch (Exception e) { MessageBox.Show(e.Message); } GlobalVar.DBHelper.EndBatch(); }