Exemple #1
0
        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 });
        }
Exemple #2
0
 public void DoAction(StrDictionary sd)
 {
     EasyUITable etb = new EasyUITable();
     etb.Parse(sd["data"]);
     BillPrinter.Print(etb.Table, sd);
 }
Exemple #3
0
        public void DoAction(StrDictionary sd)
        {
            EasyUITable etb = new EasyUITable();
            etb.Parse(sd["data"]);
            etb.Table.TableName = sd["table"];
            etb.Table.AcceptChanges();
            if (etb.Table.Columns.Contains("id") == false)
            {
                GlobalVar.Log.LogError("找不到id字段", "UpdateAction");
                throw new Exception();
            }
            GlobalVar.DBHelper.AddUpdate(sd["table"], sd["fields"], "id");
            GlobalVar.DBHelper.AddInsert(sd["table"], sd["fields"]);
            GlobalVar.DBHelper.AddDelete(sd["table"], "id");
            string[] delIds = sd["delids"].Split(new char[] { ',' });

            foreach (DataRow r in etb.Table.Rows)
            {
                string id = r.Field<string>("id");
                if (String.IsNullOrEmpty(id))//新增记录
                {
                    r["id"] = null;//不设为null,插入时失败
                    if (sd.ContainsKey("statusfield") &&
                        etb.Table.Columns.Contains(sd["statusfield"]) &&
                        String.IsNullOrEmpty(r.Field<String>(sd["statusfield"])))
                        r.SetField<int>(sd["statusfield"], 0);

                    r.AcceptChanges();
                    r.SetAdded();
                }
                else if (delIds.Contains(id))//删除记录
                {
                    if (sd.ContainsKey("statusfield"))
                    {
                        r.SetField<char>(sd["statusfield"], '1');
                    }
                    else
                        r.Delete();
                }
                else
                {
                    r.SetModified();//更新记录
                }
            }
            int cnt = GlobalVar.DBHelper.Update(etb.Table);
            if (cnt > 0 && sd.ContainsKey("invoke"))
            {
                GlobalVar.Container.InvokeScript(sd["invoke"], null);
            }
            if (cnt > 0)
                MessageBox.Show("更新成功!");
            else
                MessageBox.Show("更新失败,请查看日志!");
        }