Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateChildren(ValidationConstraints.Enabled))
                {
                    int rtn = -1;
                    //int cmbProcTypeVal = (int)cmbProcType.SelectedValue.ToString)();
                    if (txtID.Text.Trim() == "") //add data
                    {
                        rtn = med.InsertProcedure(txtName.Text, txtDesc.Text, Convert.ToInt32(cmbProcType.SelectedValue.ToString()), chkActive.Checked);
                        if (rtn == -1)
                        {
                            ShowStatus(0, "Some error occurred... Record cannot be added!");
                        }
                        else if (rtn == 0)
                        {
                            ShowStatus(0, "Name must be unique!");
                        }
                        else if (rtn == 1)
                        {
                            ShowStatus(1, "Record succesfully added!");
                            clearFormFields();

                            if (modal == true)
                            {
                                this.Close();
                            }
                        }
                    }
                    else //edit record
                    {
                        rtn = med.editProcedures(Int32.Parse(txtID.Text.Trim()), txtName.Text, txtDesc.Text, Convert.ToInt32(cmbProcType.SelectedValue.ToString()), chkActive.Checked);
                        if (rtn == 0)
                        {
                            ShowStatus(0, "This name already exists. Please provide unique name!");
                        }
                        else if (rtn == 1)
                        {
                            ShowStatus(1, "Record succesfully updated!");
                            clearFormFields();
                        }
                        else if (rtn == -1)
                        {
                            ShowStatus(0, "Some error occurred... Record cannot be added!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonLogger.Info(ex.ToString());
            }
        }