public TranLoadPreFill PreFillTranLoadAction(string wayBillNo) { V_SHIPPING_ALL_BASE_BLL saBLL = new V_SHIPPING_ALL_BASE_BLL(); V_SHIPPING_ALL_BASE sa = saBLL.GetFirstBaseInfo(wayBillNo); TranLoadPreFill result = new TranLoadPreFill(); if (sa != null) { result.InvoiceNo = sa.INVOICE_NO; result.TranType = sa.TRAN_TYPE; result.FromSystem = sa.FROM_SYSTEM; result.Msg = ""; result.BackColor = ""; //if (!string.IsNullOrEmpty(result.InvoiceNo)) //{ // ITT_TRAN_LOAD_BLL tlBLL = new ITT_TRAN_LOAD_BLL(); // if (tlBLL.ExistInvoiceNo(result.InvoiceNo)) // { // result.Msg = "Invoice No is exist"; // result.BackColor = CHubConstValues.ErrorColor; // } //} } else { result.Msg = "Can't Find Invoice No from WayBillNo"; result.BackColor = ""; } return(result); }
public ActionResult PrefillByInovice(string invoiceNo) { try { V_SHIPPING_ALL_BASE_BLL saBLL = new V_SHIPPING_ALL_BASE_BLL(); V_SHIPPING_ALL_BASE sa = saBLL.GetFirstBaseInfoByInvoice(invoiceNo); TranLoadPreFill result = new TranLoadPreFill(); if (sa != null) { result.InvoiceNo = sa.INVOICE_NO; result.TranType = sa.TRAN_TYPE; result.FromSystem = sa.FROM_SYSTEM; result.Msg = ""; result.BackColor = ""; //ITT_TRAN_LOAD_BLL tlBLL = new ITT_TRAN_LOAD_BLL(); //if (tlBLL.ExistInvoiceNo(result.InvoiceNo)) //{ // result.Msg = "Invoice No is exist"; // result.BackColor = CHubConstValues.ErrorColor; //} } else { result.Msg = "Invalid invoice No"; result.BackColor = CHubConstValues.ErrorColor; } return(Json(new RequestResult(result))); } catch (Exception ex) { return(Json(new RequestResult(false, ex.Message))); } }
public ActionResult PreFillTranLoad(string wayBillNo) { try { TranLoadPreFill result = PreFillTranLoadAction(wayBillNo); return(Json(new RequestResult(result))); } catch (Exception ex) { LogHelper.WriteLog("Pre Fill TranLoad", ex); return(Json(new RequestResult(false, ex.Message))); } }
public ActionResult UploadTranLoadFile() { try { HttpPostedFileBase fb = Request.Files[0]; string tempGuid = Guid.NewGuid().ToString(); string folderPath = Server.MapPath(CHubConstValues.ChubTempFolder); FileInfo folder = new FileInfo(folderPath); if (!Directory.Exists(folder.FullName)) { Directory.CreateDirectory(folder.FullName); } //fb.filename - to get short file name parse string string errorLogName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + tempGuid + ".txt"; string errorLogWebName = "/temp/" + errorLogName; string errorLogFullName = folder.FullName + errorLogName; TxtLog txtLog = new TxtLog(); StringBuilder errorMsg = new StringBuilder(); errorMsg.AppendLine(string.Format("Current User:{0}", Session[CHubConstValues.SessionUser].ToString())); string fileFullName = folder.FullName + tempGuid + ".xlsx"; fb.SaveAs(fileFullName); NPOIExcelHelper excelHelper = new NPOIExcelHelper(fileFullName); DataTable dt = excelHelper.ExcelToDataTable(); //LogHelper.WriteLog("DT data:"+dt.Rows[0][3].ToString() +"|"+ dt.Rows[0][4].ToString() + "|" + dt.Rows[0][5].ToString()); //Delete temp file System.IO.File.Delete(fileFullName); if (dt == null || dt.Rows.Count == 0) { return(Json(new RequestResult(false, "No data in excel"))); } //DataTable dt = ExcelHelper.GetDTFromExcel(fileFullName); List <ITT_TRAN_LOAD> modelList = ClassConvert.ConvertDT2List <ITT_TRAN_LOAD>(dt); if (modelList == null || modelList.Count == 0) { return(Json(new RequestResult(false, "wrong excel struct"))); } int successCount = 0; int failCount = 0; foreach (var item in modelList) { if (item.INVOICE_NO != null && item.INVOICE_NO.Contains("/")) { string[] invoiceArray = item.INVOICE_NO.Split('/'); foreach (var inNo in invoiceArray) { ITT_TRAN_LOAD model = new ITT_TRAN_LOAD(); ClassConvert.DrawObj(item, model); model.INVOICE_NO = inNo.Trim(); string msgInside = SaveTranLoadAction(model); if (string.IsNullOrEmpty(msgInside)) { successCount++; LogHelper.WriteLog(string.Format("willBillNo:{0},Data:{1}", item.WILL_BILL_NO, JsonConvert.SerializeObject(item))); } else { failCount++; LogHelper.WriteErrorLog(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msgInside, JsonConvert.SerializeObject(item))); errorMsg.AppendLine(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msgInside, JsonConvert.SerializeObject(item))); //txtLog.log(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msgInside, JsonConvert.SerializeObject(item)), errorLogFullName); } } } else { //If no invoce no , do a prefill ation if (string.IsNullOrEmpty(item.INVOICE_NO)) { TranLoadPreFill result = PreFillTranLoadAction(item.WILL_BILL_NO); if (!string.IsNullOrEmpty(result.Msg)) { failCount++; LogHelper.WriteErrorLog(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, result.Msg, JsonConvert.SerializeObject(item))); errorMsg.AppendLine(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, result.Msg, JsonConvert.SerializeObject(item))); continue; } else { //prefill action item.INVOICE_NO = result.InvoiceNo; item.TRAN_TYPE = result.TranType; item.FROM_SYSTEM = result.FromSystem; } } string msg = SaveTranLoadAction(item); if (string.IsNullOrEmpty(msg)) { successCount++; LogHelper.WriteLog(string.Format("willBillNo:{0},Data:{1}", item.WILL_BILL_NO, JsonConvert.SerializeObject(item))); } else { failCount++; LogHelper.WriteErrorLog(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msg, JsonConvert.SerializeObject(item))); errorMsg.AppendLine(string.Format("willBillNo:{0},message:{1},data:{2}", item.WILL_BILL_NO, msg, JsonConvert.SerializeObject(item))); } } } bool success = true; if (failCount > 0) { txtLog.log(errorMsg.ToString(), errorLogFullName); success = false; } return(Json(new RequestResult(success, string.Format("Total Lines:{0}, Success items:{1}, Fail items:{2}", modelList.Count, successCount, failCount), errorLogWebName))); } catch (Exception ex) { LogHelper.WriteLog("UploadTranLoadFile", ex); return(Json(new RequestResult(false, ex.Message))); } }