Exemplo n.º 1
0
        public void UpdateRecord(Objects.Employees obj)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SP_EmployeesUpdate";

                cmd.Parameters.AddWithValue("@EmployeeID", obj.EmployeeID);
                cmd.Parameters.AddWithValue("@EmployeeName", obj.EmployeeName);
                cmd.Parameters.AddWithValue("@FatherName", obj.FatherName);
                cmd.Parameters.AddWithValue("@JoiningDate", obj.JoiningDate);
                cmd.Parameters.AddWithValue("@CNIC", obj.CNIC);
                cmd.Parameters.AddWithValue("@ContactNo", obj.ContactNo);
                cmd.Parameters.AddWithValue("@Address", obj.Address);
                cmd.Parameters.AddWithValue("@IsSalesman", obj.IsSalesman);
                cmd.Parameters.AddWithValue("@BasicSalary", obj.BasicSalary);
                cmd.Parameters.AddWithValue("@UserID", obj.UserID);
                cmd.Parameters.AddWithValue("@DepartmentID", obj.DepartmentID);
                cmd.Parameters.AddWithValue("@DesignationID", obj.DesignationID);
                cmd.Parameters.AddWithValue("@ShiftID", obj.ShiftID);
                cmd.Parameters.AddWithValue("@InActive", obj.InActive);
                cmd.Parameters.AddWithValue("@AccountNo", obj.AccountNo);
                new Database(connectionstring).ExecuteNonQueryOnly(cmd);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtName.Text.Trim() == string.Empty)
                {
                    Message.ShowMessage(MyMessages.MessageType.MissingInfo, "Please Enter Name.");
                    txtName.Focus();
                    return;
                }

                int vDeptID, vDesgID, vShiftID;

                if (cboDepartment.SelectedIndex != -1)
                {
                    int.TryParse(cboDepartment.SelectedValue.ToString(), out vDeptID);
                }
                else
                {
                    Message.ShowMessage(MyMessages.MessageType.MissingInfo, "Please Select Department.");
                    cboDepartment.Focus();
                    return;
                }

                if (cboDesignation.SelectedIndex != -1)
                {
                    int.TryParse(cboDesignation.SelectedValue.ToString(), out vDesgID);
                }
                else
                {
                    Message.ShowMessage(MyMessages.MessageType.MissingInfo, "Please Select Designation.");
                    cboDesignation.Focus();
                    return;
                }

                if (cboShift.SelectedIndex != -1)
                {
                    int.TryParse(cboShift.SelectedValue.ToString(), out vShiftID);
                }
                else
                {
                    Message.ShowMessage(MyMessages.MessageType.MissingInfo, "Please Select Shift.");
                    cboShift.Focus();
                    return;
                }


                decimal vBasicSalary = 0;
                decimal.TryParse(txtBasicSalary.Text, out vBasicSalary);


                Objects.Employees obj = new Objects.Employees();
                obj.EmployeeID    = Int32.Parse(txtID.Text);
                obj.EmployeeName  = txtName.Text.Trim();
                obj.FatherName    = txtFatherName.Text.Trim();
                obj.CNIC          = txtCNIC.Text.Trim();
                obj.ContactNo     = txtContactNo.Text.Trim();
                obj.DepartmentID  = vDeptID;
                obj.DesignationID = vDesgID;
                obj.ShiftID       = vShiftID;
                obj.JoiningDate   = dtJoiningDate.Value;
                obj.BasicSalary   = vBasicSalary;
                obj.Address       = txtAddress.Text.Trim();
                obj.AccountNo     = txtID.Tag.ToString();
                obj.InActive      = chkInActive.Checked;
                obj.IsSalesman    = chkSalesman.Checked;
                obj.UserID        = vUserID;


                //Insert Account
                var AccDAL = new DAL.AccountChart();
                AccDAL.connectionstring = objDAL.connectionstring;
                Objects.AccountChart objAcc = new Objects.AccountChart();
                objAcc.AccountNo      = obj.AccountNo;
                objAcc.AccountTitle   = obj.EmployeeName;
                objAcc.AccountType    = "LIABILITY";
                objAcc.AccountSubType = "Employee";
                objAcc.IsParty        = false;
                objAcc.IsBank         = false;
                objAcc.OpeningDebit   = 0;
                objAcc.OpeningCredit  = 0;


                if (!vOpenMode)
                {
                    objAcc.AccountNo = AccDAL.getNextNo("LIABILITY").ToString();
                    AccDAL.InsertRecord(objAcc);

                    //Insert Party
                    obj.EmployeeID = objDAL.getNextNo();
                    obj.AccountNo  = objAcc.AccountNo;

                    objDAL.InsertRecord(obj);
                }
                else
                {
                    if (!string.IsNullOrEmpty(objAcc.AccountNo))
                    {
                        // UPdate  Account
                        AccDAL.UpdateRecord(objAcc);
                    }
                    else
                    {
                        objAcc.AccountNo = AccDAL.getNextNo("LIABILITY").ToString();
                        AccDAL.InsertRecord(objAcc);
                        obj.AccountNo = objAcc.AccountNo;
                    }

                    objDAL.UpdateRecord(obj);
                }

                Message.ShowMessage(MyMessages.MessageType.SaveRecord);
                LoadGrid();
                btnClear_Click(sender, e);
            }
            catch (Exception exc)
            {
                Message.ShowMessage(MyMessages.MessageType.Error, exc.Message);
            }
        }