protected void btnUpload_Click(object sender, EventArgs e) { //string filePath = ""; if (ImportSB.HasFile && ImportSB.FileName.Contains(".xls")) { //UploadedFile file = layoutUpload.UploadedFiles[0]; if (File.Exists(Server.MapPath("~/Southbound/" + txtPO.Text + ".xls"))) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true); } else { ImportSB.SaveAs(Server.MapPath("~/Southbound/" + txtPO.Text + ".xls")); context.cqf_logActividad.Add(new cqf_logActividad { fdt_fecha = DateTime.Now, fi_idUsuario = int.Parse(Session["UserID"].ToString()), fs_actividad = "Upload Production Order File" }); context.SaveChanges(); } } List <SouthBound> SBs = new List <SouthBound>(); using (var stream = File.Open(Server.MapPath("~/Southbound/" + txtPO.Text + ".xls"), FileMode.Open, FileAccess.Read)) { using (var reader = ExcelDataReader.ExcelReaderFactory.CreateReader(stream)) { while (reader.Read()) { if (reader.Depth >= 1) { //reader.NextResult(); try { string[] date = txtDate.Text.Split('-'); string[] ShipDate = txtShipDate.Text.Split('-'); SouthBound s = new SouthBound(); s.fc_status = "A"; s.fs_invoice = txtInvoice.Text; s.fs_trucker = txtTrucker.Text; s.fd_date = new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2])); s.fs_tracking = txtTracking.Text; s.fs_productionOrder = txtPO.Text; s.fs_reference = txtReference.Text; s.fi_exportRecords = int.Parse(ddlsexport.SelectedItem.Value); s.fs_exportRecords = ddlsexport.SelectedItem.Text; s.fi_importRecords = int.Parse(ddlsimport.SelectedItem.Value); s.fs_importRecords = ddlsimport.SelectedItem.Text; s.fi_shipper = int.Parse(ddlsShippers.SelectedItem.Value); s.fs_shipper = ddlsShippers.SelectedItem.Text; s.fi_shipTo = int.Parse(ddlsShipTo.SelectedItem.Value); s.fs_shipTo = ddlsShipTo.SelectedItem.Text; s.fs_moneda = ddlsCurrency.SelectedItem.Text; s.fs_incoterms = ddlsIncoterms.SelectedItem.Text; s.fd_shipDate = new DateTime(int.Parse(ShipDate[0]), int.Parse(ShipDate[1]), int.Parse(ShipDate[2])); s.fs_partNumber = reader.GetString(1); s.fs_description = reader.GetString(1); s.fs_scheduleHsCode = reader.GetString(2); s.fs_coo = reader.GetString(3); s.fi_qty = int.Parse(reader.GetDouble(4).ToString()); s.fd_totalWeightLbs = reader.GetDouble(5); s.fd_totalWeightKgs = reader.GetDouble(6); s.fd_unitPrice = decimal.Parse(reader.GetDouble(7).ToString()); s.fd_exitPrice = decimal.Parse(reader.GetDouble(8).ToString()); if (s.fs_partNumber == null) { reader.NextResult(); } else { SBs.Add(s); } } catch (Exception ex) { Console.Write(ex.Message); } } } rgProductionOrder.DataSource = SBs.ToList(); rgProductionOrder.DataBind(); } } }
protected void btnUpload_Click(object sender, EventArgs e) { if (txtWorkOrder.Text != "") { if (ImportSB.HasFile && ImportSB.FileName.Contains(".xls")) { //UploadedFile file = layoutUpload.UploadedFiles[0]; if (File.Exists(Server.MapPath("~/WorkOrders/" + txtWorkOrder.Text + ".xls"))) { ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true); } else { ImportSB.SaveAs(Server.MapPath("~/WorkOrders/" + txtWorkOrder.Text + ".xls")); context.cqf_logActividad.Add(new cqf_logActividad { fdt_fecha = DateTime.Now, fi_idUsuario = int.Parse(Session["UserID"].ToString()), fs_actividad = "Upload Work Order File" }); context.SaveChanges(); } } List <cqf_workOrder> SBs = new List <cqf_workOrder>(); using (var stream = File.Open(Server.MapPath("~/WorkOrders/" + txtWorkOrder.Text + ".xls"), FileMode.Open, FileAccess.Read)) { using (var reader = ExcelDataReader.ExcelReaderFactory.CreateReader(stream)) { while (reader.Read()) { if (reader.Depth >= 1) { //reader.NextResult(); try { string[] ShipDate = txtWorkOrderDate.Text.Split('-'); cqf_workOrder s = new cqf_workOrder(); s.fc_status = "A"; s.fs_workOrder = txtWorkOrder.Text; try{ s.fs_sku = reader.GetDouble(0).ToString(); } catch { s.fs_sku = reader.GetString(0).ToString(); } try { s.fs_paintCode = reader.GetDouble(1).ToString(); } catch { s.fs_paintCode = reader.GetString(1).ToString(); } s.fs_engraving = reader.GetString(2); s.fdt_date = new DateTime(int.Parse(ShipDate[0]), int.Parse(ShipDate[1]), int.Parse(ShipDate[2])); s.fi_qty = int.Parse(reader.GetDouble(3).ToString()); if (s.fs_sku == null) { reader.NextResult(); } else { SBs.Add(s); } } catch (Exception ex) { Console.Write(ex.Message); } } } rgWorkOrder.DataSource = SBs.ToList(); rgWorkOrder.DataBind(); } } } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal2();", true); } }
protected void btnUpload_Click(object sender, EventArgs e) { string filePath = ""; string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Session["UserID"].ToString() + ".xls"; if (ImportSB.HasFile) { if (File.Exists(Server.MapPath("~/NorthBound/" + filename))) { // File.Delete(Server.MapPath("~/NorthBound/" + ImportSB.FileName)); } else { ImportSB.SaveAs(Server.MapPath("~/NorthBound/" + filename)); filePath = Server.MapPath("~/NorthBound/" + filename); context.cqf_logActividad.Add(new cqf_logActividad { fdt_fecha = DateTime.Now, fi_idUsuario = int.Parse(Session["UserID"].ToString()), fs_actividad = "Upload North Bound File" }); context.SaveChanges(); lblFilename.Text = filename; List <NorthBound> SBs = new List <NorthBound>(); using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read)) { using (var reader = ExcelReaderFactory.CreateReader(stream)) { while (reader.Read()) { if (reader.Depth >= 1) { //reader.NextResult(); try { NorthBound s = new NorthBound(); s.fc_status = "A"; s.fdt_invoiceDate = reader.GetDateTime(0); s.fs_invoiceNumber = reader.GetString(1); try { s.fs_trailerNumber = reader.GetString(2); } catch { s.fs_trailerNumber = reader.GetDouble(2).ToString(); } s.fs_sealNumber = reader.GetString(3); s.fi_exportOfRecord = 1; s.fs_exportOfRecord = "Maquila Solutions Mexico SA de CV"; s.fi_importer = 1; s.fs_importer = "YETI Coolers, LLC"; s.fi_shipper = 1; s.fs_shipper = "Maquila Solutions c/o Scanpaint SA de CV"; s.fi_shipTo = 1; s.fs_shipTo = reader.GetString(7); s.fs_incoterm = "EXW"; s.fdt_shipDate = reader.GetDateTime(9); s.fs_shipVia = reader.GetString(10); try { s.fs_SKU = reader.GetString(11); } catch { s.fs_SKU = reader.GetDouble(11).ToString(); } s.fs_descYeti = reader.GetString(12); s.fs_hsCodeYeti = reader.GetString(13); s.fs_COOYeti = "CN"; s.fi_qtyYeti = int.Parse(reader.GetDouble(15).ToString()); s.fd_unitPriceYeti = decimal.Parse(reader.GetDouble(16).ToString()); s.fd_extPriceYeti = decimal.Parse(reader.GetDouble(17).ToString()); s.fs_descSP = reader.GetString(18); s.fs_hsCodeSP = reader.GetString(19); s.fs_COOSP = "CN"; s.fd_unitPriceSP = decimal.Parse(reader.GetDouble(21).ToString()); try { s.fs_WONumber = reader.GetString(22); } catch { s.fs_WONumber = reader.GetDouble(22).ToString(); } try { s.fs_upsTracking = reader.GetString(23); } catch { s.fs_upsTracking = reader.GetDouble(23).ToString(); } s.fd_extPriceSP = decimal.Parse(reader.GetDouble(24).ToString()); s.fd_totalEnteredValue = decimal.Parse(reader.GetDouble(25).ToString()); s.fd_totalWeight = reader.GetDouble(26); s.fd_totalAmount = decimal.Parse(reader.GetDouble(27).ToString()); if (s.fs_descSP == null) { reader.NextResult(); } else { SBs.Add(s); } } catch (Exception ex) { Console.Write(ex.Message); } } } } } uploadinformation.Visible = true; ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalMensajes();", true); rgNorthBound.DataSource = SBs.ToList(); rgNorthBound.DataBind(); } } }