public BonuseViewModel(Bonuse bonuse)
        {
            this.bonuse = bonuse;

            NeedAmount  = bonuse.NeedAmount;
            Title       = bonuse.Title;
            Description = bonuse.Description;
            Definition  = bonuse.Definition;
        }
        public Bonuse GetUpdatedBonuse()
        {
            if (bonuse == null)
            {
                bonuse = new Bonuse();
            }
            UpdateBonuse();

            return(bonuse);
        }
Exemple #3
0
        public void excutee()
        {
            DateTime fromDate;
            DateTime toDate;
            double   bouns = 0.09;
            int      days;
            var      emp_id = (from d in db.SelfCards
                               where d.Status != "بحكم المستقيل" && d.Status != "كف اليد" && d.Status != "مصروف من الخدمة" && d.Status != "بلا أجر" && d.Status != "متوفى" && d.Status != "مستقيل" && d.Status != "متقاعد"
                               select new { d.PersonId, full = d.FirstName + " " + d.FatherName + " " + d.LastName, d.Salary, d.maxsalary, d.Workplace, d.JobTitle, d.Category, d.Register }).ToList();

            var id = emp_id.Where(d => d.full == list.Text).ToList().ElementAt(0);


            //foreach (string ss in emp.ToList())
            //{
            int    sum1   = 0;
            double amount = 0;

            double allDays = 0;
            //  var id = emp_id.Where(d => d.full == ss).ToList().ElementAt(0);
            long eid = id.PersonId;
            int  c   = db.Bonuses.Where(x => x.DecisionId == long.Parse(dec_id.Text) && x.PersonId == eid).Count();

            if (c > 0)
            {
                MessageBox.Show("  تم تطبيق هذا القرار على الموظف  " + id.full);
            }
            else
            {
                // حساب عدد ايام الدوام
                fromDate = (DateTime)from.SelectedDate;

                toDate = (DateTime)to.SelectedDate;
                //days in first yaer
                List <Rest> rests1 = db.Rests.Where(x => x.PersonId == eid && x.RestType == "إجازة بلا أجر" && x.RestStart >= fromDate && x.RestStart <= toDate).ToList();

                foreach (Rest rset in rests1)
                {
                    if (rset.Period == "يوم")
                    {
                        sum1 += rset.RestPeriod;
                    }
                    else if (rset.Period == "شهر")
                    {
                        sum1 += (rset.RestPeriod * 30);
                    }
                    else if (rset.Period == "سنة")
                    {
                        sum1 += (rset.RestPeriod * 360);
                    }
                }


                allDays = 720 - sum1;
                if (allDays >= 0)
                {
                    amount = (double)((allDays / 720) * (0.09 * id.Salary));
                    if (id.Salary + amount <= id.maxsalary)
                    {
                        Bonuse r = new Bonuse
                        {
                            PersonId    = id.PersonId,
                            DecisionId  = long.Parse(dec_id.Text),
                            Bouns       = 0.09,
                            FromYear    = (DateTime)from.SelectedDate,
                            ToYear      = (DateTime)to.SelectedDate,
                            Salary      = (double)id.Salary,
                            NumDays     = (int)allDays,
                            SalaryBouns = (double)(id.Salary + ((allDays / 720) * (0.09 * id.Salary))),
                            Workplace   = id.Workplace, JobTitle = id.JobTitle, Category = id.Category, Register = Login.regName
                        };
                        db.Bonuses.Add(r);
                        db.SaveChanges();
                        var d = db.Decisions.Where(c => c.DecisionId == long.Parse(dec_id.Text)).Single();
                        excute.IsChecked = true;
                        // d.IsExcute = true;
                        d.IsExcute = true;

                        db.Decisions.Update(d);

                        db.SaveChanges();
                        (from p in db.SelfCards
                         where p.PersonId == eid
                         select p).ToList()
                        .ForEach(x => x.Salary = (double)(id.Salary + ((allDays / 720) * (0.09 * id.Salary))));
                        db.SaveChanges();
                    }
                    else if (id.Salary + amount > id.maxsalary)
                    {
                        Bonuse r = new Bonuse
                        {
                            PersonId    = id.PersonId,
                            DecisionId  = long.Parse(dec_id.Text),
                            Bouns       = 0.09,
                            FromYear    = (DateTime)from.SelectedDate,
                            ToYear      = (DateTime)to.SelectedDate,
                            Salary      = (double)id.Salary,
                            NumDays     = (int)allDays,
                            SalaryBouns = (double)(id.Salary + (id.maxsalary - id.Salary)),
                            Workplace   = id.Workplace,
                            JobTitle    = id.JobTitle,
                            Category    = id.Category,
                            Register    = Login.regName
                        };
                        db.Bonuses.Add(r);
                        db.SaveChanges();
                        var d = db.Decisions.Where(c => c.DecisionId == long.Parse(dec_id.Text)).Single();
                        excute.IsChecked = true;
                        // d.IsExcute = true;
                        d.IsExcute = true;

                        db.Decisions.Update(d);

                        db.SaveChanges();
                        (from p in db.SelfCards
                         where p.PersonId == eid
                         select p).ToList()
                        .ForEach(x => x.Salary = (double)(id.Salary + ((allDays / 720) * (0.09 * id.Salary))));
                        db.SaveChanges();
                    }
                }
                else if (allDays < 0)
                {
                    Bonuse r = new Bonuse
                    {
                        PersonId    = id.PersonId,
                        DecisionId  = long.Parse(dec_id.Text),
                        Bouns       = 0.09,
                        FromYear    = (DateTime)from.SelectedDate,
                        ToYear      = (DateTime)to.SelectedDate,
                        Salary      = (double)id.Salary,
                        NumDays     = 0,
                        SalaryBouns = (double)id.Salary,
                        Workplace   = id.Workplace,
                        JobTitle    = id.JobTitle,
                        Category    = id.Category,
                        Register    = Login.regName
                    };
                    db.Bonuses.Add(r);
                    db.SaveChanges();
                    var d = db.Decisions.Where(c => c.DecisionId == long.Parse(dec_id.Text)).Single();
                    excute.IsChecked = true;
                    // d.IsExcute = true;
                    d.IsExcute = true;

                    db.Decisions.Update(d);

                    db.SaveChanges();
                }
            }

            // }
            list.SelectedItem = null;



            this.Visibility = Visibility.Collapsed;



            MessageBox.Show("تمت عملية الانتهاء من تنفيذ قرار الترفيعة");
            Decision_View dv           = new Decision_View();
            Window        parentWindow = Window.GetWindow(this);

            parentWindow.Close();
            dv.Show();
        }
