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(); } } }