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!"); } }
/// <summary> /// 增删改操作 /// </summary> /// <param name="sql">sql语句</param> /// <returns>执行后的条数</returns> public int AddDelUpdate(string sql) { MySqlConnection conn = null; MySqlCommand cmd = null; try { conn = this.GetConn(); conn.Open(); cmd = new MySqlCommand(sql, conn); int i = cmd.ExecuteNonQuery(); conn.Close(); return(i); } catch (Exception ex) { MyOperation.DebugPrint(ex.Message); throw; } }
private void button5_Click(object sender, EventArgs e) { YouGeWinformApi.OrderInfo oi = new YouGeWinformApi.OrderInfo(); oi.datetime = label5.Text; oi.jinhuoqudao = comboBox1.SelectedValue.ToString(); oi.ordername = textBox2.Text; oi.totalprice = textBox4.Text; if (!ygw.InsertNewOrder(oi)) { MessageBox.Show("订单生成过程中出现了错误1!"); return; } string orderid = ygw.GetOrderIdByCreateTime(label5.Text); if (null == orderid) { MessageBox.Show("订单生成过程中出现了错误2!"); return; } for (int i = 0; i < gdt.Rows.Count; i++) { YouGeWinformApi.OrderDetail od = new YouGeWinformApi.OrderDetail(); od.off = gdt.Rows[i]["off"].ToString(); od.orderid = orderid; od.count = gdt.Rows[i]["count"].ToString(); od.bookid = gdt.Rows[i]["id"].ToString(); if (!ygw.InsertOrderDetail(od)) { MessageBox.Show("订单生成过程中出现了错误!"); return; } } MessageBox.Show("订单添加成功!"); gdt.Rows.Clear(); dataGridView2.DataSource = gdt.DefaultView; textBox5.Text = textBox4.Text = textBox3.Text = textBox2.Text = ""; label5.Text = MyOperation.GetNow(); }
/// <summary> /// 查询操作 /// </summary> /// <param name="sql"></param> /// <returns></returns> public DataTable Selectinfo(string sql) { MySqlConnection mysqlconn = null; MySqlDataAdapter sda = null; DataTable dt = null; try { mysqlconn = this.GetConn(); mysqlconn.Open(); sda = new MySqlDataAdapter(sql, mysqlconn); dt = new DataTable(); sda.Fill(dt); mysqlconn.Close(); return(dt); } catch (Exception ex) { MyOperation.DebugPrint(ex.Message); throw; } }
private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tb_username.Text)) { MessageBox.Show("请输入激活码"); tb_username.Focus(); return; } JObject Shopinfo; if (false == yg.ActivateNewShop(tb_username.Text, out Shopinfo)) { MessageBox.Show("激活失败!"); return; } else { progressBar1.Value = 30; YouGeWinformApi.Shopinfo si = new YouGeWinformApi.Shopinfo(); //初始化必须参数赋值 si.shopId = Shopinfo["data"]["id"].ToString(); si.shopRealname = Shopinfo["data"]["realname"].ToString(); if (ygw.InitDatabase(si)) { MyOperation.DebugPrint("激活成功,创建数据表完成"); this.Hide(); 主页面 formmain = new 主页面(); formmain.Show(); } else { MessageBox.Show("激活失败!"); return; } } }
private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("定价不能为空!"); textBox1.Focus(); return; } IDictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("isbn", label7.Text); parameters.Add("fixedPrice", textBox1.Text); parameters.Add("name", label9.Text); parameters.Add("press", ("" == label8.Text) ? "无" : label8.Text); parameters.Add("author", ("" == label10.Text)? "无" : label10.Text); string gbookid; if (yg.InsertNewBookInfo(parameters, out gbookid)) { YouGeWinformApi.Localbookinfo lbi = new YouGeWinformApi.Localbookinfo(); lbi.author = label10.Text; lbi.fixedprice = textBox1.Text; lbi.guid = gbookid; lbi.imgpath = ""; lbi.isbn = label7.Text; lbi.name = label9.Text; lbi.press = label8.Text; if (ygw.InsertNewBookInfo(lbi, out gbookid)) { MessageBox.Show("添加成功,重新搜索即可查到"); return; } } MessageBox.Show("添加失败,请在网络状态良好的情况下重试"); MyOperation.DebugPrint("复制图书信息失败,请在网络状态良好的情况下重试"); }
private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("请输入书名"); textBox1.Focus(); return; } if (string.IsNullOrEmpty(textBox2.Text)) { MessageBox.Show("请输入作者"); textBox2.Focus(); return; } if (string.IsNullOrEmpty(textBox3.Text)) { MessageBox.Show("请输入出版社"); textBox3.Focus(); return; } if (string.IsNullOrEmpty(textBox4.Text)) { MessageBox.Show("请输入定价"); textBox4.Focus(); return; } if (string.IsNullOrEmpty(textBox5.Text)) { MessageBox.Show("请输入ISBN"); textBox5.Focus(); return; } IDictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("isbn", textBox5.Text); parameters.Add("fixedPrice", textBox4.Text); parameters.Add("name", textBox1.Text); parameters.Add("press", textBox3.Text); parameters.Add("author", textBox2.Text); string gbookid; if (yg.InsertNewBookInfo(parameters, out gbookid)) { YouGeWinformApi.Localbookinfo lbi = new YouGeWinformApi.Localbookinfo(); lbi.author = textBox2.Text; lbi.fixedprice = textBox4.Text; lbi.guid = gbookid; lbi.imgpath = ""; lbi.isbn = textBox5.Text; lbi.name = textBox1.Text; lbi.press = textBox3.Text; if (ygw.InsertNewBookInfo(lbi, out gbookid)) { MessageBox.Show("添加成功,重新搜索即可查到"); this.Dispose(); return; } } MessageBox.Show("添加失败,请在网络状态良好的情况下重试"); MyOperation.DebugPrint("添加图书信息失败,请在网络状态良好的情况下重试"); }
private void 新书入库_Load(object sender, EventArgs e) { label5.Text = MyOperation.GetNow(); cb_binding(); }