public void Submit_NextCheck() { if (CurrentCheck != null) { var area = CurrentCheck.Get_NextArea(); if (area == null || CurrentCheck.UpdateDone) { CurrentCheck = new AutoCheck_Handle(); IsPosting = false; return; } ECheckSubmit eCheckSubmit = new ECheckSubmit { Area_Id = area.id, CheckPerson_Id = CurrentCheck.CheckingPerson.id, }; eCheckSubmit.CheckItems = new List <EItem>(); foreach (var item in area.ECheckings) { eCheckSubmit.CheckItems.Add(new EItem { Item = item.ECheckItemCode, Status = 0xFF, }); } var request = (HttpWebRequest)WebRequest.Create("http://10.10.10.3:32760/echecklist/post"); //var request = (HttpWebRequest)WebRequest.Create("http://10.4.3.41:32760/echecklist/post"); //var request = (HttpWebRequest)WebRequest.Create("http://localhost:32760/echecklist/post"); var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(eCheckSubmit)); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); if (responseString.ToLower().IndexOf("true") > -1) { CurrentCheck.IncreaseIndex(); } } }
public SubmitServices(DataContext DataContext, ECheckSubmit submit) { Data_Services = new Data_Services(DataContext); ServerExport ServerExport = new ServerExport(DataContext); try { Exception = ServerExport.Update_Database(submit); Success = true; AreadId = submit.Area_Id; } catch (Exception ex) { Success = false; Exception = ex.ToString(); } }
public IHttpActionResult ECheckListStation_Post([FromBody] ECheckSubmit ECheckSubmit) { SubmitServices submitServices = new SubmitServices(DataContext, ECheckSubmit); return(Json(submitServices)); }
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()); } }
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); } }