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!"); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { string sql = "SHOW TABLES LIKE '%yg_local_shopinfo%'"; DBOperation dbo = new DBOperation(); DataTable dt = dbo.Selectinfo(sql); if (1 != dt.Rows.Count) { Application.Run(new 登录页面()); } else { Application.Run(new 主页面()); } } catch (Exception e) { MessageBox.Show("程序启动异常,Msg=" + e.Message); } }