Beispiel #1
0
 public void Save(IHashObject data)
 {
     using (DbHelper db = AppUtils.CreateDbHelper())
     {
         IHashObject section = db.SelectFirstRow(string.Format("select id, paytotal from backsection where month='{0}-1'", data["tmonth"]));
         if (section == null)
         {
             throw new Exception(string.Format("{0}月不存在回款金额", data["tmonth"]));
         }
         data["datetime"] = DateTime.Now;
         data["id"]       = Cuid.NewCuid();
         data["uid"]      = ((Login.User)Session["user"]).Id;
         data.Remove("tmonth");
         section["paytotal"] = section.GetValue <decimal>("paytotal") + data.GetValue <decimal>("total");
         try
         {
             db.BeginTransaction();
             db.Insert("backsectionDetail", data);
             db.Update("backsection", "id", section);//更新金额
             db.CommitTransaction();
         }
         catch (Exception e)
         {
             if (db.HasBegunTransaction)
             {
                 db.RollbackTransaction();
             }
         }
     }
 }
Beispiel #2
0
 public IHashObject GetTotal(string month)
 {
     using (DbHelper db = AppUtils.CreateDbHelper())
     {
         return(db.SelectFirstRow(string.Format("select total, paytotal from backsection where month='{0}-1'", month)));
     }
 }
Beispiel #3
0
 public void Save(string user, object[] grid)
 {
     using (DbHelper db = AppUtils.CreateDbHelper())
     {
         StringBuilder sbuilder = new StringBuilder("insert into commissionrate (crid,color,size,sourceTitle,rate,uname) values");
         foreach (HashObject hash in grid)
         {
             sbuilder.AppendFormat("({0},'{1}','{2}','{3}',{4},'{5}'),", Cuid.NewCuid(), hash["color"], hash["size"], hash["sourceTitle"], hash["rate"], hash["uname"]);
         }
         db.BatchExecute(sbuilder.ToString().Substring(0, sbuilder.Length - 1));
         DataCatchSave.ClearUserGoodsCache(user);
         Login login = new Login();
         login.ReBillCatch(user);
     }
 }
Beispiel #4
0
        public void Save(IHashObject data)
        {
            using (DbHelper db = AppUtils.CreateDbHelper())
            {
                data["datetime"] = DateTime.Now;
                data["id"]       = Cuid.NewCuid();
                data["uid"]      = ((Login.User)Session["user"]).Id;

                IHashObject section = db.SelectFirstRow(string.Format("select id from backsectionDetail where month='{0}'", data["month"]));
                if (section != null)
                {
                    throw new Exception(string.Format("{0}月已设置回款金额,如需继续,请联系管理员", data["month"]));
                }
                db.Insert("backsection", data);
            }
        }
Beispiel #5
0
 public void DoSure(int id)
 {
     using (DbHelper db = AppUtils.CreateDbHelper())
     {
         try
         {
             db.BeginTransaction();
             db.AddParameter("id", id);
             int i = db.ExecuteNonQuerySQL("update bill set status = 3, goodsstatus=1 where id=@id and status <= 3");
             if (i == 1)
             {
                 db.AddParameter("id", id);
                 db.ExecuteNonQuerySQL("update billdetail set goodsstatus = 2 where bid in (select id from bill where id=@id)");
             }
             db.CommitTransaction();
         }
         catch (Exception e)
         {
             db.RollbackTransaction();
             throw e;
         }
     }
 }
Beispiel #6
0
        public static void Init()
        {
            JavaScriptSerializer serializer = JavaScriptSerializer.CreateInstance();

            socket.On(Socket.EVENT_CONNECT, () =>
            {
                IsConnected   = true;
                Data data     = new Data("server");
                data.comefrom = "net";
                socket.Emit("login", serializer.Serialize(data));
            });
            socket.On("postDataRequest", (data) =>
            {
                HashObject hash = serializer.Deserialize <HashObject>(data.ToString());
                SendMsg nmsg    = new SendMsg("server");
                nmsg.comefrom   = "net";
                nmsg.touid      = hash.GetValue <string>("fuid");
                ulong key       = Cuid.NewCuid();
                Counter counter = new Counter();
                counter.All     = hash.GetValue <ulong>("msg");
                counter.Doned   = 0;
                PostDataRequestList.Add(key, counter);
                nmsg.msg = key.ToString();//回传一个唯一标记
                socket.Emit("postDataSure", serializer.Serialize(nmsg));
            });
            socket.On("consultationEnabledUpdate", (data) =>//咨询是否允许更新
            {
                HashObject hash = serializer.Deserialize <HashObject>(data.ToString());
                SendMsg nmsg    = new SendMsg("server");
                nmsg.comefrom   = "net";
                nmsg.touid      = hash.GetValue <string>("fuid");

                string key = hash.GetValue <string>("msg");
                nmsg.msg   = WebInterface.SureUpdateIds.Contains(key) ? "1" : "0";
                WebInterface.SureUpdateIds.Remove(key);
                socket.Emit("sureEnabledUpdate", serializer.Serialize(nmsg)); //确认可以做什么操作
            });
            socket.On("getLoginToken", (data) =>                              //客户端登录
            {
                HashObject hash = serializer.Deserialize <HashObject>(data.ToString());
                SendMsg nmsg    = new SendMsg("server");
                nmsg.comefrom   = "net";
                nmsg.touid      = hash.GetValue <string>("fuid");
                try
                {
                    string key = Guid.NewGuid().ToString().Replace("-", "");
                    nmsg.msg   = key;
                    using (DbHelper db = AppUtils.CreateDbHelper())
                    {
                        string sql = "insert into logintoken (`user`, `token`,updatedate) values(@user, @token,@updatedate) on duplicate key update `token` = values(`token`),`updatedate` = values(`updatedate`);";
                        db.AddParameter("user", hash.GetValue <string>("msg"));
                        db.AddParameter("token", key);
                        db.AddParameter("updatedate", DateTime.Now);
                        db.ExecuteIntSQL(sql);
                    }
                    socket.Emit("sendLoginToken", serializer.Serialize(nmsg));//确认可以做什么操作
                }
                catch (Exception e)
                {
                    nmsg.msg = string.Format("Exception:{0}", e.Message);
                    socket.Emit("sendLoginToken", serializer.Serialize(nmsg));//确认可以做什么操作
                }
            });
            socket.On("getDownDataToken", (data) =>
            {
                HashObject hash = serializer.Deserialize <HashObject>(data.ToString());
                SendMsg nmsg    = new SendMsg("server");
                nmsg.comefrom   = "net";
                nmsg.touid      = hash.GetValue <string>("fuid");

                try
                {
                    string key           = Guid.NewGuid().ToString().Replace("-", "");
                    nmsg.msg             = key;
                    string conditionMsg  = hash.GetValue <string>("msg");
                    HashObject condition = serializer.Deserialize <HashObject>(conditionMsg);
                    using (DbHelper db = AppUtils.CreateDbHelper())
                    {
                        string sql = "insert into downtoken (`user`, `token`,getDate, `condition`) values(@user, @token,@getDate, @condition) on duplicate key update `token` = values(`token`),`getDate` = values(`getDate`),`condition` = values(`condition`);";
                        db.AddParameter("user", condition.GetValue <string>("user"));
                        db.AddParameter("token", key);
                        db.AddParameter("getDate", DateTime.Now);
                        db.AddParameter("condition", conditionMsg);
                        db.ExecuteIntSQL(sql);
                    }
                    socket.Emit("sendDownDataToken", serializer.Serialize(nmsg));//确认可以做什么操作
                }
                catch (Exception e)
                {
                    nmsg.msg = string.Format("Exception:{0}", e.Message);
                    socket.Emit("sendLoginToken", serializer.Serialize(nmsg));//确认可以做什么操作
                }
            });
            IsConnected = false;
        }
Beispiel #7
0
        private DataTable GetNeedMatchRateGoods(string suser)
        {
            DataTable            changedTable;
            DataTable            table      = TaobaoDataHelper.SpliteContentToDataTableByUser(suser, AppUtils.ConnectionString, true);
            JavaScriptSerializer serializer = JavaScriptSerializer.CreateInstance();

            using (DbHelper db = AppUtils.CreateDbHelper())
            {
                List <CommissionRateStruct> list = new List <CommissionRateStruct>();
                Dictionary <string, Dictionary <string, List <string> > > dictionary = new Dictionary <string, Dictionary <string, List <string> > >();
                foreach (DataRow row in table.Rows)
                {
                    GoodsInfo[] ginfos = serializer.Deserialize <GoodsInfo[]>(row["货物信息"].ToString());

                    foreach (GoodsInfo ginfo in ginfos)
                    {
                        CommissionRateStruct crstruct = new CommissionRateStruct();
                        crstruct.Color       = ginfo.Color;
                        crstruct.Size        = ginfo.Size;
                        crstruct.SourceTitle = ginfo.Title;
                        crstruct.User        = row["所属用户"].ToString();
                        if (list.Contains(crstruct))
                        {
                            continue;
                        }
                        list.Add(crstruct);
                    }
                }

                IHashObjectList commList = db.Select("select color,size,sourceTitle, uname, rate from commissionrate");
                foreach (HashObject commItem in commList)
                {
                    CommissionRateStruct crstruct = new CommissionRateStruct();
                    crstruct.Color       = commItem.GetValue <string>("color");
                    crstruct.Size        = commItem.GetValue <string>("size");
                    crstruct.SourceTitle = commItem.GetValue <string>("sourcetitle");
                    crstruct.User        = commItem.GetValue <string>("uname");
                    if (list.Contains(crstruct))
                    {
                        list.Remove(crstruct);
                    }
                }

                changedTable = new DataTable();
                changedTable.Columns.Add("color");
                changedTable.Columns.Add("size");
                changedTable.Columns.Add("sourceTitle");
                changedTable.Columns.Add("uname");
                changedTable.Columns.Add("rate");
                changedTable.Columns.Add("crid");
                foreach (CommissionRateStruct item in list)
                {
                    DataRow row = changedTable.NewRow();
                    row["color"]       = item.Color;
                    row["size"]        = item.Size;
                    row["sourceTitle"] = item.SourceTitle;
                    row["uname"]       = item.User;
                    row["rate"]        = item.Rate;
                    changedTable.Rows.Add(row);
                }
                return(changedTable);
            }
        }
