Beispiel #1
0
        public string Update_Database(ECheckSubmit AreaData)
        {
            string        Excp          = string.Empty;
            Data_Services Data_Services = new Data_Services(DataContext);

            try
            {
                var area = Data_Services.Get_ECheckArea(AreaData.Area_Id);

                if (area == null)
                {
                    return($"Can not find aread with id {AreaData.Area_Id}");
                }

                if (area.ECheckings.Count != AreaData.CheckItems.Count)
                {
                    return($"Total items not equal");
                }

                var person = Data_Services.Get_CheckPerson(AreaData.CheckPerson_Id);
                if (person == null)
                {
                    return($"Can not find person Id: {AreaData.CheckPerson_Id}");
                }


                ESubmit ESubmit = new ESubmit
                {
                    AreaId     = area.id,
                    PersonId   = person.id,
                    Date       = DateTime.Now,
                    UpdateTime = DateTime.Now.ToString("hh:mm tt, dd/MM/yy"),
                };

                // update new esubmit
                Data_Services.Update_ESubmit(ESubmit);

                foreach (var item in AreaData.CheckItems)
                {
                    var CheckItem = Data_Services.Get_ECheckItem(item.Item);

                    var submit_data = new ECheckingDaily
                    {
                        ECheckAreaCode   = area.AreaCode,
                        ECheckAreaId     = area.id,
                        ECheckItemId     = CheckItem.id,
                        ECheckItemCode   = CheckItem.ECheckItemCode,
                        Status           = item.Status,
                        Time             = DateTime.Now,
                        CheckingPersonId = person.id,
                        ESubmitId        = ESubmit.Id,
                    };

                    if (item.Status == 0x00)
                    {
                        submit_data.ECheckNotesId = item.Note;
                    }

                    if (!Data_Services.Update_ECheckDaily(submit_data))
                    {
                        Excp = $"Error when add item {item.Item} to database";
                    }
                }

                return(Excp);
            }
            catch (Exception ex)
            { return(ex.ToString()); }
        }
Beispiel #2
0
        public bool UpdateToExcel(ECheckSubmit AreaData, string path)
        {
            FileInfo CurrentExcel = new FileInfo(path);
            DateTime Time         = DateTime.Now;
            int      currentHour  = Time.Hour;
            int      Area_Id      = AreaData.Area_Id;
            int      Person_Id    = AreaData.CheckPerson_Id;


            try
            {
                var ECheckPerson = Data_Services.Get_CheckPerson(Person_Id);

                using (ExcelPackage excelPackage = new ExcelPackage(CurrentExcel, "echecklist"))
                {
                    ExcelWorksheet currentSheet = excelPackage.Workbook.Worksheets[Area_Id];

                    for (int checkItem = 0; checkItem < AreaData.CheckItems.Count; checkItem++)
                    {
                        int currentTime = 0;
                        for (int timeLine = 0; timeLine < 12; timeLine++)
                        {
                            if (currentHour == 0 && timeLine == 0)
                            {
                                currentTime = 0;
                                if (AreaData.CheckItems[checkItem].Status == 0xFF)
                                {
                                    currentSheet.Cells[checkItem + 5, 1].Value           = "X";
                                    currentSheet.Cells[checkItem + 5, 1].Style.Font.Bold = true;

                                    currentSheet.Cells[checkItem + 5, 2].Value = string.Empty;
                                }
                                else
                                {
                                    currentSheet.Cells[checkItem + 5, 1].Value = string.Empty;

                                    currentSheet.Cells[checkItem + 5, 2].Value           = "X";
                                    currentSheet.Cells[checkItem + 5, 2].Style.Font.Bold = true;
                                }
                            }
                            else
                            {
                                if (currentHour / 2 == timeLine)
                                {
                                    currentTime = timeLine * 2 + 2;
                                    if (AreaData.CheckItems[checkItem].Status == 0xFF)
                                    {
                                        currentSheet.Cells[checkItem + 5, timeLine * 2 + 2].Value           = "X";
                                        currentSheet.Cells[checkItem + 5, timeLine * 2 + 2].Style.Font.Bold = true;

                                        currentSheet.Cells[checkItem + 5, timeLine * 2 + 1 + 2].Value = string.Empty;
                                    }
                                    else
                                    {
                                        currentSheet.Cells[checkItem + 5, timeLine * 2 + 2].Value = string.Empty;

                                        currentSheet.Cells[checkItem + 5, timeLine * 2 + 1 + 2].Value           = "X";
                                        currentSheet.Cells[checkItem + 5, timeLine * 2 + 1 + 2].Style.Font.Bold = true;
                                    }
                                }
                            }
                        }
                        if (ECheckPerson != null)
                        {
                            currentSheet.Cells[AreaData.CheckItems.Count + 5, currentTime].Value = ECheckPerson.Name;
                        }
                    }

                    excelPackage.Save();
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }