protected void btnAdd_Click(object sender, EventArgs e)
    {
        var          idd   = int.Parse(Request.QueryString["id"]);
        AbsenceAlert alert = (from k in km.AbsenceAlerts where k.Id == idd select k).FirstOrDefault();

        alert.Reason = txtReson.Text;
        if (Calendar1.CultureName == "ar-SA")
        {
            alert.ReplyDate    = MyDate.convertHijriToGregorian(txtDateReplayEmp.Text);
            alert.DecisionDate = MyDate.convertHijriToGregorian(txtDateReplay.Text);
        }
        else
        {
            alert.ReplyDate    = DateTime.ParseExact(txtDateReplayEmp.Text, "yyyy/MM/dd", CultureInfo.CreateSpecificCulture("ar-EG"));
            alert.DecisionDate = DateTime.ParseExact(txtDateReplay.Text, "yyyy/MM/dd", CultureInfo.CreateSpecificCulture("ar-EG"));
        }

        var decition = lstDecition.SelectedValue;

        alert.Decision = decition;
        var year          = DateTime.Now.Year;
        int vacationCount = (from k in km.Schools where k.Id == alert.SchoolId select k.VacationNumber).FirstOrDefault();

        if (decition == "اضطرارية")
        {
            EmployeesVacation empvacation = (from k in km.EmployeesVacations where k.Year == year && k.EmployeeId == alert.EmployeeId select k).FirstOrDefault();

            if (empvacation == null)
            {
                empvacation                = new EmployeesVacation();
                empvacation.EmployeeId     = alert.EmployeeId;
                empvacation.VacationNumber = vacationCount - 1;
                empvacation.Year           = year;
                km.EmployeesVacations.Add(empvacation);
            }
            else
            if (empvacation.VacationNumber == 0)
            {
                alert.Decision = "حسم";
            }
            else
            {
                empvacation.VacationNumber = (empvacation.VacationNumber) - 1;
            }
        }
        else
        if (decition == "حسم")
        {
        }
        else
        if (decition == "مرضية")
        {
        }
        clearText();
        km.SaveChanges();
        ClientScript.RegisterStartupScript(this.GetType(), "openModal", "<script> openModal(); </script>", false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["id"] != null || Request.QueryString["view"] != null)
            {
                Calendar1.DataBind();
                Calendar2.DataBind();
                int idd = 0;
                if (Request.QueryString["id"] != null)
                {
                    idd = int.Parse(Request.QueryString["id"]);
                }
                else
                {
                    idd = int.Parse(Request.QueryString["view"]);
                }

                AbsenceAlert absence = (from k in km.AbsenceAlerts where k.Id == idd select k).FirstOrDefault();

                var emp = (from k in km.Employees where k.IdentityNumber == absence.EmployeeId select k).FirstOrDefault();
                lblEmpName.Text  = emp.Name;
                lblIdentity.Text = emp.IdentityNumber;
                lblfrom.Text     = MyDate.getDate(absence.DateFrom + "");
                lblto.Text       = MyDate.getDate(absence.DateTo + "");
                lblCount.Text    = absence.count + "";


                if (Request.QueryString["view"] != null)
                {
                    btnAdd.Visible    = false;
                    Calendar1.Visible = false;
                    Calendar2.Visible = false;

                    txtDateReplay.Text    = MyDate.getDate(absence.DecisionDate + "");
                    txtDateReplayEmp.Text = MyDate.getDate(absence.ReplyDate + "");
                    txtReson.Text         = absence.Reason;

                    txtDateReplay.Enabled    = false;
                    txtDateReplayEmp.Enabled = false;
                    txtReson.Enabled         = false;

                    lstDecition.SelectedValue = absence.Decision;
                    lstDecition.Enabled       = false;
                }
            }
        }
    }
