Esempio n. 1
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Clear();
            using (EmployeesViewDBContext db = new EmployeesViewDBContext())
            {
                if (txtCodeSe.Text != "" && txtNameSe.Text == "")
                {
                    int Code         = int.Parse(txtCodeSe.Text);
                    var Employeedata = from Employee_tbl in db.View_Employees where (Employee_tbl.DeletedEmployee == null || Employee_tbl.DeletedEmployee == false) && Employee_tbl.EmployeeHRCode == Code select Employee_tbl;
                    gvEmployee.DataSource = Employeedata.ToList();
                }

                if (txtCodeSe.Text == "" && txtNameSe.Text != "")
                {
                    string Name         = txtNameSe.Text;
                    var    Employeedata = from Employee_tbl in db.View_Employees where (Employee_tbl.DeletedEmployee == null || Employee_tbl.DeletedEmployee == false) && Employee_tbl.EmployeeFullName.Contains(Name) select Employee_tbl;
                    gvEmployee.DataSource = Employeedata.ToList();
                }

                if (txtCodeSe.Text != "" && txtNameSe.Text != "")
                {
                    int    Code         = int.Parse(txtCodeSe.Text);
                    string Name         = txtNameSe.Text;
                    var    Employeedata = from Employee_tbl in db.View_Employees where (Employee_tbl.DeletedEmployee == null || Employee_tbl.DeletedEmployee == false) && Employee_tbl.EmployeeHRCode == Code && Employee_tbl.EmployeeFullName.Contains(Name) select Employee_tbl;
                    gvEmployee.DataSource = Employeedata.ToList();
                }
                gvEmployee.DataBind();
            }
        }
Esempio n. 2
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";
            }
        }
