Esempio n. 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"))
             {
                 //string btnText = btnSave.Text;
                 btnSave.Text             = "update";
                 prevsg                   = new stockgroup3();
                 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)
     {
     }
 }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Boolean status = true;

            try
            {
                StockGroupDB3 sgdb = new StockGroupDB3();
                stockgroup3   sg   = new stockgroup3();
                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("This GroupCode accepts only numeric characters");
                        return;
                    }
                    else
                    {
                        sg.GroupCode = txtGroupCode.Text;
                    }

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

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

                if (btnText.Equals("Save"))
                {
                    if (sgdb.validateStockGroup(sg))
                    {
                        if (sgdb.insertStockGroup(sg))
                        {
                            MessageBox.Show("Stock Code Added");
                            closeAllPanels();
                            listStockGroup(lvl);
                            pnlAddNew.Visible        = false;
                            pnlBottomButtons.Visible = true;
                        }
                        else
                        {
                            status = false;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Validation failed");
                    }
                    if (!status)
                    {
                        MessageBox.Show("Failed to Insert Stock Code");
                    }
                }
                else if (btnText.Equals("update"))
                {
                    if (sgdb.validateStockGroup(sg))
                    {
                        if (sgdb.updateStockGroup(sg))
                        {
                            MessageBox.Show("Stock Code Added");
                            closeAllPanels();
                            listStockGroup(lvl);
                            pnlAddNew.Visible        = false;
                            pnlBottomButtons.Visible = true;
                        }
                        else
                        {
                            status = false;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Validation failed");
                    }
                    if (!status)
                    {
                        MessageBox.Show("Failed to Insert Stock Code");
                    }
                }
                else
                {
                    MessageBox.Show("btnSave error.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Errorr in saving");
            }
        }