コード例 #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (ValidateDetail())
     {
         if (ProductSelected != null)
         {
             try {
                 bool result = productPresenter.Update();
                 if (result)
                 {
                     UpdateStocking();
                     MessageBox.Show("Update Success.", "Update Status");
                     this.Dispose();
                 }
                 else
                 {
                     MessageBox.Show("Update Fail.", "Update Status");
                 }
             }
             catch (SqlException ex) {
                 MessageBox.Show(ex.Message, "Update status");
             }
         }
         else
         {
             try {
                 bool result = productPresenter.Insert();
                 if (result)
                 {
                     UpdateStocking();
                     MessageBox.Show("Add Success.", "Insert Status");
                     this.Dispose();
                 }
                 else
                 {
                     MessageBox.Show("Add Fail.", "Insert Status");
                 }
             }
             catch (SqlException ex) {
                 if (ex.Message.Contains("duplicate"))
                 {
                     MessageBox.Show("Product ID is already existed. Please choose another.", "Insert Status");
                 }
                 else
                 {
                     MessageBox.Show(ex.Message, "Insert status");
                 }
             }
         }
     }
 }