Esempio n. 3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Session["EmployeeType"].ToString() == "Rep")
            {
                DateTime first_date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                DateTime last_date  = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month));
                var      today      = DateTime.Now;
                var      tomorrow   = today.AddDays(1);
                var      yesterday  = today.AddDays(-1);
                var      month      = DateTime.Now.Month.ToString();



                con = new SqlConnection(ConfigurationManager.ConnectionStrings["AmounCrmConnectionString"].ConnectionString);
                SqlCommand cmd2 = new SqlCommand("select CycleID from Cycles where IsCurrent=1");
                cmd2.CommandType = CommandType.Text;
                con.Open();
                cmd2.Connection = con;
                int cycleid = (int)cmd2.ExecuteScalar();
                con.Close();


                con = new SqlConnection(ConfigurationManager.ConnectionStrings["AmounCrmConnectionString"].ConnectionString);
                SqlCommand cmd22 = new SqlCommand("select MonthID from Cycles where IsCurrent=1");
                cmd22.CommandType = CommandType.Text;
                con.Open();
                cmd22.Connection = con;
                int cyclemonth = (int)cmd22.ExecuteScalar();
                con.Close();



                if (month != cyclemonth.ToString())
                {
                    VacationslblSaveStatus.Text = "You can't register a vacation beyond the current cycle";
                    return;
                }

                if (Session["CycleID"].ToString() != cycleid.ToString())
                {
                    VacationslblSaveStatus.Text = "You can't register a vacation beyond the current cycle";
                    return;
                }


                if (dpStartDate.SelectedDate.Value.Date < yesterday.Date)//Modified to take a Date Part in a consideration, Ehab(4-Mar-2018) Reviewe before publishing
                {
                    VacationslblSaveStatus.Text = "Invalid Start Date,it must be within 24 hour by maximum";
                    return;
                }
                if (dpStartDate.SelectedDate > last_date || dpStartDate.SelectedDate < first_date)
                {
                    VacationslblSaveStatus.Text = "Invalid Start Date,it must be within this month";
                    return;
                }

                if (dpEndDate.SelectedDate > last_date || dpEndDate.SelectedDate < first_date)
                {
                    VacationslblSaveStatus.Text = "Invalid End Date,it must be within this month";
                    return;
                }



                if (dpStartDate.SelectedDate == null || dpEndDate.SelectedDate == null || txtNoOfDays.Text == "" || ddlVacationType.SelectedValue == "0")
                {
                    VacationslblSaveStatus.Text = "All fields are mandatory";
                    return;
                }

                if (dpEndDate.SelectedDate < dpStartDate.SelectedDate)
                {
                    VacationslblSaveStatus.Text = "Invalid End Date";
                    return;
                }
                if (int.Parse(ddlVacationType.SelectedValue) == 2 && dpStartDate.SelectedDate > today)
                {
                    VacationslblSaveStatus.Text = "Invalid Vacation type, Emergency Vaction must be within 24 hour by maximum";
                    return;
                }

                int EmpID = int.Parse(Session["EmployeeID"].ToString());
                using (VacationDBContext db = new VacationDBContext())
                {
                    Vacation VacationData = (from Vacation_tbl in db.Vacations where Vacation_tbl.EmpID == EmpID && Vacation_tbl.StartDate >= first_date && Vacation_tbl.EndDate <= last_date && ((Vacation_tbl.StartDate <= dpStartDate.SelectedDate && Vacation_tbl.EndDate >= dpEndDate.SelectedDate) || (Vacation_tbl.StartDate <= dpStartDate.SelectedDate && Vacation_tbl.EndDate >= dpStartDate.SelectedDate) || (Vacation_tbl.StartDate <= dpEndDate.SelectedDate && Vacation_tbl.EndDate >= dpEndDate.SelectedDate) || (Vacation_tbl.StartDate > dpStartDate.SelectedDate && Vacation_tbl.EndDate < dpEndDate.SelectedDate)) && Vacation_tbl.Deleted == false select Vacation_tbl).FirstOrDefault();
                    if (VacationData != null)
                    {
                        VacationslblSaveStatus.Text = "You have a vacation in this date range.";
                        //gvVacations.DataSource = VacationData.;
                        //gvVacations.DataBind();
                        return;
                    }
                }
                using (NationalEntities db = new NationalEntities())
                {
                    NationalVaccation nationalData = (from nationalVac_tbl in db.NationalVaccations where nationalVac_tbl.Deleted == null && nationalVac_tbl.VaccationDate >= dpStartDate.SelectedDate && nationalVac_tbl.VaccationDate <= dpEndDate.SelectedDate select nationalVac_tbl).FirstOrDefault();
                    if (nationalData != null)
                    {
                        VacationslblSaveStatus.Text = "You have a National vacation in this date range.";
                        return;
                    }
                }



                using (VacationDBContext newvac = new VacationDBContext())
                {
                    Vacation vac = new Vacation();
                    vac.EmpID     = int.Parse(Session["EmployeeID"].ToString());
                    vac.EmpHRCode = int.Parse(Session["EmployeeHRCode"].ToString());
                    vac.EmpName   = Session["EmployeeName"].ToString();
                    vac.StartDate = dpStartDate.SelectedDate;
                    string start = dpStartDate.SelectedDate.ToString();

                    vac.EndDate     = dpEndDate.SelectedDate;
                    vac.RequestDate = DateTime.Today;

                    vac.Deleted        = false;
                    vac.NoOfDayes      = int.Parse(txtNoOfDays.Text);
                    vac.CycleID        = int.Parse(Session["CycleID"].ToString());
                    vac.VacationTypeID = int.Parse(ddlVacationType.SelectedValue);
                    vac.VacationType   = ddlVacationType.SelectedItem.ToString();

                    using (EmployeesViewDBContext Empdb = new EmployeesViewDBContext())
                    {
                        View_Employees EmpData = (from Emp_tbl in Empdb.View_Employees where Emp_tbl.EmployeeID == vac.EmpID select Emp_tbl).FirstOrDefault();
                        vac.DMID = EmpData.DirectManagerID;
                    }
                    newvac.Vacations.Add(vac);
                    int roweffected = newvac.SaveChanges();
                    if (roweffected > 0)
                    {
                        VacationslblSaveStatus.Text = "Saved";
                        Clear();
                        LoadVacations();
                    }
                    else
                    {
                        VacationslblSaveStatus.Text = "Error";
                    }
                }
            }
        }
Esempio n. 4
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();
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string Pass;

            using (AmounCRM2Entities newEmployeMD = new AmounCRM2Entities())
            {
                EmployeesMasterDataTemp EmpMD = new EmployeesMasterDataTemp();
                EmpMD.EmployeeFullName = txtName.Text;

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

            using (EmpHistoryTempEntities newHistory = new EmpHistoryTempEntities())
            {
                EmployeesHistoryTemp History = new EmployeesHistoryTemp();
                History.EmployeeHRCode = int.Parse(txtHRCode.Text);
                History.LineID         = int.Parse(ddlLine.SelectedValue);
                History.EmployeeID     = int.Parse(txtEmpID.Text);

                History.Deleted = true;
                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.EmployeesHistoryTemps.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;
                }
            }
        }