public ActionResult SaveDieFlatRoll(DieFlatRoll Die) { string status = "ok"; if (ModelState.IsValid) { try { Die.CodArticle = articleRepository.GetNewCode(Die, customerSupplierRepository, Die.SupplierMaker, Die.SupplierMaker); articleRepository.Add(Die); articleRepository.Save(); status = "ok"; var obj = new { textStatus = status, }; return Json(obj, JsonRequestBehavior.AllowGet); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message); } } status = "err"; var retPW = PartialView(this, "~/Areas/Working/Views/Document/_SaveDieFlatRoll.cshtml", (Die)Die); var obj2 = new { textStatus = status, view = retPW }; return Json(obj2, JsonRequestBehavior.AllowGet); }
public ActionResult ExcelDie2(HttpPostedFileBase file) { DataSet ds = new DataSet(); if (Request.Files["file"].ContentLength > 0) { string fileExtension = System.IO.Path.GetExtension(Request.Files["file"].FileName); if (fileExtension == ".xls" || fileExtension == ".xlsx") { string fileLocation = Server.MapPath("~/Content/") + Request.Files["file"].FileName; if (System.IO.File.Exists(fileLocation)) { System.IO.File.Delete(fileLocation); } Request.Files["file"].SaveAs(fileLocation); string excelConnectionString = string.Empty; excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; //connection String for xls file format. if (fileExtension == ".xls") { excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; } //connection String for xlsx file format. else if (fileExtension == ".xlsx") { excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; } //Create Connection to Excel work book and add oledb namespace OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); excelConnection.Open(); DataTable dt = new DataTable(); dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (dt == null) { return null; } String[] excelSheets = new String[dt.Rows.Count]; int t = 0; //excel data saves in temp file here. foreach (DataRow row in dt.Rows) { excelSheets[t] = row["TABLE_NAME"].ToString(); t++; } OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString); string query = string.Format("Select * from [{0}]", excelSheets[0]); using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1)) { dataAdapter.Fill(ds); } excelConnection.Close(); excelConnection1.Close(); } if (fileExtension.ToString().ToLower().Equals(".xml")) { string fileLocation = Server.MapPath("~/Content/") + Request.Files["FileUpload"].FileName; if (System.IO.File.Exists(fileLocation)) { System.IO.File.Delete(fileLocation); } Request.Files["FileUpload"].SaveAs(fileLocation); XmlTextReader xmlreader = new XmlTextReader(fileLocation); // DataSet ds = new DataSet(); ds.ReadXml(xmlreader); xmlreader.Close(); } for (int i = 2; i <= ds.Tables[0].Rows.Count - 1; i++) { Die a; if ((ds.Tables[0].Rows[i][6].ToString()).Equals("")) { a = new DieFlatRoll(); } else { a = new DieFlexo(); } if (a.TypeOfArticle.ToString().Equals("DieFlexo")) { string format = String.Empty; try { format = ((Convert.ToDouble(ds.Tables[0].Rows[i][0]) / 10).ToString()) + "x" + ((Convert.ToDouble(ds.Tables[0].Rows[i][1]) / 10).ToString()); } catch (Exception) { format = "0x0"; } a.Format = format; a.MaxGain1 = Convert.ToInt32(ds.Tables[0].Rows[i][2]); a.MaxGain2 = Convert.ToInt32(ds.Tables[0].Rows[i][3]); try { a.Width = Convert.ToDouble(ds.Tables[0].Rows[i][5]) / 10; } catch (Exception) { a.Width = 0; } a.Z = Convert.ToInt32(ds.Tables[0].Rows[i][6]); a.PrintingFormat = a.Width + "x" + a.GetCmFromZ(Convert.ToInt32(a.Z ?? 0)); a.TaskExecutorName = ds.Tables[0].Rows[i][11].ToString(); a.CodDie = ds.Tables[0].Rows[i][13].ToString(); a.Description = ds.Tables[0].Rows[i][0].ToString() + "x" + ds.Tables[0].Rows[i][1].ToString(); // a.ArticleName = a.Description; var typeFormat = ds.Tables[0].Rows[i][0].ToString(); try { if (typeFormat.ToLower().Contains("tonda") || typeFormat.ToLower().Contains("roto")) { a.FormatType = 5; } else { if (typeFormat.ToLower().Contains("ova")) { a.FormatType = 1; } else { a.FormatType = 3; } } } catch (Exception) { a.FormatType = 3; } } else { string format = String.Empty; try { format = ((Convert.ToDouble(ds.Tables[0].Rows[i][0]) / 10).ToString()) + "x" + ((Convert.ToDouble(ds.Tables[0].Rows[i][1]) / 10).ToString()); } catch (Exception) { format = "0x0"; } a.Format = format; a.MaxGain1 = Convert.ToInt32(ds.Tables[0].Rows[i][2]); a.MaxGain2 = Convert.ToInt32(ds.Tables[0].Rows[i][3]); try { a.Width = Convert.ToDouble(ds.Tables[0].Rows[i][5]) / 10; } catch (Exception) { a.Width = 0; } a.PrintingFormat = a.Width + "x" + (Convert.ToInt32(ds.Tables[0].Rows[i][7]) / 10); a.TaskExecutorName = ds.Tables[0].Rows[i][11].ToString(); a.CodDie = ds.Tables[0].Rows[i][13].ToString(); a.Description = ds.Tables[0].Rows[i][0].ToString() + "x" + ds.Tables[0].Rows[i][1].ToString(); // a.ArticleName = a.Description; var typeFormat = ds.Tables[0].Rows[i][0].ToString(); try { if (typeFormat.ToLower().Contains("tonda") || typeFormat.ToLower().Contains("roto")) { a.FormatType = 5; } else { if (typeFormat.ToLower().Contains("ova")) { a.FormatType = 1; } else { a.FormatType = 3; } } } catch (Exception) { a.FormatType = 3; } } a.CodArticle = articleRepository.GetNewCode(a, customerSupplierRepository, "Die", "Die"); var b = articleRepository.GetSingle(a.CodArticle); if (b == null) { articleRepository.Add(a); } else { //b.ProductName = a.ProductName; //b.CodMenuProduct = "Vuoto"; articleRepository.Edit(b); } articleRepository.Save(); } } return View(); }
public ActionResult EditDieFlatRoll(DieFlatRoll c) { if (ModelState.IsValid) { try { articleRepository.Edit(c); articleRepository.Save(); return Json(new { redirectUrl = Url.Action("IndexDie") }); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message); } } foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { Console.WriteLine(error); } } //If we come here, something went wrong. Return it back. //multi submit ViewBag.ActionMethod = "EditDieFlatRoll"; return PartialView("_EditAndCreateDieFlatRoll", c); }
public ActionResult EditDieFlatRoll(string id) { DieFlatRoll viewModel = new DieFlatRoll(); viewModel = (DieFlatRoll)articleRepository.GetSingle(id); //get producer and maker if (viewModel.CodArticle == "") return HttpNotFound(); //is used to know where we are from and go ViewBag.ActionMethod = "EditDieFlatRoll"; return View("EditDieFlatRoll", viewModel); }
public ActionResult CreateDieFlatRoll(DieFlatRoll c) { if (ModelState.IsValid) { try { c.CodArticle = articleRepository.GetNewCode(c, customerSupplierRepository, c.SupplierMaker, c.SupplierMaker); articleRepository.Add(c); articleRepository.Save(); return Json(new { redirectUrl = Url.Action("IndexDie") }); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message); } } //view name is needed for reach right view because to using more than one submit we have to use "Action" in action method name ViewBag.ActionMethod = "CreateDieFlatRoll"; return PartialView("_EditAndCreateDieFlatRoll", c); }