Beispiel #8
0
        internal static string SaveData(string suser, CallBackMsg callBack, bool onlyAdd = true)
        {
            DataTable table = TaobaoDataHelper.SpliteContentToDataTableByUser(suser, AppUtils.ConnectionString, true);

            if (table.Rows.Count == 0)
            {
                return("OK:没有需要分析的数据");
            }

            using (DbHelper db = AppUtils.CreateDbHelper())
            {
                try
                {
                    string         ids        = GetTaobaoBillID(table);
                    HashObjectList billList   = new HashObjectList();
                    HashObjectList detailList = new HashObjectList();

                    callBack("开始分析数据");
                    callBack("开始构建数据");

                    BuildBillDataFromTable(suser, onlyAdd, table, billList, detailList, db, ids, false);

                    StringBuilder insertBillDetailBuilder = new StringBuilder(@"insert into billdetail(id, bid, code, size, amount, color, address,area,total, remark, 
                        ltotal,sourceTitle,goodsstatus,sendway, btotal) values");
                    string        sDetailFormate          = "({0}, {1}, '{2}', '{3}', '{4}','{5}', '{6}', '{7}', {8}, '{9}',{10}, '{11}', {12}, '{13}', {14}),";
                    foreach (HashObject item in detailList)
                    {
                        //构建明细数据
                        insertBillDetailBuilder.AppendFormat(sDetailFormate, item["id"], item["bid"], item["code"], item["size"], item["amount"], item["color"], item["address"], item["area"], item["total"], item["remark"], item["ltotal"], item["sourceTitle"], item["goodsstatus"], item["sendway"], item["btotal"]);
                    }

                    string insertBillDetail = insertBillDetailBuilder.ToString();
                    insertBillDetail = insertBillDetail.Substring(0, insertBillDetail.Length - 1);


                    StringBuilder doedIds           = new StringBuilder();//影响到的主数据
                    StringBuilder insertBillBuilder = new StringBuilder(@"insert into bill(id, date, taobaocode,cname,ctel,caddress,carea,cremark,
                        ltotal,status, scode, sname, uid, goodsstatus, billfrom, createdate, zfbpaycode,tbcode, total, btotal, senddate, successdate, `user`) values");
                    foreach (HashObject item in billList)
                    {
                        StringBuilder sformate = new StringBuilder("({0}, '{1}', '{2}', '{3}', '{4}','{5}', '{6}', '{7}', {8}, {9},'{10}', '{11}', {12}, {13}, '{14}','{15}', '{16}', '{17}', {18},{19} ");
                        sformate.Append(IsNullDate(item["senddate"]) ? ",{20}" : ",'{20}'");
                        sformate.Append(IsNullDate(item["successdate"]) ? ",{21}" : ",'{21}'");
                        sformate.Append(",'{22}'");
                        sformate.Append("), ");
                        doedIds.AppendFormat("{0},", item["id"]);
                        //构建主表数据,如果已经存在,直接更改数据
                        insertBillBuilder.AppendFormat(sformate.ToString(), item["id"], item["date"], item["taobaocode"], item["cname"], item["ctel"], item["caddress"], item["carea"], item["cremark"],
                                                       item["ltotal"], item["status"], item["scode"], item["sname"], item["uid"], item["goodsstatus"], item["billfrom"], item["createdate"], item["zfbpaycode"], item["tbcode"], item["total"], item["btotal"], item["senddate"], item["successdate"], suser);
                    }
                    string insertBill = insertBillBuilder.ToString();
                    insertBill = insertBill.Substring(0, insertBill.Length - 2);

                    callBack("构建数据完毕");
                    callBack("开始保存数据");
                    if (billList.Count != 0)
                    {
                        db.BeginTransaction();
                        db.BatchExecute(string.Format("update tbill set hasupdate=0 where bid in {0}", ids));
                        db.BatchExecute(string.Format("{0} on duplicate key update `createdate`=values(`createdate`),`senddate`=values(`senddate`),`successdate`=values(`successdate`),`zfbpaycode`=values(`zfbpaycode`),`status`=values(`status`),`sname`=values(`sname`),`scode`=values(`scode`);", insertBill));
                        if (detailList.Count != 0)
                        {
                            db.BatchExecute(insertBillDetail);//直接新增,不修改
                        }
                        //后期退款的单据,金额都为0
                        db.BatchExecute(string.Format("update bill set ltotal = 0, total=0, btotal=0 where status=9 and id in ({0})", doedIds.ToString().Substring(0, doedIds.Length - 1)));
                        db.CommitTransaction();
                    }
                    return(string.Format("OK:数据保存成功,分析处理了{0}条数据", billList.Count));
                }
                catch (Exception e1)
                {
                    if (db.HasBegunTransaction)
                    {
                        db.RollbackTransaction();
                    }
                    return(string.Format("Exception:{0}", e1.Message));
                }
            }
        }