Exemple #1
0
            public void ThreadProc()
            {
                DBOperation dbo = new DBOperation();
                YouGeWebApi ygw = new YouGeWebApi();

                if (string.IsNullOrEmpty(_book_id))
                {
                    throw new Exception("book_id is null!");
                }
                if (string.IsNullOrEmpty(_price))
                {
                    throw new Exception("price is null!");
                }
                //判断本地是否有相同book_id和price的交易记录,如果有就全部同步成一个mallid,不要再上报给喵校园主库
                string sql = string.Format("SELECT tt_bookinfo.id,tt_sellinfo.mallid FROM tt_bookinfo ,tt_sellinfo WHERE tt_bookinfo.id " +
                                           "= tt_sellinfo.bookid AND tt_bookinfo.gbookid ='{0}' AND ABS(tt_sellinfo.price- {1}) < 1e-5  AND tt_sellinfo.mallid IS NOT NULL",
                                           _book_id, _price);
                DataTable dt = dbo.Selectinfo(sql);

                //如果有,则直接全部更新一次mallid,不用上报给喵校园主库
                if (dt.Rows.Count > 0)
                {
                    sql = string.Format("UPDATE tt_sellinfo SET mallid = '{0}' WHERE bookid = '{1}' AND ABS(price- {2}) < 1e-5",
                                        dt.Rows[0]["mallid"].ToString(), dt.Rows[0]["id"].ToString(), _price);
                    dbo.AddDelUpdate(sql);
                    return;
                }
                //如果没有,则添加到喵校园主库,返回交易ID后,同步到每一条符合条件的交易中
                string sellinfoid;//喵校园交易ID
                IDictionary <string, string> parameters = new Dictionary <string, string>();

                parameters.Add("book_id", _book_id);
                parameters.Add("price", _price);
                parameters.Add("seller_id", Properties.Settings.Default.sellerid);
                if (ygw.InsertNewSellInfo(parameters, out sellinfoid))
                {
                    sql = string.Format("UPDATE tt_sellinfo SET mallid = '{0}' WHERE bookid = '{1}' AND ABS(price- {2}) < 1e-5",
                                        sellinfoid, _local_book_id, _price);
                    dbo.AddDelUpdate(sql);
                    MessageBox.Show("执行完成");
                    return;
                }
                else
                {
                    MyOperation.DebugPrint("Insert Error!", 3);
                    throw new Exception("Insert Error!");
                }
            }
            public void ThreadProc()
            {
                DBOperation     dbo = new DBOperation();
                YouGeWebApi     yg  = new YouGeWebApi();
                YouGeWinformApi ygw = new YouGeWinformApi();

                if (string.IsNullOrEmpty(_local_book_id))
                {
                    throw new Exception("local_book_id is null!");
                }
                string sql = string.Format("SELECT b.gbookid,b.id,o.mallid FROM yg_oldbookdetail AS o ,yg_bookinfo AS b " +
                                           " WHERE o.bookid = b.id AND o.bookid = '{0}' AND ABS(o.price-{1}) < 1e-5 AND " +
                                           "o.mallid IS NOT NULL", _local_book_id, _price);
                DataTable dt = dbo.Selectinfo(sql);

                if (dt.Rows.Count > 0)
                {
                    //说明已经有相同图书ID以及价格的交易信息,直接把mallid同步过来
                    sql = string.Format("UPDATE yg_oldbookdetail SET mallid = '{0}' WHERE bookid = '{1}'  AND ABS(price- {2}) < 1e-5 ", dt.Rows[0]["mallid"].ToString(), _local_book_id, _price);
                    dbo.AddDelUpdate(sql);
                    MyOperation.DebugPrint("本地已经有相同交易信息");
                    return;
                }
                sql = string.Format("SELECT b.gbookid,b.id,o.mallid FROM yg_oldbookdetail AS o ,yg_bookinfo AS b " +
                                    " WHERE o.bookid = b.id AND o.bookid = '{0}' AND ABS(o.price-{1}) < 1e-5", _local_book_id, _price);
                dt = dbo.Selectinfo(sql);
                //如果没有,则添加到喵校园主库,返回交易ID后,同步到每一条符合条件的交易中
                IDictionary <string, string> parameters = new Dictionary <string, string>();

                parameters.Add("book_id", dt.Rows[0]["gbookid"].ToString());
                parameters.Add("seller_id", ygw.GetLocalShopId());
                parameters.Add("price", _price);
                string gsellinfoid;//喵校园交易ID

                if (yg.InsertNewSellInfo(parameters, out gsellinfoid))
                {
                    sql = string.Format("UPDATE yg_oldbookdetail SET mallid = '{0}' WHERE bookid = '{1}'  AND ABS(price- {2}) < 1e-5 ", gsellinfoid, _local_book_id, _price);
                    dbo.AddDelUpdate(sql);
                }
                else
                {
                    MyOperation.DebugPrint("Insert Error!", 3);
                    throw new Exception("Insert Error!");
                }
            }
 void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
 {
     try
     {
         string sellinfoid = e.ToString();
         //需要先判断本地是否还有尚未出售的交易
         string    sql = string.Format("SELECT bookid,price, mallid FROM tt_sellinfo WHERE sellinfoid = '{0}'", sellinfoid);
         DataTable dt  = dbo.Selectinfo(sql);
         if (dt.Rows.Count != 1)
         {
             //不等于1说明传进来的sellinfoid就有问题,直接异常
             MyOperation.DebugPrint("出售图书时,传入的sellinfoid异常:" + sellinfoid, 3);
             return;
         }
         string mallid = dt.Rows[0]["mallid"].ToString();
         sql = string.Format("SELECT mallid FROM tt_sellinfo WHERE issold = '0' AND mallid IS NOT NULL AND bookid = '{0}' AND price = '{1}'",
                             dt.Rows[0]["bookid"].ToString(), dt.Rows[0]["price"].ToString());
         dt = dbo.Selectinfo(sql);
         //如果有就不需要上报给喵校园,不需要任何处理,直接返回
         if (dt.Rows.Count > 0)
         {
             return;
         }
         //如果没有就上报给喵校园主库
         else if (!string.IsNullOrEmpty(mallid))
         {
             IDictionary <string, string> parameters = new Dictionary <string, string>();
             parameters.Add("status", "1");
             parameters.Add("id", mallid);
             ygw.InsertNewSellInfo(parameters, out sellinfoid);
         }
         else
         {
             MyOperation.DebugPrint("存在尚未出售但是没有mallid的交易信息:" + sellinfoid, 3);
         }
     }
     catch (Exception ex)
     {
         MyOperation.DebugPrint(ex.Message, 3);
     }
 }
        void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            string    sql;
            DataTable dt;
            int       i;
            IDictionary <string, string> parameters;
            string sellid;

            while (true)
            {
                //线上书主信息导入本地
                sql = "SELECT * FROM tt_sellerinfo";
                dt  = dbo.Selectinfo(sql);
                ExcelOperation.dataTableToCsv(dt, "LocalSellerInfo.csv", false);
                //Thread.Sleep(3600 * 1000);//间隔1小时

                //本地对线上同步
                sql = "SELECT DISTINCT s.bookid,b.gbookid,s.price,s.mallid FROM tt_bookinfo AS b ,tt_sellinfo AS s WHERE b.isbn not like '1000000%' AND b.id = s.bookid AND s.issold = 0";
                dt  = dbo.Selectinfo(sql);
                for (i = 0; i < dt.Rows.Count; i++)
                {
                    if (!ygw.IsExistSellInfo(dt.Rows[i]["mallid"].ToString(), dt.Rows[i]["gbookid"].ToString(), dt.Rows[i]["price"].ToString()))
                    {
                        parameters = new Dictionary <string, string>();
                        parameters.Add("book_id", dt.Rows[i]["gbookid"].ToString());
                        parameters.Add("seller_id", Properties.Settings.Default.sellerid);
                        parameters.Add("price", dt.Rows[i]["price"].ToString());
                        sellid = null;
                        if (ygw.InsertNewSellInfo(parameters, out sellid))
                        {
                            sql = string.Format("UPDATE tt_sellinfo SET mallid = '{0}' WHERE bookid = '{1}' AND  ABS(price- {2}) < 1e-5", sellid, dt.Rows[i]["bookid"].ToString(), dt.Rows[i]["price"].ToString());
                            dbo.AddDelUpdate(sql);
                        }
                    }
                }
                Thread.Sleep(3600 * 1000); //间隔1小时

                //线上对本地同步
                Thread.Sleep(3600 * 1000);//执行完毕延时1小时
            }
        }
 void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
 {
     try
     {
         string[]  Args = e.ToString().Split('|');
         string    sql  = string.Format("SELECT mallid FROM tt_sellinfo WHERE sellinfoid = '{0}'", Args[0]);
         DataTable dt   = dbo.Selectinfo(sql);
         if (dt.Rows.Count == 1)
         {
             IDictionary <string, string> parameters = new Dictionary <string, string>();
             parameters.Add("price", Args[1]);
             parameters.Add("id", dt.Rows[0]["mallid"].ToString());
             string tmp;
             ygw.InsertNewSellInfo(parameters, out tmp);
         }
     }
     catch (Exception ex)
     {
         MyOperation.DebugPrint(ex.Message, 3);
     }
 }