public static String DeleteCustomer_trade_data(string tableName, Customer_trade_data customer_Trade_Data) { try { using (var statement = connection.Prepare("DELETE FROM " + tableName + " WHERE " + "ctid = ?")) { statement.Bind(1, customer_Trade_Data.ctid); statement.Step(); } } catch (Exception e) { Debug.WriteLine(e.Message); } return(connection.ErrorMessage().ToString()); }
public static String UpdateCustomer_trade_data(string tableName, Customer_trade_data customer_Trade_Data) { try { using (var statement = connection.Prepare("UPDATE " + tableName + " SET ctprice = ?, ctnum = ? WHERE ctid = ?")) { statement.Bind(1, customer_Trade_Data.ctprice); statement.Bind(2, customer_Trade_Data.ctnum); statement.Bind(3, customer_Trade_Data.ctid); statement.Step(); } } catch (Exception e) { Debug.WriteLine(e.Message); } return(connection.ErrorMessage().ToString()); }
//获取用户交易信息 public static String GetAllCustomer_trade_data(ObservableCollection <Customer_trade_data> customer_Trade_Datas, string tableName, string searchStr = "") { customer_Trade_Datas.Clear(); string sql = "SELECT * FROM " + tableName; if (searchStr != "") { sql = sql + " WHERE ctid = " + searchStr; using (var statement = connection.Prepare(sql)) { while (statement.Step() == SQLiteResult.ROW) { Customer_trade_data customer_Trade_Data = new Customer_trade_data(); customer_Trade_Data.ctid = (string)statement[0]; customer_Trade_Data.ctprice = (int)(long)statement[1]; customer_Trade_Data.ctnum = (int)(long)statement[2]; customer_Trade_Data.cuid = (string)statement[3]; customer_Trade_Data.cid = (string)statement[4]; customer_Trade_Data.cprofit = (int)(long)statement[5]; customer_Trade_Datas.Add(customer_Trade_Data); } } return(connection.ErrorMessage().ToString()); } using (var statement = connection.Prepare(sql)) { while (statement.Step() == SQLiteResult.ROW) { Customer_trade_data customer_Trade_Data = new Customer_trade_data(); customer_Trade_Data.ctid = (string)statement[0]; customer_Trade_Data.ctprice = (int)(long)statement[1]; customer_Trade_Data.ctnum = (int)(long)statement[2]; customer_Trade_Data.cuid = (string)statement[3]; customer_Trade_Data.cid = (string)statement[4]; customer_Trade_Data.cprofit = (int)(long)statement[5]; customer_Trade_Datas.Add(customer_Trade_Data); } } return(connection.ErrorMessage().ToString()); }
private async void Button_Click_1(object sender, RoutedEventArgs e) { if ( (Garage_info.Visibility == Visibility.Visible && (qid.Text == "" || ctnum.Text == "" || cid2.Text == "")) || (in_info.Visibility == Visibility.Visible && (ftid.Text == "" || ftprice.Text == "" || ftnum.Text == "" || fid2.Text == "" || cid3.Text == "")) || (out_info.Visibility == Visibility.Visible && (ctid.Text == "" || ctprice.Text == "" || ctnum2.Text == "" || cuid2.Text == "" || cid4.Text == "")) ) { var dialog = new ContentDialog() { Content = "请不要留空", PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog.ShowAsync(); return; } if (smallIndex == 0) { Factory_trade_data factory_Trade_Data = new Factory_trade_data { ftid = ftid.Text, ftprice = String2int(ftprice.Text), cid = cid3.Text, fid = fid2.Text, ftnum = String2int(ftnum.Text) }; String message1 = SqlHelper.AddFactory_trade_data(factory_Trade_Data, "Factory_trade_data"); String message2 = SqlHelper.GetAllCustomer_trade_data(customer_Trade_Datas, "Customer_trade_data"); String message3 = SqlHelper.GetAllFactory_trade_data(factory_Trade_Datas, "factory_trade_data"); String feedback = ""; if (message1 != "not an error") { feedback += message1 + "\n"; } if (message2 != "not an error") { feedback += message2 + "\n"; } if (message3 != "not an error") { feedback += message3 + "\n"; } Cleanhelp(); var dialog = new ContentDialog() { Content = feedback == "" ? "创建成功" : feedback, PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog.ShowAsync(); } else { ObservableCollection <Car> cars = new ObservableCollection <Car>(); SqlHelper.GetAllCar(cars, "car"); ObservableCollection <Customer> customers = new ObservableCollection <Customer>(); ObservableCollection <Factory_trade_data> factory_Trade_Datas = new ObservableCollection <Factory_trade_data>(); SqlHelper.GetAllCustomer(customers, "Customer"); SqlHelper.GetAllFactory_trade_data(factory_Trade_Datas, "Factory_Trade_Data"); bool judge = false; bool judge2 = false; int price = 0; int count = 0; foreach (Factory_trade_data temp in factory_Trade_Datas) { if (temp.cid == cid4.Text) { judge = true; price += (temp.ftnum * temp.ftprice); count += temp.ftnum; } } if (count != 0) { price = price / count; } foreach (Customer temp in customers) { if (temp.cuid == cuid2.Text) { judge2 = true; break; } } if (judge && judge2) { int temp_ctnum = 0; ObservableCollection <Garage> temp_g = new ObservableCollection <Garage>(); SqlHelper.GetAllGarage(temp_g, "garage"); foreach (Garage temp in temp_g) { if (temp.cid == cid4.Text) { temp_ctnum = temp.ctnum; } } if (String2int(ctnum2.Text) > temp_ctnum) { var dialog2 = new ContentDialog() { Content = "车库剩余不足", PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog2.ShowAsync(); return; } Debug.Write(price); price = (String2int(ctprice.Text) - price) * String2int(ctnum2.Text); Customer_trade_data customer_Trade_Data = new Customer_trade_data { ctid = ctid.Text, ctprice = String2int(ctprice.Text), cid = cid4.Text, cuid = cuid2.Text, ctnum = String2int(ctnum2.Text), cprofit = price }; SqlHelper.AddCustomer_trade_data(customer_Trade_Data, "customer_trade_data"); SqlHelper.GetAllCustomer_trade_data(customer_Trade_Datas, "Customer_trade_data"); SqlHelper.GetAllFactory_trade_data(factory_Trade_Datas, "factory_trade_data"); Cleanhelp(); var dialog = new ContentDialog() { Content = "创建成功", PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog.ShowAsync(); } else { var dialog = new ContentDialog() { Title = "提示", Content = "车的编号或者客户编号不存在", PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog.ShowAsync(); } } }
//插入用户交易记录 public static String AddCustomer_trade_data(Customer_trade_data customer_trade_data, string tableName) { ObservableCollection <Garage> garages = new ObservableCollection <Garage>(); GetAllGarage(garages, "garage"); Car temp_car = new Car(); int temp_ctnum = 0; foreach (Garage temp in garages) { if (temp.cid == customer_trade_data.cid) { temp_ctnum = temp.ctnum; } } String UPDATE = "UPDATE " + "garage" + " SET ctnum = ? WHERE cid = ?"; try { using (var statement = connection.Prepare(UPDATE)) { statement.Bind(1, (temp_ctnum - customer_trade_data.ctnum)); statement.Bind(2, customer_trade_data.cid); statement.Step(); } } catch (Exception e) { Debug.WriteLine(e.Message); } String message = connection.ErrorMessage().ToString(); try { using (var statement = connection.Prepare("INSERT INTO " + tableName + "(ctid, ctprice, ctnum, cuid, cid, cprofit) VALUES (?, ?, ?, ?, ?, ?)")) { statement.Bind(1, customer_trade_data.ctid); statement.Bind(2, customer_trade_data.ctprice); statement.Bind(3, customer_trade_data.ctnum); statement.Bind(4, customer_trade_data.cuid); statement.Bind(5, customer_trade_data.cid); statement.Bind(6, customer_trade_data.cprofit); statement.Step(); } } catch (Exception e) { Debug.WriteLine(e.Message); } if (message == "not an error" && connection.ErrorMessage().ToString() == "not an error") { return(message); } else if (connection.ErrorMessage().ToString() != "not an error" && message != "not an error") { return(message + "\n" + connection.ErrorMessage().ToString()); } else if (message == "not an error") { return(connection.ErrorMessage().ToString()); } else { return(message); } }
private async void Button_Click_1(object sender, RoutedEventArgs e) { if (nowIndex == 0) { if (smallIndex == 0) { Car car = new Car(); car.cid = cid.Text; car.cbrand = cbrand.Text; car.cprice = String2int(cprice.Text); car.fid = fid.Text; Factory factory = new Factory(); factory.fid = fid.Text; factory.faddress = faddress.Text; factory.fname = fname.Text; SqlHelper.UpdateFactory("factory", factory); SqlHelper.UpdateCar("car", car); var dialog = new ContentDialog() { Content = "更新成功", PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog.ShowAsync(); } else if (smallIndex == 1) { Customer customer = new Customer(); customer.cuid = cuid.Text; customer.cuname = cuname.Text; customer.cuaddress = cuaddress.Text; SqlHelper.UpdateCustomer("customer", customer); var dialog = new ContentDialog() { Content = "更新成功", PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog.ShowAsync(); } else { ObservableCollection <Car> cars = new ObservableCollection <Car>(); SqlHelper.GetAllCar(cars, "car"); Garage garage = new Garage(); garage.gid = qid.Text; garage.ctnum = String2int(ctnum.Text); garage.cid = cid2.Text; SqlHelper.UpdateGarage("garage", garage); var dialog = new ContentDialog() { Content = "更新成功", PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog.ShowAsync(); } } else { if (smallIndex == 0) { ObservableCollection <Car> cars = new ObservableCollection <Car>(); SqlHelper.GetAllCar(cars, "car"); ObservableCollection <Factory> factorys = new ObservableCollection <Factory>(); SqlHelper.GetAllFactory(factorys, "factory"); Factory_trade_data factory_Trade_Data = new Factory_trade_data { ftid = ftid.Text, ftprice = String2int(ftprice.Text), cid = cid3.Text, fid = fid2.Text, ftnum = String2int(ftnum.Text) }; SqlHelper.UpdateFactory_trade_data("Factory_trade_data", factory_Trade_Data); var dialog = new ContentDialog() { Content = "更新成功", PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog.ShowAsync(); } else { ObservableCollection <Car> cars = new ObservableCollection <Car>(); SqlHelper.GetAllCar(cars, "car"); ObservableCollection <Customer> customers = new ObservableCollection <Customer>(); SqlHelper.GetAllCustomer(customers, "Customer"); Customer_trade_data customer_Trade_Data = new Customer_trade_data { ctid = ctid.Text, ctprice = String2int(ctprice.Text), cid = cid4.Text, cuid = cuid2.Text, ctnum = String2int(ctnum.Text) }; SqlHelper.UpdateCustomer_trade_data("customer_trade_data", customer_Trade_Data); var dialog = new ContentDialog() { Content = "更新成功", PrimaryButtonText = "确定", FullSizeDesired = false, }; await dialog.ShowAsync(); } } this.Frame.Navigate(typeof(Base_Information)); }