Пример #1
0
        private void Update()
        {
            int Code = int.Parse(txtHRCode.Text);

            using (EmployeeDBContext db = new EmployeeDBContext())
            {
                EmployeesMasterData updateEmployeeMD = (from Employee_tbl in db.EmployeesMasterDatas where Employee_tbl.EmployeeHRCode == Code select Employee_tbl).FirstOrDefault();
                updateEmployeeMD.EmployeeFullName = txtName.Text;
                updateEmployeeMD.NoOfVisitsPerDay = int.Parse(txtVisitsPreDay.Text);
                int roweffected = db.SaveChanges();

                lblEmployeeSaveStatus.Text = "Saved";
            }
            using (EmployeeHDBContext db = new EmployeeHDBContext())
            {
                EmployeesHistory updateEmpHistory = (from Employee_tbl in db.EmployeesHistories where Employee_tbl.EmployeeHRCode == Code select Employee_tbl).FirstOrDefault();
                if (ddlPosition.SelectedValue == "Rep")
                {
                    updateEmpHistory.RepAreaID    = int.Parse(ddlAreaForRep.SelectedValue);
                    updateEmpHistory.EmployeeType = "Rep";
                    updateEmpHistory.ReportsTo    = int.Parse(ddlDMNames.SelectedValue);
                }
                if (ddlPosition.SelectedValue == "DM")
                {
                    updateEmpHistory.RepAreaID    = int.Parse(ddlAreaForDM.SelectedValue);
                    updateEmpHistory.EmployeeType = "DM";
                    updateEmpHistory.ReportsTo    = int.Parse(ddlManNames.SelectedValue);
                }
                if (ddlPosition.SelectedValue == "Sales Manager")
                {
                    updateEmpHistory.RepAreaID    = int.Parse(ddlAreaForDM.SelectedValue);
                    updateEmpHistory.EmployeeType = "Sales Manager";
                    updateEmpHistory.ReportsTo    = int.Parse(ddlManNames.SelectedValue);
                }

                int roweffected = db.SaveChanges();


                using (EmployeesViewDBContext refreshdb = new EmployeesViewDBContext())
                {
                    var Employeedata = from Employee_tbl in refreshdb.View_Employees where Employee_tbl.EmployeeHRCode == Code select Employee_tbl;
                    gvEmployee.DataSource = Employeedata.ToList();
                    gvEmployee.DataBind();
                }
                Clear();
                lblEmployeeSaveStatus.Text = "Updated";
            }
        }
Пример #2
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int Code = int.Parse(txtHRCode.Text);

            using (EmployeeDBContext db = new EmployeeDBContext())
            {
                EmployeesMasterData DeleteEmployeeMD = (from Employee_tbl in db.EmployeesMasterDatas where Employee_tbl.EmployeeHRCode == Code select Employee_tbl).FirstOrDefault();
                DeleteEmployeeMD.Deleted = true;
                int roweffected = db.SaveChanges();
                if (roweffected > 0)
                {
                    lblEmployeeSaveStatus.Text = "Deleted";
                }
                else
                {
                    lblEmployeeSaveStatus.Text = "Error";
                    return;
                }
            }
            using (EmployeeHDBContext db = new EmployeeHDBContext())
            {
                EmployeesHistory DeleteEmpHistory = (from Employee_tbl in db.EmployeesHistories where Employee_tbl.EmployeeHRCode == Code select Employee_tbl).FirstOrDefault();
                DeleteEmpHistory.Deleted = true;
                int roweffected = db.SaveChanges();
                if (roweffected > 0)
                {
                    Clear();
                    lblEmployeeSaveStatus.Text = "Deleted";
                }
                else
                {
                    lblEmployeeSaveStatus.Text = "Error";
                    return;
                }
            }
        }
Пример #3
0
        private void Save()
        {
            string Pass;

            using (EmployeeDBContext newEmployeMD = new EmployeeDBContext())
            {
                EmployeesMasterData EmpMD = new EmployeesMasterData();
                EmpMD.EmployeeFullName   = txtName.Text;
                EmpMD.EmployeeHRCode     = int.Parse(txtHRCode.Text);
                EmpMD.EmployeeUserName   = txtHRCode.Text;
                EmpMD.MustChangePassword = true;
                EmpMD.NoOfVisitsPerDay   = int.Parse(txtVisitsPreDay.Text);
                EmpMD.EmployeePassword   = RandomPassword.Generate(8, 10);
                Pass = EmpMD.EmployeePassword;
                newEmployeMD.EmployeesMasterDatas.Add(EmpMD);
                int roweffected = newEmployeMD.SaveChanges();
                if (roweffected > 0)
                {
                    lblEmployeeSaveStatus.Text = "Saved";
                }
                else
                {
                    lblEmployeeSaveStatus.Text = "Error";
                    return;
                }
            }

            using (EmployeeHDBContext newHistory = new EmployeeHDBContext())
            {
                EmployeesHistory History = new EmployeesHistory();
                History.EmployeeHRCode = int.Parse(txtHRCode.Text);
                History.LineID         = int.Parse(ddlLine.SelectedValue);

                if (ddlPosition.SelectedValue == "Rep")
                {
                    History.RepAreaID    = int.Parse(ddlAreaForRep.SelectedValue);
                    History.EmployeeType = "Rep";
                    History.ReportsTo    = int.Parse(ddlDMNames.SelectedValue);
                }
                if (ddlPosition.SelectedValue == "DM")
                {
                    History.RepAreaID    = int.Parse(ddlAreaForDM.SelectedValue);
                    History.EmployeeType = "DM";
                    History.ReportsTo    = int.Parse(ddlManNames.SelectedValue);
                }
                if (ddlPosition.SelectedValue == "SM")
                {
                    History.RepAreaID    = int.Parse(ddlAreaForDM.SelectedValue);
                    History.EmployeeType = "Sales Manager";
                    History.ReportsTo    = int.Parse(ddlManNames.SelectedValue);
                }

                newHistory.EmployeesHistories.Add(History);
                int roweffected = newHistory.SaveChanges();
                if (roweffected > 0)
                {
                    using (EmployeesViewDBContext refreshdb = new EmployeesViewDBContext())
                    {
                        int empid        = int.Parse(txtHRCode.Text);
                        var Employeedata = from Employee_tbl in refreshdb.View_Employees where Employee_tbl.EmployeeHRCode == empid select Employee_tbl;
                        gvEmployee.DataSource = Employeedata.ToList();
                        gvEmployee.DataBind();
                    }
                    Clear();
                    lblEmployeeSaveStatus.Text = "Saved, Password is: " + Pass;
                }
                else
                {
                    lblEmployeeSaveStatus.Text = "Error";
                    return;
                }
            }
            //UploadPic();
        }