Exemple #1
0
 private void grdList_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.RowIndex < 0)
         {
             return;
         }
         string columnName = grdList.Columns[e.ColumnIndex].Name;
         try
         {
             if (columnName.Equals("Edit"))
             {
                 clearData();
                 //string btnText = btnSave.Text;
                 btnSave.Text             = "update";
                 prevsg                   = new customergroup();
                 prevsg.GroupCode         = grdList.Rows[e.RowIndex].Cells["GroupCode"].Value.ToString();
                 prevsg.GroupDescription  = grdList.Rows[e.RowIndex].Cells["GroupDescription"].Value.ToString();
                 prevsg.GroupLevel        = Convert.ToInt32(cmbSelectLevel.SelectedItem.ToString().Trim());
                 txtGroupCode.Text        = prevsg.GroupCode;
                 txtGroupDescription.Text = prevsg.GroupDescription;
                 pnlAddNew.Visible        = true;
             }
         }
         catch (Exception)
         {
         }
     }
     catch (Exception ex)
     {
     }
 }
Exemple #2
0
 public void clearData()
 {
     try
     {
         txtGroupCode.Text        = "";
         txtGroupDescription.Text = "";
         prevsg = new customergroup();
     }
     catch (Exception ex)
     {
     }
 }
Exemple #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Boolean status = true;

            try
            {
                CustomerGroupDB             cgdb = new CustomerGroupDB();
                customergroup               cg   = new customergroup();
                System.Windows.Forms.Button btn  = sender as System.Windows.Forms.Button;
                string btnText = btnSave.Text;

                try
                {
                    if (!System.Text.RegularExpressions.Regex.IsMatch(txtGroupCode.Text, @"^[0-9]+$"))
                    {
                        MessageBox.Show("GroupCode accepts only numeric characters");
                        return;
                    }
                    else
                    {
                        cg.GroupCode = txtGroupCode.Text;
                    }

                    if (!System.Text.RegularExpressions.Regex.IsMatch(txtGroupDescription.Text, @"^[\sa-zA-Z0-9]+$"))
                    {
                        MessageBox.Show("Group Description accepts only alphanumeric characters");
                        return;
                    }
                    else
                    {
                        cg.GroupDescription = txtGroupDescription.Text;
                    }

                    cg.GroupLevel = Convert.ToInt32(cmbSelectLevel.SelectedItem.ToString().Trim());
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Validation failed");
                    return;
                }

                if (btnText.Equals("Save"))
                {
                    if (cgdb.validateCustomerGroup(cg))
                    {
                        if (cgdb.insertCustomerGroup(cg))
                        {
                            MessageBox.Show("Customer Code Added");
                            closeAllPanels();
                            listCustomerGroup(lvl);
                            pnlAddNew.Visible        = false;
                            pnlBottomButtons.Visible = true;
                        }
                        else
                        {
                            status = false;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Validation failed");
                    }
                    if (!status)
                    {
                        MessageBox.Show("Failed to Insert Customer Group");
                    }
                }
                else if (btnText.Equals("update"))
                {
                    if (cgdb.validateCustomerGroup(cg))
                    {
                        if (cgdb.updateCustomerGroup(cg))
                        {
                            MessageBox.Show("Customer Group Added");
                            closeAllPanels();
                            listCustomerGroup(lvl);
                            pnlAddNew.Visible        = false;
                            pnlBottomButtons.Visible = true;
                        }
                        else
                        {
                            status = false;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Validation failed");
                    }
                    if (!status)
                    {
                        MessageBox.Show("Failed to Insert Customer Group");
                    }
                }
                else
                {
                    MessageBox.Show("btnSave error.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Errorr in saving");
            }
        }