private void CustomerRelate_Click(object sender, RoutedEventArgs e) { if (ProcessOrder == null) { MessageBox.Show("尚未選擇一筆訂單!!"); return; } if (!(ComboBoxCustomer.SelectedItem is Customer customer)) { MessageBox.Show("尚未選擇客戶!!"); return; } bool inCustomerOrderRelate = ProcessModule.CheckInCustomerOrderRelate(ProcessOrder.OrderNo, customer.CustomerID); if (inCustomerOrderRelate) { MessageBox.Show(string.Format("{0}已關連至{1},{2}!!", customer.Name, ProcessOrder.OrderString, ProcessOrder.Fabric)); return; } CustomerOrderRelate customerOrderRelate = new CustomerOrderRelate { CustomerID = customer.CustomerID, ProcessOrderID = ProcessOrder.OrderNo }; bool success = ProcessModule.InsertCustomerOrderRelate(customerOrderRelate); if (success) { MessageBox.Show(string.Format("成功將{0}關連至{1},{2}!!", customer.Name, ProcessOrder.OrderString, ProcessOrder.Fabric)); } else { MessageBox.Show("新增錯誤!!"); } }
/// <summary> /// 新增客戶訂單關連 /// </summary> /// <param name="customerOrderRelate"></param> /// <returns></returns> public int InsertCustomerOrderRelate(CustomerOrderRelate customerOrderRelate) { var sqlCmd = @"INSERT INTO CustomerOrderRelate (CustomerID,ProcessOrderID) VALUES (@CustomerID,@ProcessOrderID)"; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@CustomerID", SqlDbType.Int) { Value = customerOrderRelate.CustomerID }, new SqlParameter("@ProcessOrderID", SqlDbType.Int) { Value = customerOrderRelate.ProcessOrderID } }; return(DapperHelper.ExecuteParameter(AppSettingConfig.ConnectionString(), CommandType.Text, sqlCmd, parameter)); }
/// <summary> /// 新增客戶訂單關連 /// </summary> /// <param name="customerOrderRelate"></param> /// <returns></returns> public bool InsertCustomerOrderRelate(CustomerOrderRelate customerOrderRelate) { int count = ProcessOrderAdapter.InsertCustomerOrderRelate(customerOrderRelate); return(count == 1); }