Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cmbDivision.SelectedValue != null)
            {
                if (txtDepartmentDescription.Text.Equals("") || txtDepartmentName.Text.Equals(""))
                {
                    MessageBox.Show(this, "Please Fill all Fields", "Blank Fields", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                else
                {
                    try
                    {
                        long ID = 0;
                        if (!txtID.Text.Equals("[Auto]"))
                        {
                            ID = Convert.ToInt64(txtID.Text);
                        }


                        objDepartment.DepID = ID;

                        objDepartment.DepDescription = txtDepartmentDescription.Text;
                        objDepartment.DepHead        = objEmpDL.Get(cmbDepHead.SelectedValue.ToString());
                        objDepartment.DepName        = txtDepartmentName.Text;

                        long DivisionID = Convert.ToInt64(cmbDivision.SelectedValue);
                        objDepartment.DivisionID = DivisionID;


                        if (rbOther.Checked)
                        {
                            objDepartment.DepType = "OTHER";
                        }

                        if (rbSales.Checked)
                        {
                            objDepartment.DepType = "LAB";
                        }

                        if (rbStores.Checked)
                        {
                            objDepartment.DepType = Department.Type.STORE.ToString();
                        }
                        if (rbPRPD.Checked)
                        {
                            objDepartment.DepType = Department.Type.PRPD.ToString();
                        }
                        if (rbRPD.Checked)
                        {
                            objDepartment.DepType = Department.Type.RPD.ToString();
                        }
                        if (rbAgri.Checked)
                        {
                            objDepartment.DepType = Department.Type.AGRI.ToString();
                        }
                        if (rbSupply.Checked)
                        {
                            objDepartment.DepType = Department.Type.SUPPLY.ToString();
                        }
                        if (rbProduction.Checked)
                        {
                            objDepartment.DepType = Department.Type.PRODUCTION.ToString();
                        }



                        long NewID = objDepDL.Add_New(objDepartment);
                        if (NewID > 0)
                        {
                            ClearDepartment();
                            bindDep.DataSource = objDepDL.GetDataView(DivisionID);
                            MessageBox.Show(this, "Succesfully Added to Database", "Succesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        //int x = 0;

                        //if (this.DepSelect)
                        //{
                        //    // x = objDepDL.Update(objDepartment);



                        //    if (x > 0)
                        //    {
                        //        ClearDepartment();
                        //        bindDep.DataSource = objDepDL.GetDataView();
                        //        MessageBox.Show(this, "Succesfully Updated the Database", "Succesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //    }

                        //}
                        //else
                        //{
                        //    x = objDepDL.Add(objDepartment);


                        //    if (x > 0)
                        //    {
                        //        ClearDepartment();
                        //        bindDep.DataSource = objDepDL.GetDataView();
                        //        MessageBox.Show(this, "Succesfully Added to Database", "Succesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //    }


                        //}
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show(this, "Please enter valid data", "Input Data Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                    }
                }
            }
        }