public ActionResult Trade(string shippingId) { int cnvrtShippingID = Convert.ToInt32(shippingId); ViewBag.Message = "Your Trade page."; Trading.BLL.Trade trade = new BLL.Trade(); trade.TradeDBConnectionString = ConfigurationManager.ConnectionStrings["TradeConnectionString"].ConnectionString; UploadTradeVM uploadTrade = trade.GetShippingTradeDetails(cnvrtShippingID); uploadTrade = ReEvaluateUploadTrade(uploadTrade); return(View(uploadTrade)); }
public UploadTradeVM ReEvaluateUploadTrade(UploadTradeVM uploadTrade) { List <DocumentInstructionVM> lstDocumentInstructions = new List <DocumentInstructionVM>(); List <ShippingModelVM> lstShippingModels = new List <ShippingModelVM>(); DocumentInstructionVM documentInstructionVM; ShippingModelVM shippingModelVM; var documentList = uploadTrade.DocumentInstructions.Select(x => x.Instruction.Split(new string[] { "AND" }, StringSplitOptions.RemoveEmptyEntries)).ToList(); foreach (var it in documentList) { documentInstructionVM = new DocumentInstructionVM(); documentInstructionVM.Instruction = Regex.Replace(it[0], "[^A-Za-z ]", ""); //string clean = Regex.Replace(it[0], "[^A-Za-z ]", ""); ; var resultString = Regex.Match(it[1], @"\d+").Value; if (resultString != "") { documentInstructionVM.Copies = Int32.Parse(resultString); } else { documentInstructionVM.Copies = 0; } lstDocumentInstructions.Add(documentInstructionVM); } uploadTrade.DocumentInstructions.Clear(); uploadTrade.DocumentInstructions = lstDocumentInstructions; foreach (var it in uploadTrade.ShippingModels) { shippingModelVM = new ShippingModelVM(); shippingModelVM.BLModelName = it.BLModelName; shippingModelVM.Description = it.Description; shippingModelVM.LineNo = it.PONo.Substring(18, 4); shippingModelVM.PONo = it.PONo.Substring(10, 7); shippingModelVM.ModelName = it.ModelName; shippingModelVM.Quantity = it.Quantity; //shippingModelVM.SCNo = it.Remarks.Substring(10, 5); if (it.Remarks.Length > 0) { shippingModelVM.SCNo = it.Remarks.Substring(it.Remarks.Length - 8).Remove(7); } else { shippingModelVM.SCNo = it.Remarks; } shippingModelVM.Version = it.Version; lstShippingModels.Add(shippingModelVM); } uploadTrade.ShippingModels.Clear(); uploadTrade.ShippingModels = lstShippingModels; return(uploadTrade); }
public ActionResult Trade(UploadTrade uploadTrade, HttpPostedFileBase postedFile, string submitButton) { UploadTradeVM uploadTradeVM = new UploadTradeVM(); try { switch (submitButton) { case "Search": ModelState.Clear(); Trading.BLL.Trade trade = new BLL.Trade(); trade.TradeDBConnectionString = ConfigurationManager.ConnectionStrings["TradeConnectionString"].ConnectionString; uploadTradeVM = trade.GetShippingTradeDetails(uploadTrade.ShippingId); uploadTradeVM = ReEvaluateUploadTrade(uploadTradeVM); if (uploadTrade.Shipping.SINo == null || uploadTrade.Shipping.SINo == string.Empty) { uploadTrade.IsSINoAvailable = false; } break; case "Upload": if (postedFile != null) { string path = Server.MapPath("~/TradeShippingSheets/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } postedFile.SaveAs(path + Path.GetFileName(postedFile.FileName)); uploadTradeVM = new UploadTradeVM() { Shipping = new ViewModel.Shipping(), DocumentInstructions = new List <DocumentInstructionVM>(), ShippingModels = new List <ShippingModelVM>() }; ProcessInputFile((path + Path.GetFileName(postedFile.FileName))); } break; } return(View(uploadTradeVM)); } catch (Exception ex) { throw ex; } }
public ActionResult SIList(HttpPostedFileBase postedFile) { UploadTradeVM uploadTradeVM = new UploadTradeVM(); List <ViewModel.Shipping> shippingModel = new List <ViewModel.Shipping>(); try { if (postedFile != null) { string path = Server.MapPath("~/TradeShippingSheets/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } postedFile.SaveAs(path + Path.GetFileName(postedFile.FileName)); uploadTradeVM = new UploadTradeVM() { Shipping = new ViewModel.Shipping(), DocumentInstructions = new List <DocumentInstructionVM>(), ShippingModels = new List <ShippingModelVM>() }; ProcessInputFile((path + Path.GetFileName(postedFile.FileName))); shippingModel = GetDetailsFromShipping(); ViewBag.Exception = "File uploaded successfully"; } return(View(shippingModel)); } catch (Exception ex) { ViewBag.Exception = ex.Message; shippingModel = GetDetailsFromShipping(); return(View(shippingModel)); } }
public UploadTradeVM GetShippingTradeDetails(int shippingId) { UploadTradeVM uploadedTrade = new UploadTradeVM(); SqlParameter parameter; try { using (SqlConnection connection = new SqlConnection(TradeDBConnectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand("GetShippingTradeDetails", connection); cmd.CommandType = CommandType.StoredProcedure; parameter = new SqlParameter(); parameter.ParameterName = "@SINo"; parameter.SqlDbType = SqlDbType.Int; parameter.Value = shippingId; cmd.Parameters.Add(parameter); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataSet tradeAndShippingDetails = new DataSet(); adapter.Fill(tradeAndShippingDetails, "Trade"); uploadedTrade = new UploadTradeVM() { Shipping = new ViewModel.Shipping(), DocumentInstructions = new List <DocumentInstructionVM>(), ShippingModels = new List <ShippingModelVM>() }; uploadedTrade.ShippingId = shippingId; if (tradeAndShippingDetails.Tables[0].Rows.Count > 0) { uploadedTrade.Shipping = (from DataRow dr in tradeAndShippingDetails.Tables[0].Rows select new ViewModel.Shipping { TradeSheetName = dr["TradeSheetName"]?.ToString(), BLConsignee = dr["BLConsignee"]?.ToString(), FinalDestination = dr["FinalDestination"]?.ToString(), Freight = dr["Freight"]?.ToString(), LCExpiryDate = dr["LCExpiryDate"]?.ToString(), LCIssuanceDate = dr["LCIssuanceDate"]?.ToString(), LCIssuingBank = dr["LCIssuingBank"]?.ToString(), LCNo = dr["LCNo"]?.ToString(), PartialShipment = dr["PartialShipment"]?.ToString(), PaymentTerms = dr["PaymentTerms"]?.ToString(), PortOfDischarge = dr["PortOfDischarge"]?.ToString(), PortOfLoading = dr["PortOfLoading"]?.ToString(), RequiredBLDate = dr["RequiredBLDate"]?.ToString(), ShipmentExpiryDate = dr["ShipmentExpiryDate"]?.ToString(), ShipToParty = dr["ShipToParty"]?.ToString(), SIDate = dr["SIDate"]?.ToString(), SINo = dr["SINo"]?.ToString(), SoldToParty = dr["SoldToParty"]?.ToString(), TradeTerms = dr["TradeTerms"]?.ToString(), Transportation = dr["Transportation"]?.ToString(), TransShipment = dr["TransShipment"]?.ToString(), Vender = dr["Vender"]?.ToString(), Via = dr["Via"]?.ToString() }).FirstOrDefault(); } if (tradeAndShippingDetails.Tables[1].Rows.Count > 0) { uploadedTrade.DocumentInstructions = (from DataRow dr in tradeAndShippingDetails.Tables[1].Rows select new DocumentInstructionVM { Instruction = dr["Instruction"]?.ToString() }).ToList(); } if (tradeAndShippingDetails.Tables[2].Rows.Count > 0) { uploadedTrade.ShippingModels = (from DataRow dr in tradeAndShippingDetails.Tables[2].Rows select new ShippingModelVM { PONo = dr["PONo"]?.ToString(), BLModelName = dr["BLModelName"]?.ToString(), Description = dr["Description"]?.ToString(), ModelName = dr["ModelName"]?.ToString(), Quantity = dr["Quantity"]?.ToString(), Remarks = dr["Remarks"]?.ToString(), Version = dr["Version"]?.ToString() }).ToList(); } connection.Close(); } } catch (Exception ex) { _tradeLogger.Error("Trading.DAL.Trade.LoadSheet", ex); throw ex; } return(uploadedTrade); }