예제 #3
0
    protected void btnsave_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            SchoolInformation info   = new SchoolInformation();
            MyDate            mydate = new MyDate();

            foreach (ListViewItem item in ListView1.Items)
            {
                Button btnActive = (Button)item.FindControl("btnActive");
                if (btnActive.Text == "غياب")
                {
                    Absence abs = new Absence();
                    abs.SemesterId = MyDate.getCurrentSemesterId();
                    abs.SchoolId   = info.getId();
                    var empId = ((HiddenField)item.FindControl("HiddenField1")).Value.ToString();
                    abs.EmployeeId = empId;
                    if (Calendar1.CultureName == "ar-SA")
                    {
                        abs.Date = MyDate.convertHijriToGregorian(datepicker.Text);
                    }
                    else
                    {
                        abs.Date = DateTime.ParseExact(datepicker.Text, "yyyy/MM/dd", CultureInfo.CreateSpecificCulture("ar-EG"));
                    }

                    abs.Type = int.Parse(((DropDownList)item.FindControl("lstResonLate")).SelectedValue);

                    var today = DateTime.Now.DayOfWeek;

                    var schoolid = info.getId();

                    DateTime yesterday = DateTime.Now.AddDays(-1).Date;
                    if (today == DayOfWeek.Sunday)
                    {
                        yesterday = DateTime.Now.AddDays(-3).Date;
                    }

                    var absentYesterday = ((from k in km.Absences where k.EmployeeId == empId && k.Date == yesterday select k).FirstOrDefault());
                    if (absentYesterday != null)
                    {
                        AbsenceAlert alert = (from k in km.AbsenceAlerts where k.Id == absentYesterday.AlertId select k).FirstOrDefault();
                        alert.DateTo = DateTime.Now;
                        abs.AlertId  = alert.Id;
                        alert.count++;
                        if (today == DayOfWeek.Sunday)
                        {
                            alert.countHoliday = alert.countHoliday + 2;
                        }
                    }
                    else
                    {
                        AbsenceAlert alert = new AbsenceAlert();
                        alert.SemesterId   = MyDate.getCurrentSemesterId();
                        alert.SchoolId     = info.getId();
                        alert.EmployeeId   = empId;
                        alert.DateFrom     = DateTime.Now;
                        alert.DateTo       = DateTime.Now;
                        alert.count        = 1;
                        alert.countHoliday = 0;
                        km.AbsenceAlerts.Add(alert);
                        km.SaveChanges();

                        abs.AlertId = alert.Id;
                    }

                    lstAbs.Add(abs);
                    km.Absences.Add(abs);
                    km.SaveChanges();
                }
                else if (btnActive.Text == "حضور")
                {
                    Attendence att = new Attendence();
                    att.Date = DateTime.Now;
                    var schoolId = info.getId();
                    att.SchoolId   = schoolId;
                    att.SemesterId = MyDate.getCurrentSemesterId();
                    att.EmployeeId = ((HiddenField)item.FindControl("HiddenField1")).Value;
                    TextBox txtArrive = (TextBox)item.FindControl("txtarrivingTime");
                    if (!String.IsNullOrEmpty(txtArrive.Text))
                    {
                        att.ArrivingTime = Convert.ToDateTime(txtArrive.Text).TimeOfDay;
                    }
                    TextBox txtDeparture = (TextBox)item.FindControl("txtdeptime");
                    if (!String.IsNullOrEmpty(txtDeparture.Text))
                    {
                        TimeSpan departure   = Convert.ToDateTime(txtDeparture.Text).TimeOfDay;
                        var      timeWorkEnd = (from k in km.Schools where k.Id == schoolId select k.TimeEndWork).FirstOrDefault();
                        var      amount      = timeWorkEnd - departure;
                        if (amount.TotalSeconds > 0)
                        {
                            Lateness late = new Lateness();
                            late.Amount       = amount;
                            late.TotalSeconds = amount.TotalSeconds;
                            late.IsPrinted    = false;
                            late.Type         = ConstantManager.getConstantId("انصراف مبكر");
                            late.SchoolId     = schoolId;
                            late.SemesterId   = MyDate.getCurrentSemesterId();
                            late.Date         = DateTime.Now.Date;
                            late.EmployeeId   = ((HiddenField)item.FindControl("HiddenField1")).Value;
                            km.Latenesses.Add(late);
                        }
                        att.DepartureTime = departure;
                    }

                    km.Attendences.Add(att);
                    km.SaveChanges();
                }
                else if (btnActive.Text == "تأخر")
                {
                    Lateness late = new Lateness();

                    if (!String.IsNullOrEmpty(((TextBox)item.FindControl("TimeLate")).Text))
                    {
                        var schoolId = info.getId();

                        TimeSpan timearrive    = Convert.ToDateTime(((TextBox)item.FindControl("TimeLate")).Text).TimeOfDay;
                        TimeSpan timestartwork = (TimeSpan)(from k in km.Schools where k.Id == schoolId select k.TimeStartWork).FirstOrDefault();
                        TimeSpan amount        = timearrive - timestartwork;
                        if (amount.TotalSeconds > 0)
                        {
                            late.TotalSeconds = amount.TotalSeconds;
                            late.Type         = ConstantManager.getConstantId("تأخر صباحي");
                            late.Amount       = amount;
                            late.Date         = DateTime.Now;
                            late.SchoolId     = info.getId();
                            late.SemesterId   = MyDate.getCurrentSemesterId();
                            var empId = ((HiddenField)item.FindControl("HiddenField1")).Value;
                            late.EmployeeId = empId;
                            km.Latenesses.Add(late);
                            var year = DateTime.Now.Year;

                            var lateSum = (from k in km.Latenesses
                                           where k.EmployeeId == empId && k.Date.Value.Year == year
                                           select k.TotalSeconds).Sum();

                            if (lateSum != null)
                            {
                                var total = lateSum + late.TotalSeconds;

                                var currentLate = (int)lateSum / 3600;
                                var totalLate   = (int)total / 3600;

                                if (totalLate >= 7 && totalLate > currentLate)
                                {
                                    //اضافة حسم
                                    LatenessDecision alertdecition = new LatenessDecision();
                                    alertdecition.SchoolId   = info.getId();
                                    alertdecition.SemesterId = MyDate.getCurrentSemesterId();
                                    alertdecition.Date       = DateTime.Now.Date;
                                    alertdecition.Days       = 1;
                                    alertdecition.EmployeeId = empId;
                                    alertdecition.Hours      = totalLate;
                                    km.LatenessDecisions.Add(alertdecition);
                                }
                                else
                                if (totalLate >= 3 && totalLate > currentLate)
                                {
                                    //اضافة تنبيه
                                    LatenessDecision alertdecition = new LatenessDecision();
                                    alertdecition.SchoolId   = info.getId();
                                    alertdecition.SemesterId = MyDate.getCurrentSemesterId();
                                    alertdecition.Date       = DateTime.Now.Date;
                                    alertdecition.Days       = 0;
                                    alertdecition.EmployeeId = empId;
                                    alertdecition.Hours      = totalLate;
                                    km.LatenessDecisions.Add(alertdecition);
                                }
                            }
                        }
                        else
                        {
                            Attendence att = new Attendence();
                            att.Date         = DateTime.Now;
                            att.SchoolId     = info.getId();
                            att.SemesterId   = MyDate.getCurrentSemesterId();
                            att.EmployeeId   = ((HiddenField)item.FindControl("HiddenField1")).Value;
                            att.ArrivingTime = timearrive;

                            km.Attendences.Add(att);
                        }
                    }
                    km.SaveChanges();
                }
            }

            Response.Redirect("~/EmployeeAttendence/AttendenceReport.aspx");
        }
    }