public ActionResult UploadSales(string BillType, string InterState, string UploadType, HttpPostedFileBase FileUpload) { ExcelUploaders uploader = new ExcelUploaders(); bool IsVat = false; bool IsLocal = true; if (BillType == "VAT") { IsVat = true; } if (InterState == "InterState") { IsLocal = false; } UploadTypes uType = UploadTypes.SaleItemWise; if (UploadType == "Register") { uType = UploadTypes.SaleRegister; } UploadReturns response = uploader.UploadExcel(uType, FileUpload, Server.MapPath("~/Doc/"), IsVat, IsLocal); ViewBag.Status = response.ToString(); if (response == UploadReturns.Success) { return(RedirectToAction("SaleList")); } return(View()); }
public IActionResult UploadSales(string BillType, string InterState, string UploadType, string StoreCode, IFormFile FileUpload) { ExcelUploaders uploader = new ExcelUploaders(); bool IsVat = false; bool IsLocal = true; if (BillType == "VAT") { IsVat = true; } if (InterState == "InterState") { IsLocal = false; } UploadTypes uType = UploadTypes.SaleItemWise; if (UploadType == "Register") { uType = UploadTypes.SaleRegister; } UploadReturns response = uploader.UploadExcel(db, uType, FileUpload, StoreCode, IsVat, IsLocal); ViewBag.Status = response.ToString(); if (response == UploadReturns.Success) { return(RedirectToAction("SaleList")); } return(View()); }
public static IList <PdbUploadRevision> GetUploadRevisions(UploadTypes type) { var crit = new DaoCriteria(); crit.Expressions.Add(new EqualExpression("Type", type.ToString())); crit.Orders.Add(new SortOrder("Date", SortType.Desc)); crit.Limit = MaxRevisionsReturned; var revisions = _urDao.Get(crit); return(revisions); }
public static void AddUploadRevision(UploadTypes type, String data, User u) { var ur = new PdbUploadRevision { Type = type.ToString(), Data = data, Date = DateTime.Now, UserId = u.Id }; _urDao.Insert(ur); }
public static ILoadable GetLoader(UploadTypes type) { ILoadable loader; switch (type) { case UploadTypes.Project: loader = new ProjectUploader(); break; case UploadTypes.Attribute: loader = new AttributeUploader(); break; case UploadTypes.Reac: loader = new ReacUploader(); break; case UploadTypes.Parcel: loader = new ParcelUploader(); break; case UploadTypes.RealPropertyEvent: loader = new PropertyEventUploader(); break; case UploadTypes.Subsidy: loader = new SubsidyUploader(); break; case UploadTypes.Comment: loader = new CommentExporter(); break; default: throw new ApplicationException(String.Format("{0} is not a valid upload type.", type)); } return(loader); }
private DataTable ProcessData(DataSet dataSet, UploadTypes updateType) { DataTable dtBulkUpload = dataSet.Tables[0]; #region Check Data Validity and Call Service dtBulkUpload.Columns.Add("Status"); dtBulkUpload.Columns.Add("Message"); DataTable dtDestination = dtBulkUpload.Copy(); dtDestination.Rows.Clear(); List<BulkUpload> registerDevices = new List<BulkUpload>(); for (int cnt = 0; cnt < dtBulkUpload.Rows.Count; cnt++) { DataRow row = dtBulkUpload.Rows[cnt]; registerDevices.Add(new BulkUpload(updateType, row)); } foreach (BulkUpload reg in registerDevices) { if (reg.CurrentClass.Count == 0) { reg.CurrentClass.InsertObject(); } dtDestination.ImportRow(reg.CurrentClass.Row); } #endregion return dtDestination; }
public async Task <JSON_UploadLocalFile> UploadLocal(object FileToUpload, UploadTypes UploadType, string VideoTitle = null, List <string> VideoTags = null, ChannelsEnum?VideoChannel = null, PrivacyEnum?Privacy = null, IProgress <ReportStatus> ReportCls = null, CancellationToken token = default) { var uploadUrl = await GetUploadUrl(); ReportCls = ReportCls ?? new Progress <ReportStatus>(); ReportCls.Report(new ReportStatus() { Finished = false, TextStatus = "Initializing..." }); try { System.Net.Http.Handlers.ProgressMessageHandler progressHandler = new System.Net.Http.Handlers.ProgressMessageHandler(new HCHandler()); progressHandler.HttpSendProgress += (sender, e) => { ReportCls.Report(new ReportStatus() { ProgressPercentage = e.ProgressPercentage, BytesTransferred = e.BytesTransferred, TotalBytes = e.TotalBytes ?? 0, TextStatus = "Uploading..." }); }; using (HttpClient localHttpClient = new HtpClient(progressHandler)) { HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(uploadUrl.upload_url)); var MultipartsformData = new MultipartFormDataContent(); HttpContent streamContent = null; switch (UploadType) { case UploadTypes.FilePath: streamContent = new StreamContent(new System.IO.FileStream(FileToUpload.ToString(), System.IO.FileMode.Open, System.IO.FileAccess.Read)); break; case UploadTypes.Stream: streamContent = new StreamContent((System.IO.Stream)FileToUpload); break; case UploadTypes.BytesArry: streamContent = new StreamContent(new System.IO.MemoryStream((byte[])FileToUpload)); break; } MultipartsformData.Add(streamContent, "file"); HtpReqMessage.Content = MultipartsformData; // ''''''''''''''''will write the whole content to H.D WHEN download completed''''''''''''''''''''''''''''' using (HttpResponseMessage ResPonse = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false)) { string result = await ResPonse.Content.ReadAsStringAsync(); token.ThrowIfCancellationRequested(); var TheRsult = JsonConvert.DeserializeObject <JSON_UploadLocalFile>(result); if (ResPonse.StatusCode == System.Net.HttpStatusCode.OK) { ReportCls.Report(new ReportStatus() { Finished = true, TextStatus = string.Format("[{0}] Uploaded successfully", VideoTitle) }); // ''''''''Complete file upload'''''''''''' using (HtpClient localHttpClient2 = new HtpClient(new HCHandler())) { using (HttpRequestMessage HtpReqMessage2 = new HttpRequestMessage(HttpMethod.Post, new pUri("/me/videos"))) { var parameters = new Dictionary <string, string>(); parameters.Add("url", TheRsult.url); parameters.Add("title", VideoTitle); parameters.Add("tags", VideoTags != null ? string.Join(",", VideoTags) : null); parameters.Add("channel", VideoChannel.HasValue ? VideoChannel.ToString() : null); if (Privacy.HasValue) { switch (Privacy) { case PrivacyEnum.Public: parameters.Add("published", "1"); parameters.Add("private", "0"); break; case PrivacyEnum.Private: parameters.Add("published", "0"); parameters.Add("private", "1"); break; } } HtpReqMessage2.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues()); using (HttpResponseMessage ResPonse2 = await localHttpClient2.SendAsync(HtpReqMessage2, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false)) { string resu = await ResPonse2.Content.ReadAsStringAsync(); if (ResPonse2.StatusCode == System.Net.HttpStatusCode.OK) { var TheRlt = JsonConvert.DeserializeObject <JSON_CompleteUpload>(resu, JSONhandler); TheRsult.id = TheRlt.id; return(TheRsult); } else { throw new DailymotionException(JObject.Parse(resu).SelectToken("error.message").ToString(), (int)ResPonse2.StatusCode); } } } } } else { ReportCls.Report(new ReportStatus() { Finished = true, TextStatus = string.Format("The request returned with HTTP status code {0}", ResPonse.StatusCode) }); throw ShowError(result); } } } } catch (Exception ex) { ReportCls.Report(new ReportStatus() { Finished = true }); if (ex.Message.ToString().ToLower().Contains("a task was canceled")) { ReportCls.Report(new ReportStatus() { TextStatus = ex.Message }); } else { throw new DailymotionException(ex.Message, 1001); } return(null); } }
public async Task <JSON_FileMetadata> Upload(object FileToUpload, UploadTypes UploadType, string DestinationBucketID, string FileName, string SHA1, IProgress <ReportStatus> ReportCls = null, CancellationToken token = default) { ReportCls = ReportCls ?? new Progress <ReportStatus>(); var uploadUrl = await GETUploadUrl(DestinationBucketID); ReportCls.Report(new ReportStatus() { Finished = false, TextStatus = "Initializing..." }); try { System.Net.Http.Handlers.ProgressMessageHandler progressHandler = new System.Net.Http.Handlers.ProgressMessageHandler(new HCHandler()); progressHandler.HttpSendProgress += (sender, e) => { ReportCls.Report(new ReportStatus() { ProgressPercentage = e.ProgressPercentage, BytesTransferred = e.BytesTransferred, TotalBytes = e.TotalBytes ?? 0, TextStatus = "Uploading..." }); }; using (HtpClient localHttpClient = new HtpClient(progressHandler)) { var HtpReqMessage = new HtpRequestMessage(HttpMethod.Post, new Uri(uploadUrl.uploadUrl)); HttpContent streamContent = null;; switch (UploadType) { case UploadTypes.FilePath: streamContent = new StreamContent(new System.IO.FileStream(FileToUpload.ToString(), System.IO.FileMode.Open, System.IO.FileAccess.Read)); break; case UploadTypes.Stream: streamContent = new StreamContent((System.IO.Stream)FileToUpload); break; case UploadTypes.BytesArry: streamContent = new StreamContent(new System.IO.MemoryStream((byte[])FileToUpload)); break; } streamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"); // #If NET452 Then // streamContent.Headers.ContentType = New Net.Http.Headers.MediaTypeHeaderValue(system.Web.MimeMapping.GetMimeMapping(FileName)) // #End If HtpReqMessage.Content = streamContent; HtpReqMessage.Headers.TryAddWithoutValidation("Authorization", uploadUrl.authorizationToken); HtpReqMessage.Headers.TryAddWithoutValidation("X-Bz-File-Name", WebUtility.UrlEncode(FileName)); HtpReqMessage.Headers.TryAddWithoutValidation("Content-Length", "2000"); HtpReqMessage.Headers.TryAddWithoutValidation("X-Bz-Content-Sha1", SHA1); // ''''''''''''''''will write the whole content to H.D WHEN download completed''''''''''''''''''''''''''''' using (HttpResponseMessage ResPonse = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead, token).ConfigureAwait(false)) { string result = await ResPonse.Content.ReadAsStringAsync(); token.ThrowIfCancellationRequested(); if (ResPonse.StatusCode == HttpStatusCode.OK) { var userInfo = JsonConvert.DeserializeObject <JSON_FileMetadata>(result); ReportCls.Report(new ReportStatus() { Finished = true, TextStatus = $"[{FileName}] Uploaded successfully" }); return(userInfo); } else { var errorInfo = JsonConvert.DeserializeObject <JSON_Error>(result); ReportCls.Report(new ReportStatus() { Finished = true, TextStatus = $"The request returned with HTTP status code {errorInfo._ErrorMessage ?? errorInfo.code}" }); return(null); } } } } catch (Exception ex) { ReportCls.Report(new ReportStatus() { Finished = true }); if (ex.Message.ToString().ToLower().Contains("a task was canceled")) { ReportCls.Report(new ReportStatus() { TextStatus = ex.Message }); } else { throw new BackBlazeException(ex.Message, 1001); } return(null); } }
public BulkUpload(UploadTypes uploadType, DataRow row) { this.Row = row; this.UploadType = uploadType; this.SetClass(); }
public UploadReturns UploadExcel(UploadTypes UploadType, HttpPostedFileBase FileUpload, string targetpath, bool IsVat, bool IsLocal) { using (VoyagerContext db = new VoyagerContext()) { //UploadType = "InWard"; List <string> data = new List <string>(); if (FileUpload != null) { // tdata.ExecuteCommand("truncate table OtherCompanyAssets"); if (FileUpload.ContentType == "application/vnd.ms-excel" || FileUpload.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { string filename = FileUpload.FileName; //TODO: pass from calling function of http post // string targetpath = Server.MapPath("~/Doc/"); FileUpload.SaveAs(targetpath + filename); string pathToExcelFile = targetpath + filename; var connectionString = ""; if (filename.EndsWith(".xls")) { connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", pathToExcelFile); } else if (filename.EndsWith(".xlsx")) { connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", pathToExcelFile); } var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString); var ds = new DataSet(); adapter.Fill(ds, "ExcelTable"); DataTable dtable = ds.Tables["ExcelTable"]; string sheetName = "Sheet1"; var excelFile = new ExcelQueryFactory(pathToExcelFile); if (UploadType == UploadTypes.Purchase) { var currentImports = from a in excelFile.Worksheet <ImportPurchase>(sheetName) select a; foreach (var a in currentImports) { try { a.ImportTime = DateTime.Now; //Vat & Local a.IsLocal = IsLocal; a.IsVatBill = IsVat; db.ImportPurchases.Add(a); db.SaveChanges(); } catch (DbEntityValidationException) { //TODO: need to handel this return(UploadReturns.Error); } } } else if (UploadType == UploadTypes.SaleItemWise) { var currentImports = from a in excelFile.Worksheet <ImportSaleItemWiseVM>(sheetName) select a; foreach (var a in currentImports) { try { a.ImportTime = DateTime.Now; a.IsDataConsumed = false; db.ImportSaleItemWises.Add(ImportSaleItemWiseVM.ToTable(a)); db.SaveChanges(); } catch (DbEntityValidationException) { //TODO: need to handel this return(UploadReturns.Error); } } } else if (UploadType == UploadTypes.SaleRegister) { var currentImports = from a in excelFile.Worksheet <ImportSaleRegister>(sheetName) select a; foreach (var a in currentImports) { try { a.ImportTime = DateTime.Now; a.IsConsumed = false; db.ImportSaleRegisters.Add(a); db.SaveChanges(); } catch (DbEntityValidationException) { //TODO: need to handel this return(UploadReturns.Error); } } } else if (UploadType == UploadTypes.InWard) { var currentImports = from a in excelFile.Worksheet <ImportInWard>(sheetName) select a; foreach (var a in currentImports) { try { // Inward No Inward Date Invoice No Invoice Date Party Name Total Qty Total MRP Value Total Cost ImportInWard inw = new ImportInWard { ImportDate = DateTime.Today, InvoiceDate = a.InvoiceDate, InvoiceNo = a.InvoiceNo, InWardDate = a.InWardDate, InWardNo = a.InWardNo, PartyName = a.PartyName, TotalCost = a.TotalCost, TotalMRPValue = a.TotalMRPValue, TotalQty = a.TotalQty }; db.ImportInWards.Add(inw); db.SaveChanges(); } catch (DbEntityValidationException) { //TODO: need to handel this return(UploadReturns.Error); } } } else { return(UploadReturns.ImportNotSupported); } //deleting excel file from folder if ((System.IO.File.Exists(pathToExcelFile))) { System.IO.File.Delete(pathToExcelFile); } return(UploadReturns.Success); }//end of if contexttype else { return(UploadReturns.NotExcelType); } }//end of if fileupload else { return(UploadReturns.FileNotFound); } } }//end of function
public async Task <JSON_Upload> Upload(object FileToUpload, UploadTypes UploadType, string DestinationFolderID, string FileName, IProgress <ReportStatus> ReportCls = null, CancellationToken token = default) { var uploadUrl = await GetUploadUrl(DestinationFolderID); ReportCls = ReportCls ?? new Progress <ReportStatus>(); ReportCls.Report(new ReportStatus() { Finished = false, TextStatus = "Initializing..." }); try { System.Net.Http.Handlers.ProgressMessageHandler progressHandler = new System.Net.Http.Handlers.ProgressMessageHandler(new HCHandler()); progressHandler.HttpSendProgress += (sender, e) => { ReportCls.Report(new ReportStatus() { ProgressPercentage = e.ProgressPercentage, BytesTransferred = e.BytesTransferred, TotalBytes = e.TotalBytes ?? 0, TextStatus = "Uploading..." }); }; HttpClient localHttpClient = new HtpClient(progressHandler); HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(uploadUrl.form_action)); MultipartFormDataContent MultipartsformData = new MultipartFormDataContent(); HttpContent streamContent = null; switch (UploadType) { case UploadTypes.FilePath: streamContent = new StreamContent(new FileStream(FileToUpload.ToString(), FileMode.Open, FileAccess.Read)); break; case UploadTypes.Stream: streamContent = new StreamContent((Stream)FileToUpload); break; case UploadTypes.BytesArry: streamContent = new StreamContent(new MemoryStream((byte[])FileToUpload)); break; } streamContent.Headers.Clear(); streamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data") { Name = "file", FileName = FileName }; streamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"); MultipartsformData.Add(streamContent); // ''''''''''''''''''''''''' MultipartsformData.Add(new StringContent(uploadUrl.form_data.ajax.ToString()), "ajax"); MultipartsformData.Add(new StringContent(uploadUrl.form_data.@params), "params"); MultipartsformData.Add(new StringContent(uploadUrl.form_data.signature), "signature"); HtpReqMessage.Content = MultipartsformData; // ''''''''''''''''will write the whole content to H.D WHEN download completed''''''''''''''''''''''''''''' using (HttpResponseMessage ResPonse = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false)) { string result = await ResPonse.Content.ReadAsStringAsync(); token.ThrowIfCancellationRequested(); ResPonse.EnsureSuccessStatusCode(); if (JObject.Parse(result).SelectToken("status").ToString() == "success") { ReportCls.Report(new ReportStatus() { Finished = true, TextStatus = $"[{FileName}] Uploaded successfully" }); var userInfo = JsonConvert.DeserializeObject <JSON_Upload>(result, JSONhandler); return(userInfo); } else { var errorInfo = JsonConvert.DeserializeObject <JSON_Error>(result, JSONhandler); ReportCls.Report(new ReportStatus() { Finished = true, TextStatus = $"The request returned with HTTP status code {errorInfo.ErrorMessage}" }); return(null); } } } catch (Exception ex) { ReportCls.Report(new ReportStatus() { Finished = true }); if (ex.Message.ToString().ToLower().Contains("a task was canceled")) { ReportCls.Report(new ReportStatus() { TextStatus = ex.Message }); } else { throw new keep2shareException(ex.Message, 1001); } return(null); } }
public static string UploadFile(HttpPostedFile postedFile, string path, UploadTypes uploadType) { string strFileName; if (postedFile != null && postedFile.ContentLength > 0 && postedFile.FileName.ToLower() != "none") { int nFileLen = postedFile.ContentLength; strFileName = Path.GetFileName(postedFile.FileName); string strExtention = Path.GetExtension(postedFile.FileName).ToLower(); switch (strExtention.ToUpper()) { //check the extension, must be an accepted file format case ".PDF": case ".TXT": case ".DOC": case ".DOCX": case ".XLS": case ".XLSX": case ".PPT": case ".PPS": case ".PPSX": case ".VST": case ".VSD": case ".VDX": if (uploadType != UploadTypes.Document && uploadType != UploadTypes.Attachment) strFileName = ""; break; //or an accepted image format case ".GIF": case ".JPG": case "JPEG": case ".PNG": if (uploadType != UploadTypes.Image && uploadType != UploadTypes.Attachment) strFileName = ""; break; //video case ".MOV": if (uploadType != UploadTypes.Video) strFileName = ""; break; // everything else is an unacceptable file type default: strFileName = ""; break; } if (strFileName.Trim().Length > 0) { // Read file into a data stream byte[] data = new Byte[nFileLen]; postedFile.InputStream.Read(data, 0, nFileLen); // Make sure a duplicate file doesnt exist. If it does, append incremental numbers string tmpFileName = Path.GetFileNameWithoutExtension(postedFile.FileName); int tmpCount = 0; while (File.Exists(path + strFileName)) { tmpCount++; strFileName = tmpFileName + "_" + tmpCount + strExtention; } postedFile.SaveAs(path + strFileName); } } else { strFileName = ""; } if (strFileName == "") return null; else return strFileName; }
public UploadReturns UploadExcel(VoyagerContext db, UploadTypes UploadType, IFormFile FileUpload, string StoreCode, bool IsVat, bool IsLocal) { //UploadType = "InWard"; //List<string> data = new List<string> (); if (FileUpload != null) { // tdata.ExecuteCommand("truncate table OtherCompanyAssets"); if (FileUpload.ContentType == "application/vnd.ms-excel" || FileUpload.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { string filename = FileUpload.FileName; string pathToExcelFile = Path.GetTempPath() + filename; using (var stream = new FileStream(pathToExcelFile, FileMode.Create)) { FileUpload.CopyTo(stream); } if (UploadType == UploadTypes.Purchase) { try { ImportPurchase(db, pathToExcelFile, StoreCode, IsVat, IsLocal); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(UploadReturns.Error); } } else if (UploadType == UploadTypes.SaleItemWise) { try { ImportSaleItemWise(db, pathToExcelFile, StoreCode, IsVat, IsLocal); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(UploadReturns.Error); } } else if (UploadType == UploadTypes.SaleRegister) { try { ImportSaleRegister(db, StoreCode, pathToExcelFile); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(UploadReturns.Error); } } else if (UploadType == UploadTypes.InWard) { try { ImportPurchaseInward(db, StoreCode, pathToExcelFile); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(UploadReturns.Error); } } else { return(UploadReturns.ImportNotSupported); } if ((System.IO.File.Exists(pathToExcelFile))) { System.IO.File.Delete(pathToExcelFile); } return(UploadReturns.Success); }//end of if context type else { return(UploadReturns.NotExcelType); } }//end of if file upload else { return(UploadReturns.FileNotFound); } }//end of function
public async Task <JSON_Upload> Upload(object FileToUpload, UploadTypes UploadType, string FileName, IProgress <ReportStatus> ReportCls = null, CancellationToken token = default) { var clint = new SClient(AccessToken, ConnectionSetting); return(await clint.Folder(string.Empty).Upload(FileToUpload, UploadType, FileName, ReportCls, token)); }
public JsonResult UploadExcel(/*string UploadType,*/ UploadTypes UploadType, HttpPostedFileBase FileUpload) { //UploadType = "InWard"; List<string> data = new List<string>(); if (FileUpload != null) { // tdata.ExecuteCommand("truncate table OtherCompanyAssets"); if (FileUpload.ContentType == "application/vnd.ms-excel" || FileUpload.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { string filename = FileUpload.FileName; string targetpath = Server.MapPath("~/Doc/"); FileUpload.SaveAs(targetpath + filename); string pathToExcelFile = targetpath + filename; var connectionString = ""; if (filename.EndsWith(".xls")) { connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", pathToExcelFile); } else if (filename.EndsWith(".xlsx")) { connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", pathToExcelFile); } var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString); var ds = new DataSet(); adapter.Fill(ds, "ExcelTable"); DataTable dtable = ds.Tables["ExcelTable"]; string sheetName = "Sheet1"; var excelFile = new ExcelQueryFactory(pathToExcelFile); //if (OfTypes != null && OfTypes == UploadTypes.SaleItemWise) //{ // //alert message for invalid file format // data.Add("<ul>"); // data.Add("<li>SaleItemWise of UploadType Was Selected</li>"); // data.Add("</ul>"); // data.ToArray(); // return Json(data, JsonRequestBehavior.AllowGet); //} //else if (UploadType == UploadTypes.Purchase) { var currentImports = from a in excelFile.Worksheet<ImportPurchase>(sheetName) select a; foreach (var a in currentImports) { try { a.ImportTime = DateTime.Now; db.ImportPurchases.Add(a); db.SaveChanges(); } catch (DbEntityValidationException) { //TODO: need to handel this throw; } } } else if (UploadType == UploadTypes.SaleItemWise) { var currentImports = from a in excelFile.Worksheet<ImportSaleItemWiseVM>(sheetName) select a; foreach (var a in currentImports) { try { a.ImportTime = DateTime.Now; a.IsDataConsumed = false; db.ImportSaleItemWises.Add(ImportSaleItemWiseVM.ToTable(a)); db.SaveChanges(); } catch (DbEntityValidationException) { //TODO: need to handel this throw; } } } else if (UploadType == UploadTypes.SaleRegister) { var currentImports = from a in excelFile.Worksheet<ImportSaleRegister>(sheetName) select a; foreach (var a in currentImports) { try { a.ImportTime = DateTime.Now; a.IsConsumed = false; db.ImportSaleRegisters.Add(a); db.SaveChanges(); } catch (DbEntityValidationException) { //TODO: need to handel this throw; } } } else if (UploadType == UploadTypes.InWard) { var currentImports = from a in excelFile.Worksheet<ImportInWard>(sheetName) select a; foreach (var a in currentImports) { try { // Inward No Inward Date Invoice No Invoice Date Party Name Total Qty Total MRP Value Total Cost ImportInWard inw = new ImportInWard { ImportDate = DateTime.Today, InvoiceDate = a.InvoiceDate, InvoiceNo = a.InvoiceNo, InWardDate = a.InWardDate, InWardNo = a.InWardNo, PartyName = a.PartyName, TotalCost = a.TotalCost, TotalMRPValue = a.TotalMRPValue, TotalQty = a.TotalQty }; db.ImportInWards.Add(inw); db.SaveChanges(); } catch (DbEntityValidationException) { //TODO: need to handel this throw; } } } else { //alert message for invalid file format data.Add("<ul>"); data.Add("<li>Upload Type select is not supported</li>"); data.Add("</ul>"); data.ToArray(); return Json(data, JsonRequestBehavior.AllowGet); } //deleting excel file from folder if ((System.IO.File.Exists(pathToExcelFile))) { System.IO.File.Delete(pathToExcelFile); } return Json("success", JsonRequestBehavior.AllowGet); }//end of if contexttype else { //alert message for invalid file format data.Add("<ul>"); data.Add("<li>Only Excel file format is allowed</li>"); data.Add("</ul>"); data.ToArray(); return Json(data, JsonRequestBehavior.AllowGet); } }//end of if fileupload else { data.Add("<ul>"); if (FileUpload == null) data.Add("<li>Please choose Excel file</li>"); data.Add("</ul>"); data.ToArray(); return Json(data, JsonRequestBehavior.AllowGet); } }//end of function