Exemplo n.º 1
0
 public static Nullable <int> AddDisposalReason(DisposalReason aDisposalReason)
 {
     if (Helper.Instance.con.State == ConnectionState.Closed)
     {
         try
         {
             Helper.Instance.con.Open();
             SqlCommand cmd = new SqlCommand("INSERT INTO DisposalReason (Name,Comment) VALUES (@Name,@Comment)", Helper.Instance.con);
             cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value    = aDisposalReason.Disposal_Detailed_Name;
             cmd.Parameters.Add("@Comment", SqlDbType.NVarChar).Value = aDisposalReason.Disposal_Detailed_Comment;
             cmd.ExecuteNonQuery();
             Helper.Instance.con.Close();
             return(1);
         }
         catch (Exception ex)
         {
             Helper.Instance.con.Close();
             MessageBox.Show("ERROR IN DisposalReason MGMT (AddDisposalReason FUNCTION) EX=" + ex.Message.ToString());
             return(0);
         }
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
        private void AddDisposalReasonBtn_Click(object sender, EventArgs e)
        {
            if (Validators.TxtBoxNotEmpty(NameTxtBox.Text))
            {
                if (Validators.TxtBoxNotEmpty(DescriptionTxtBox.Text))
                {
                    DisposalReason aDisposalReason = new DisposalReason();
                    aDisposalReason.Disposal_Detailed_Name    = NameTxtBox.Text;
                    aDisposalReason.Disposal_Detailed_Comment = DescriptionTxtBox.Text;

                    Nullable <int> IsAddDisposalReasonOK = DisposalReasonMgmt.AddDisposalReason(aDisposalReason);
                    if (IsAddDisposalReasonOK == 1)
                    {
                        MessageBox.Show(MsgTxt.DisposalReasonTxt + NameTxtBox.Text + "\n" + MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DataBase Error: AddDisposalReasonBtn_Click] \n Exception: \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields + "\n" + "1)" + MsgTxt.DescriptionTxt, MsgTxt.PleaseAddAllRequiredFields, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    DescriptionTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                    DescriptionTxtBox.Focus();

                    NameTxtBox.BackColor = NameBGColor;
                }
            }
            else
            {
                MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields + "\n" + "1)" + MsgTxt.NameTxt + "\n 2)" + MsgTxt.DescriptionTxt, MsgTxt.PleaseAddAllRequiredFields, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                if (!Validators.TxtBoxNotEmpty(DescriptionTxtBox.Text))
                {
                    DescriptionTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                    DescriptionTxtBox.Focus();
                }
                else
                {
                    DescriptionTxtBox.BackColor = DescBGColor;
                }

                if (!Validators.TxtBoxNotEmpty(NameTxtBox.Text))
                {
                    NameTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                    NameTxtBox.Focus();
                }
                else
                {
                    NameTxtBox.BackColor = NameBGColor;
                }
            }
        }