Exemple #4
0
        public void excutee()
        {
            //var emp_id = (from d in db.SelfCards select new { d.PersonId, full = d.FirstName + " " + d.FatherName + " " + d.LastName }).ToList();

            //emp= emp_id.Where(d => d.full == emp_list.Text).FirstOrDefault().ToString();

            //long empId = id.PersonId;
            //emp = empname.Text;///////////
            var id = (from x in db.SelfCards
                      where x.FirstName + " " + x.FatherName + " " + x.LastName == emp_list.Text
                      select new { x.PersonId, x.Salary, x.maxsalary, x.Category, x.Workplace, x.JobTitle }).Single();


            double amount = 0;


            long eid = id.PersonId;
            int  c   = db.Bonuses.Where(x => x.DecisionId == long.Parse(dec_id.Text) && x.PersonId == eid).Count();

            if (c > 0)
            {
                MessageBox.Show("  تم تطبيق هذا القرار على الموظف  " + emp_list.Text);
            }
            else

            {
                var query = (from p in db.Bonuses
                             join d in db.Decisions on p.DecisionId equals d.DecisionId
                             where p.PersonId == eid && d.DecisionContent == "قرار ترفيعة استثنائية"
                             select new { p.DecisionId, fu = (d.DecisionNumber + " " + d.DecisionType + " " + d.DecisionYear) }).Count();



                if (query > 0)
                {
                    MessageBox.Show("   تم منح ترفيعة استثنائية من قبل  للموظف " + emp_list.Text);
                }
                else
                {
                    if (id.Category == "الأولى")
                    {
                        amount = 1000;
                    }

                    else if (id.Category == "الثانية")
                    {
                        amount = 600;
                    }
                    Bonuse r = new Bonuse
                    {
                        PersonId    = id.PersonId,
                        DecisionId  = long.Parse(dec_id.Text),
                        Bouns       = amount,
                        FromYear    = null,
                        ToYear      = null,
                        Salary      = (double)id.Salary,
                        NumDays     = 0,
                        SalaryBouns = (double)(id.Salary + amount),
                        Workplace   = id.Workplace,
                        JobTitle    = id.JobTitle,
                        Category    = id.Category,
                        Register    = Login.regName
                    };
                    db.Bonuses.Add(r);
                    db.SaveChanges();
                    (from p in db.SelfCards
                     where p.PersonId == eid
                     select p).ToList()
                    .ForEach(x => x.Salary = (double)(id.Salary + amount));
                    db.SaveChanges();

                    MessageBox.Show("تمت عملية الانتهاء من تنفيذ قرار الترفيعة");
                    string message = "هل انتهى تنفيذ القرار؟";
                    string caption = "تنبيه";
                    var    result  = MessageBox.Show(message, caption,
                                                     MessageBoxButton.YesNo,
                                                     MessageBoxImage.Question);
                    if (result == MessageBoxResult.Yes)
                    {
                        emp_list.Text   = null;
                        this.Visibility = Visibility.Collapsed;
                        var d = db.Decisions.Where(c => c.DecisionId == long.Parse(dec_id.Text)).Single();
                        excute.IsChecked = true;
                        // d.IsExcute = true;
                        d.IsExcute = true;

                        db.Decisions.Update(d);

                        db.SaveChanges();


                        this.Visibility = Visibility.Collapsed;



                        Decision_View dv           = new Decision_View();
                        Window        parentWindow = Window.GetWindow(this);
                        parentWindow.Close();
                        dv.Show();
                    }
                    else if (result == MessageBoxResult.No)
                    {
                        emp_list.Text = null;
                    }
                }
            }
        }