Exemplo n.º 1
0
        public ActionResult Create(int id, WorkCountViewModel collection)
        {
            try
            {
                using (OnlineShopDbContext db = new OnlineShopDbContext())
                {
                    WorkCountViewModel model = new WorkCountViewModel();
                    model.Thiet_Bi   = db.Thiet_Bis.OrderBy(m => m.ID).ToList();
                    model.ProjectAll = new List <SelectListItem>();

                    var items = new List <SelectListItem>();
                    foreach (var project in model.Thiet_Bi)
                    {
                        items.Add(new SelectListItem()
                        {
                            Value = project.Ten_Thiet_Bi,
                            Text  = project.Ten_Thiet_Bi,
                        });
                    }

                    model.ProjectAll = items;

                    var Check = model.Thiet_Bi[0].Ten_Thiet_Bi;

                    model.Catelory_Project = db.Catelories.Where(i => i.Prj_Name == Check).ToList();

                    model.Number_Team_2   = model.Catelory_Project.Count();
                    model.SelectedProject = null;
                    int j = 0;

                    model.WorkCount = db.WorkCounts.Where(i => i.CreateDate == collection.SelectedWorkCount.CreateDate).ToList();

                    if (model.WorkCount.Count() != 0)
                    {
                        return(View("Index", model));
                    }

                    foreach (var item in collection.Count_Number)
                    {
                        WorkCount obj = new WorkCount();

                        model.WorkCount = db.WorkCounts.Where(i => i.CreateDate == collection.SelectedWorkCount.CreateDate).ToList();

                        obj.Ten_Thiet_Bi = Check;
                        obj.Unit_Name    = model.Catelory_Project[j].Unit_Name;
                        obj.CreateDate   = collection.SelectedWorkCount.CreateDate;
                        obj.Unit_Number  = item;

                        db.WorkCounts.Add(obj);
                        db.SaveChanges();
                        j = j + 1;
                    }
                    return(View("Index", model));
                }
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 2
0
        //
        // GET: /Admin/WorkCount/

        public ActionResult Index()
        {
            using (OnlineShopDbContext db = new OnlineShopDbContext())
            {
                WorkCountViewModel model = new WorkCountViewModel();

                model.Thiet_Bi   = db.Thiet_Bis.OrderBy(m => m.ID).ToList();
                model.ProjectAll = new List <SelectListItem>();

                var items = new List <SelectListItem>();
                foreach (var project in model.Thiet_Bi)
                {
                    items.Add(new SelectListItem()
                    {
                        Value = project.Ten_Thiet_Bi,
                        Text  = project.Ten_Thiet_Bi,
                    });
                }

                model.ProjectAll = items;

                var Check = model.Thiet_Bi[0].Ten_Thiet_Bi;

                model.Catelory_Project = db.Catelories.Where(i => i.Prj_Name == Check).ToList();

                model.Number_Team_2 = model.Catelory_Project.Count();

                model.WorkCount = null;

                return(View(model));
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, WorkCountViewModel collection)
        {
            try
            {
                using (OnlineShopDbContext db = new OnlineShopDbContext())
                {
                    WorkCountViewModel model = new WorkCountViewModel();

                    model.Thiet_Bi   = db.Thiet_Bis.OrderBy(m => m.ID).ToList();
                    model.ProjectAll = new List <SelectListItem>();

                    var items = new List <SelectListItem>();

                    foreach (var project in model.Thiet_Bi)
                    {
                        items.Add(new SelectListItem()
                        {
                            Value = project.Ten_Thiet_Bi,
                            Text  = project.Ten_Thiet_Bi,
                        });
                    }

                    model.ProjectAll = items;

                    var Check = model.Thiet_Bi[0].Ten_Thiet_Bi;

                    model.Catelory_Project = db.Catelories.Where(i => i.Prj_Name == Check).ToList();

                    model.Number_Team_2   = model.Catelory_Project.Count();
                    model.SelectedProject = null;

                    model.WorkCount = db.WorkCounts.Where(i => i.Ten_Thiet_Bi == collection.SelectedProject.Ten_Thiet_Bi && i.CreateDate >= collection.StartDate && i.CreateDate <= collection.EndDate).ToList();

                    var dates = new List <DateTime>();

                    for (var dt = collection.StartDate; dt <= collection.EndDate; dt = dt.AddDays(1))
                    {
                        dates.Add(dt);
                    }

                    model.SelectDate = dates;

                    return(View("Index", model));
                }
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 4
0
        public ActionResult Edit(int id, WorkCountViewModel collection)
        {
            try
            {
                using (OnlineShopDbContext db = new OnlineShopDbContext())
                {
                    WorkCountViewModel model = new WorkCountViewModel();

                    model.Thiet_Bi   = db.Thiet_Bis.OrderBy(m => m.ID).ToList();
                    model.ProjectAll = new List <SelectListItem>();

                    var items = new List <SelectListItem>();

                    foreach (var project in model.Thiet_Bi)
                    {
                        items.Add(new SelectListItem()
                        {
                            Value = project.Ten_Thiet_Bi,
                            Text  = project.Ten_Thiet_Bi,
                        });
                    }

                    model.ProjectAll = items;

                    var Check = model.Thiet_Bi[0].Ten_Thiet_Bi;

                    model.Catelory_Project = db.Catelories.Where(i => i.Prj_Name == Check).ToList();

                    model.Number_Team_2   = model.Catelory_Project.Count();
                    model.SelectedProject = null;

                    collection.Catelory_Project = model.Catelory_Project;

                    var dates               = new List <DateTime>();
                    var all_number          = new List <int>();
                    var all_job_number_temp = new List <int>();
                    var all_job_number      = new List <List <int> >();

                    var Date       = db.WorkCounts.Where(i => i.CreateDate >= collection.StartDate && i.CreateDate <= collection.EndDate).Select(i => i.CreateDate).Distinct().ToList();
                    var Date_Count = db.WorkCounts.Where(i => i.CreateDate >= collection.StartDate && i.CreateDate <= collection.EndDate).Select(i => i.CreateDate).Distinct().Count();

                    model.List_Job   = db.WorkCounts.Where(i => i.CreateDate >= collection.StartDate && i.CreateDate <= collection.EndDate).Select(i => i.Unit_Job).Distinct().ToList();
                    model.Number_Job = db.WorkCounts.Where(i => i.CreateDate >= collection.StartDate && i.CreateDate <= collection.EndDate).Select(i => i.Unit_Job).Distinct().Count();

                    DateTime Date_te = Convert.ToDateTime(Date[0]);
                    var      dt      = Date_te;

                    List <List <WorkCount> > myList = new List <List <WorkCount> >();

                    for (var temp_test = 0; temp_test < Date_Count; dt = dt.AddDays(1), temp_test++)
                    {
                        DateTime Date_Temp_Test = Convert.ToDateTime(Date[temp_test]);
                        dates.Add(Date_Temp_Test);

                        model.WorkCount = db.WorkCounts.Where(i => i.Ten_Thiet_Bi == collection.SelectedProject.Ten_Thiet_Bi && i.CreateDate == Date_Temp_Test).ToList();
                        myList.Add(model.WorkCount);

                        int temp_all_number = 0;

                        for (var j = 0; j < model.WorkCount.Count(); j++)
                        {
                            temp_all_number = temp_all_number + (int)model.WorkCount[j].Unit_Number;
                        }

                        all_number.Add(temp_all_number);

                        for (var j = 0; j < model.Number_Job; j++)
                        {
                            int temp_job_all_number = 0;
                            int temp_job            = 0;

                            for (var i = 0; i < model.WorkCount.Count(); i++)
                            {
                                if (model.WorkCount[i].Unit_Job == model.List_Job[j])
                                {
                                    temp_job_all_number = temp_job_all_number + (int)model.WorkCount[i].Unit_Number;
                                }

                                temp_job = i;
                            }

                            all_job_number_temp.Add(temp_job_all_number);
                        }
                    }

                    List <List <WorkCount> > myList_2 = new List <List <WorkCount> >();

                    foreach (var item in collection.Catelory_Project)
                    {
                        model.WorkCount_Temp_2 = db.WorkCounts.Where(i => i.Ten_Thiet_Bi == collection.SelectedProject.Ten_Thiet_Bi && i.Unit_Name == item.Unit_Name && i.CreateDate >= collection.StartDate && i.CreateDate <= collection.EndDate).OrderBy(i => i.CreateDate).ToList();
                        myList_2.Add(model.WorkCount_Temp_2);
                    }

                    model.WorkCount_List   = myList;
                    model.WorkCount_List_2 = myList_2;

                    model.SelectDate   = dates;
                    model.Total_number = all_number;

                    model.Total_Job_number_2 = all_job_number_temp;

                    return(View("Index", model));
                }
            }
            catch
            {
                return(View());
            }
        }