public ActionResult Create(tblrole tblrole) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); // Save was Start Now int UserID = Convert.ToInt32(Session["UserId"]); tblrole.CreatedBy = UserID; tblrole.CreatedOn = System.DateTime.Now; tblrole.IsDeleted = 0; //ActiveLog Code string CompleteModificationdetail = "New Creation"; Action = "Create"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End db.tblroles.Add(tblrole); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(tblsendermailid tblsm) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); ViewBag.AutoEmailType = new SelectList(db.tblemailreporttypes.Where(m => m.IsDeleted == 0), "ERTID", "ReportType"); tblsm.CreatedBy = Convert.ToInt32(Session["UserId"]); tblsm.CreatedOn = System.DateTime.Now; tblsm.IsDeleted = 0; //ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End db.tblsendermailids.Add(tblsm); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(tblpart tblpart, int Unit = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); tblpart.CreatedBy = Convert.ToInt32(Session["UserId"]); tblpart.UnitDesc = Unit; tblpart.CreatedOn = DateTime.Now.ToString("yyyyMMddHHmmss"); tblpart.IsDeleted = 0; //ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End db.tblparts.Add(tblpart); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(message_code_master msgcm) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } int UserID = Convert.ToInt32(Session["UserId"]); ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); // Save was Start Now var msgcode = db.message_code_master.Where(m => m.MessageCode == msgcm.MessageCode).SingleOrDefault(); if (msgcode == null) { msgcm.InsertedBy = UserID.ToString(); msgcm.InsertedOn = System.DateTime.Now; msgcm.IsDeleted = 0; msgcm.MessageType = "BREAKDOWN"; msgcm.MessageMCode = "M" + msgcm.MessageCode; db.message_code_master.Add(msgcm); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BDCode = "BREAKDOWN Code already exist"; ViewBag.MessageType = new SelectList(db.tbldowntimecategories.Where(m => m.IsDeleted == 0), "DTCategory", "DTCategory"); return(View(msgcm)); }
public ActionResult Create(tbldowntimecategory tbldowntimecategory) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); if (ModelState.IsValid) { //ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End DateTime TimeOFCreation = DateTime.Now; //db.createDownTimeCategory(tbldowntimecategory.DTCategory, tbldowntimecategory.DTCategoryDesc, 0, TimeOFCreation,1); tbldowntimecategory.CreatedBy = UserID; tbldowntimecategory.CreatedOn = TimeOFCreation; db.tbldowntimecategories.Add(tbldowntimecategory); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbldowntimecategory)); }
public ActionResult Create(tblcustomer tblcust, HttpPostedFileBase inputimg) { if (Request.Cookies["YourApLogin&"] != null) { string username = Request.Cookies["YourAppLogin"].Values["username"]; string RoleID = Request.Cookies["YourAppLogin"].Values["RoleID"]; string UserID = Request.Cookies["YourAppLogin"].Values["UserId"]; Session["Username"] = username; Session["RoleID"] = RoleID; Session["UserId"] = UserID; } else if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } else { ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); } {// string filename = ""; byte[] bytes; int BytestoRead; int numBytesRead; if (inputimg != null) { filename = Path.GetFileName(inputimg.FileName); bytes = new byte[inputimg.ContentLength]; BytestoRead = (int)inputimg.ContentLength; numBytesRead = 0; while (BytestoRead > 0) { int n = inputimg.InputStream.Read(bytes, numBytesRead, BytestoRead); if (n == 0) { break; } numBytesRead += n; BytestoRead -= n; } tblcust.Logo = bytes; } // int UserID1 = Convert.ToInt32(Session["UserID"].ToString()); // Save was Start Now tblcust.CreatedBy = UserID1; tblcust.CreatedOn = System.DateTime.Now; tblcust.IsDeleted = 0; db.tblcustomers.Add(tblcust); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblcust)); }
public ActionResult Create(tblmailid tmi) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); #region//ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); //string CompleteModificationdetail = "New Creation"; //Action = "Create"; // ActiveLogStorage Obj = new ActiveLogStorage(); // Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End #endregion //MailID Details validation string name = tmi.Name.ToString(); string emailid = tmi.EmailID.ToString(); string contactNo = tmi.ContactNo.ToString(); var doesTheseExists = db.tblmailids.Where(m => m.IsDeleted == 0 && (m.Name == name || m.EmailID == emailid || m.ContactNo == contactNo)).ToList(); if (doesTheseExists.Count == 0) { tmi.IsDeleted = 0; tmi.CreatedBy = UserID; tmi.CreatedOn = DateTime.Now; db.tblmailids.Add(tmi); db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = null; var doesNameExists = db.tblmailids.Where(m => m.IsDeleted == 0 && m.Name == name).ToList(); if (doesNameExists.Count > 0) { Session["Error"] += "Duplicate Name. "; } var doesMailIdExists = db.tblmailids.Where(m => m.EmailID == emailid).ToList(); if (doesMailIdExists.Count > 0) { Session["Error"] += " Duplicate Email ID. "; } var doesCnoExists = db.tblmailids.Where(m => m.IsDeleted == 0 && m.ContactNo == contactNo).ToList(); if (doesCnoExists.Count > 0) { Session["Error"] += " Duplicate Contact Number. "; } return(View(tmi)); } }
//[HttpPost] //public ActionResult Create(OperatorModule OPTDet) //{ // if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) // { // return RedirectToAction("Login", "Login", null); // } // ViewBag.Logout = Session["Username"].ToString().ToUpper(); // ViewBag.roleid = Session["RoleID"]; // int UserID = Convert.ToInt32(Session["UserId"]); // string Dept = OPTDet.OPDetails.Dept; // string OperatorName = OPTDet.OPDetails.OperatorName; // int OperatorID = OPTDet.OPDetails.OperatorID; // bool check = ValidationCheckForInsertion(OperatorID); // if (check == true) // { // OPTDet.OPDetails.CreatedOn = DateTime.Now; // OPTDet.OPDetails.CorrectedDate = DateTime.Now.Date; // OPTDet.OPDetails.CreatedBy = UserID; // OPTDet.OPDetails.isDeleted = 0; // db.tbloperatordetails.Add(OPTDet.OPDetails); // db.SaveChanges(); // } // return RedirectToAction("Index"); //} public string CreateOperator(string dept, int operatorId, string operatorName, int OperatorDesc) { string res = ""; int UserID = Convert.ToInt32(Session["UserId"]); bool check = ValidationCheckForInsertion(operatorId); if (check == true) { tbloperatordetail OPTDet = new tbloperatordetail(); OPTDet.CreatedOn = DateTime.Now; OPTDet.CorrectedDate = DateTime.Now.Date; OPTDet.CreatedBy = UserID; OPTDet.isDeleted = 0; OPTDet.Dept = dept; OPTDet.OperatorID = operatorId; OPTDet.OperatorName = operatorName; OPTDet.OperatorDesc = OperatorDesc; db.tbloperatordetails.Add(OPTDet); db.SaveChanges(); res = "Success"; } else { res = "failure"; } return(res); }
public void setvalue(string[,] set) { int i = 0; int ModuleID = 0; string Modulename = set[0, 8]; int RlId = Convert.ToInt32(set[0, 7]); var note = (from n in db.tblmodulemasters where n.ModuleName == Modulename select n).First(); if (note != null) { ModuleID = note.ModuleID; } //Checking Role and dodule In DB int Count = 0; try { var RoleModule = (from n in db.tblroleplaymasters where (n.ModuleID == ModuleID && n.RolePlayID == RlId) select n).First(); if (RoleModule != null) { Count = 1; } } catch { } if (Count == 0) { //Taking moduleId From Table for (int j = 0; j < 1; j++) { tblroleplaymaster rl = new tblroleplaymaster(); rl.IsAdded = Convert.ToBoolean(set[j, 0]); rl.IsAll = Convert.ToBoolean(set[j, 1]); rl.IsDeleted = Convert.ToInt32(set[j, 2]); rl.IsEdited = Convert.ToBoolean(set[j, 3]); rl.IsHidden = Convert.ToBoolean(set[j, 4]); rl.IsReadOnly = Convert.ToBoolean(set[j, 5]); rl.IsRemoved = Convert.ToBoolean(set[j, 6]); rl.RoleID = Convert.ToInt32(set[j, 7]); rl.ModuleID = ModuleID; rl.CreatedBy = Convert.ToInt32(Session["UserID"]); rl.CreatedOn = System.DateTime.Now; db.tblroleplaymasters.Add(rl); db.SaveChanges(); } } }
public ActionResult Create(tbluser tbluser) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; int roleid = Convert.ToInt32(Session["RoleID"]); String Username = Session["Username"].ToString(); //ViewBag.PrimaryRole = new SelectList(db.tblroles.Where(m => m.IsDeleted == 0), "Role_ID", "RoleDesc"); //ViewBag.SecondaryRole = new SelectList(db.tblroles.Where(m => m.IsDeleted == 0), "Role_ID", "RoleDesc"); tbluser.CreatedBy = roleid; tbluser.CreatedOn = System.DateTime.Now; tbluser.IsDeleted = 0; ////ActiveLog Code //int UserID = Convert.ToInt32(Session["UserId"]); //string CompleteModificationdetail = "New Creation"; //Action = "Create"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); ////End var dupUserData = db.tblusers.Where(m => m.IsDeleted == 0 && m.UserName == tbluser.UserName).ToList(); if (dupUserData.Count == 0) { int primaryrole = Convert.ToInt32(tbluser.PrimaryRole); if (primaryrole != 3) { // tbluser.MachineID = ; } db.tblusers.Add(tbluser); db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = "User Name Exists."; ViewBag.PrimaryRole = new SelectList(db.tblroles.Where(m => m.IsDeleted == 0 && m.Role_ID >= roleid), "Role_ID", "RoleDesc", tbluser.PrimaryRole); ViewBag.SecondaryRole = new SelectList(db.tblroles.Where(m => m.IsDeleted == 0 && m.Role_ID >= roleid), "Role_ID", "RoleDesc", tbluser.SecondaryRole); ViewBag.MachineID = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0), "MachineID", "MachineDispName", tbluser.MachineID); return(View(tbluser)); } }
public ActionResult Create(tblplant tblp) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); #region//ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; // ActiveLogStorage Obj = new ActiveLogStorage(); // Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End #endregion string plantName = tblp.PlantName.ToString(); var doesThisPlantExist = db.tblplants.Where(m => m.IsDeleted == 0 && m.PlantName == plantName).ToList(); if (doesThisPlantExist.Count == 0) { tblp.CreatedBy = UserID; tblp.CreatedOn = DateTime.Now; db.tblplants.Add(tblp); db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = "Plant Name already Exists."; return(View(tblp)); } }
public ActionResult Create(tbldaytiming tbldaytiming) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } tbldaytiming.CreatedBy = 1; tbldaytiming.CreatedOn = DateTime.Now; tbldaytiming.IsDeleted = 0; //if (ModelState.IsValid) { db.tbldaytimings.Add(tbldaytiming); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbldaytiming)); }
public ActionResult Create(tblmachinedetail tblmachine, int Shop = 0, int Plant = 0, int Cell = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; string machineinv = tblmachine.MachineInvNo; var duplicateEntry = db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.PlantID == Plant && m.ShopID == Shop && m.CellID == Cell && m.MachineInvNo == machineinv).ToList(); if (duplicateEntry.Count == 0) { tblmachine.InsertedBy = Convert.ToInt32(Session["UserId"]); tblmachine.InsertedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); tblmachine.IsDeleted = 0; tblmachine.IsParameters = 1; tblmachine.MachineType = "2"; tblmachine.PlantID = Plant; tblmachine.ShopID = Shop; var shopname = db.tblshops.Where(m => m.IsDeleted == 0 && m.ShopID == Shop).Select(m => m.ShopName).FirstOrDefault(); tblmachine.ShopNo = shopname.ToString(); if (Cell != 0) { tblmachine.CellID = Cell; } //ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); String Username = Session["Username"].ToString(); string CompleteModificationdetail = "New Creation"; Action = "Create"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End db.tblmachinedetails.Add(tblmachine); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(tblshift_mstr tblshift_mstr) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; tblshift_mstr.CreatedBy = Convert.ToInt32(Session["UserId"]); tblshift_mstr.CreatedOn = DateTime.Now; tblshift_mstr.IsDeleted = 0; //if (ModelState.IsValid) { db.tblshift_mstr.Add(tblshift_mstr); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblshift_mstr)); }
public ActionResult Create(tblplannedbreak tblplannedbreak) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; tblplannedbreak.CreatedBy = 1; tblplannedbreak.CreatedOn = DateTime.Now; tblplannedbreak.IsDeleted = 0; //if (ModelState.IsValid) { db.tblplannedbreaks.Add(tblplannedbreak); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblplannedbreak)); }
public ActionResult Create(tblcell tblp, int Shop = 0, int Plant = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); #region//ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; // ActiveLogStorage Obj = new ActiveLogStorage(); // Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End #endregion //Cell name validation string cellname = tblp.CellName.ToString(); var doesThisShopExists = db.tblcells.Where(m => m.IsDeleted == 0 && m.PlantID == Plant && m.ShopID == Shop && m.CellName == cellname).ToList(); if (doesThisShopExists.Count == 0) { tblp.CreatedBy = UserID; tblp.CreatedOn = DateTime.Now; tblp.ShopID = Shop; tblp.PlantID = Plant; db.tblcells.Add(tblp); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.Plant = new SelectList(db.tblplants.Where(m => m.IsDeleted == 0), "PlantID", "PlantName", Plant); ViewBag.Shop = new SelectList(db.tblshops.Where(m => m.IsDeleted == 0), "ShopID", "ShopName", Shop); Session["Error"] = "Cell Name already exists for this Plant/Shop."; return(View(tblp)); } }
public ActionResult Create(tblmachinecategory tblmc) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); //ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; ActiveLogStorage Obj = new ActiveLogStorage(); Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End db.tblmachinecategories.Add(tblmc); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(tblmachineallocation tblmachine) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; string CorrectedDate = null; tbldaytiming StartTime = db.tbldaytimings.Where(m => m.IsDeleted == 0).SingleOrDefault(); TimeSpan Start = StartTime.StartTime; if (Start <= DateTime.Now.TimeOfDay) { CorrectedDate = DateTime.Now.ToString("yyyy-MM-dd"); } else { CorrectedDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); } tblmachine.CreatedBy = Convert.ToInt32(Session["UserId"]); tblmachine.CreatedOn = DateTime.Now; tblmachine.CorrectedDate = CorrectedDate; tblmachine.IsDeleted = 0; if (ModelState.IsValid) { db.tblmachineallocations.Add(tblmachine); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.tblusers.Where(m => m.IsDeleted == 0 && m.PrimaryRole == 3), "UserID", "DisplayName"); ViewBag.ShiftID = new SelectList(db.tblshift_mstr.Where(m => m.IsDeleted == 0), "ShiftID", "ShiftName"); ViewBag.MachineID = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0), "MachineID", "MachineDispName"); return(View(tblmachine)); }
public ActionResult Create(tblmodulemaster tblModule) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; if (Request.Cookies["YourApLogin&"] != null) { string username = Request.Cookies["YourAppLogin"].Values["username"]; string RoleID = Request.Cookies["YourAppLogin"].Values["RoleID"]; string UserID = Request.Cookies["YourAppLogin"].Values["UserId"]; Session["Username"] = username; Session["RoleID"] = RoleID; Session["UserId"] = UserID; } else if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } else { ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); } int UserID1 = Convert.ToInt32(Session["UserID"].ToString()); // Save was Start Now string modulename = tblModule.ModuleName; tblModule.CreatedBy = UserID1; tblModule.CreatedOn = System.DateTime.Now; tblModule.IsDeleted = 0; db.tblmodulemasters.Add(tblModule); db.SaveChanges(); //Saving in module helper tblmodulehelper rl = new tblmodulehelper(); rl.IsAdded = false; rl.IsAll = false; rl.IsDeleted = 0; rl.IsEdited = false; rl.IsHidden = false; rl.IsReadonly = false; rl.IsRemoved = false; rl.RoleID = 1; rl.ModuleID = modulename; db.tblmodulehelpers.Add(rl); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(tblmasterparts_st_sw tblmp) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; //ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); //string CompleteModificationdetail = "New Creation"; //Action = "Create"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End string partno = tblmp.PartNo; string opno = tblmp.OpNo; var partInMP = db.tblmasterparts_st_sw.Where(m => m.IsDeleted == 0 && m.PartNo == partno && m.OpNo == opno).ToList(); if (partInMP.Count > 0) { Session["Error"] = "PartNo " + partno + " has details in Database"; return(View(tblmp)); } tblmp.CreatedOn = DateTime.Now; tblmp.CreatedBy = UserID; tblmp.IsDeleted = 0; db.tblmasterparts_st_sw.Add(tblmp); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(tblpriorityalarm tblpriorityalarm) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); string CreatedON = DateTime.Now.ToString("yyyyMMddHHmmss"); if (ModelState.IsValid) { string CorrectedDate = null; tbldaytiming StartTime = db.tbldaytimings.Where(m => m.IsDeleted == 0).SingleOrDefault(); TimeSpan Start = StartTime.StartTime; if (Start <= DateTime.Now.TimeOfDay) { CorrectedDate = DateTime.Now.ToString("yyyy-MM-dd"); } else { CorrectedDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); } //ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End tblpriorityalarm.CreatedBy = UserID; tblpriorityalarm.CreatedOn = CreatedON; tblpriorityalarm.CorrectedDate = CorrectedDate; tblpriorityalarm.MachineID = 1; db.tblpriorityalarms.Add(tblpriorityalarm); db.SaveChanges(); //db.createAlarmsPrority(tblpriorityalarm.AlarmNumber, tblpriorityalarm.AlarmDesc, tblpriorityalarm.AxisNo, tblpriorityalarm.AlarmGroup, tblpriorityalarm.PriorityNumber, 0, CreatedON, 1); return(RedirectToAction("Index")); } ViewBag.MachineID = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0), "MachineID", "MachineDispName"); return(View(tblpriorityalarm)); }
public ActionResult Create(IEnumerable <tblshiftdetail> tblp, int ShiftMethod = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); #region//ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; // ActiveLogStorage Obj = new ActiveLogStorage(); // Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End #endregion //shop name validation //string shopname = tblp.ShopName.ToString(); //var doesThisShiftDetailsExists = db.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftDetailsName == ).ToList(); //if (doesThisShopExists.Count == 0) //{ //check if there's a entry of this shiftMethod in tblshiftdetails var shiftmethodCheck = db.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).ToList(); if (shiftmethodCheck.Count > 0) { Session["Error"] = "ShiftDetails for this ShiftMethod Exists."; ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName"); return(RedirectToAction("Index")); } var shiftmethodiddata = db.tblshiftmethods.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).SingleOrDefault(); int noofshifts = shiftmethodiddata.NoOfShifts; int rowscount = 0; //to check if names are duplicate List <string> shiftdetailsnames = new List <string>(); foreach (var shift in tblp) { if (shift.ShiftDetailsName != null) { shiftdetailsnames.Add(shift.ShiftDetailsName); } } // for current shiftdetails. if (shiftdetailsnames.Distinct().Count() != shiftdetailsnames.Count()) { //Console.WriteLine("List contains duplicate values."); TempData["Error"] = "Shift Names Cannot be Same."; ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName"); return(RedirectToAction("Index")); } try { foreach (var shift in tblp) { if (rowscount < noofshifts) { // calculate duration int duration = 0; string starttimestring = "2016-06-02" + " " + shift.ShiftStartTime; DateTime starttimedatetime = Convert.ToDateTime(starttimestring); string endtimestring = null; TimeSpan tsStart = (System.TimeSpan)shift.ShiftStartTime; TimeSpan tsEnd = (System.TimeSpan)shift.ShiftEndTime; int result = TimeSpan.Compare(tsStart, tsEnd); if (result < 0) { endtimestring = "2016-06-02" + " " + shift.ShiftEndTime; } else if (result > 0) { endtimestring = "2016-06-03" + " " + shift.ShiftEndTime; shift.NextDay = 1; } DateTime endtimedatetime = Convert.ToDateTime(endtimestring); TimeSpan ts = endtimedatetime.Subtract(starttimedatetime); duration = Convert.ToInt32(ts.TotalMinutes); //create new object/row tblshiftdetail tsd = new tblshiftdetail(); tsd.CreatedBy = UserID; tsd.CreatedOn = DateTime.Now; tsd.Duration = duration; tsd.IsDeleted = 0; tsd.NextDay = shift.NextDay; tsd.ShiftMethodID = ShiftMethod; tsd.ShiftDetailsDesc = shift.ShiftDetailsDesc; tsd.ShiftDetailsName = shift.ShiftDetailsName; tsd.ShiftEndTime = shift.ShiftEndTime; tsd.ShiftStartTime = shift.ShiftStartTime; db.tblshiftdetails.Add(tsd); db.SaveChanges(); } rowscount++; } } catch (Exception e) { Session["Error"] = "Shift Name already exists for this ShiftMethod."; using (i_facility_tamlEntities db1 = new i_facility_tamlEntities()) { var todeletedata = db1.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).ToList(); foreach (var row in todeletedata) { row.IsDeleted = 1; db.Entry(row).State = EntityState.Modified; db.SaveChanges(); } } } //ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName"); return(RedirectToAction("Index")); }
public ActionResult Create(tbllossescode tlc, int Level1 = 0, int Level2 = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } int UserID = Convert.ToInt32(Session["UserId"]); ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; tlc.CreatedBy = UserID; tlc.CreatedOn = DateTime.Now; tlc.IsDeleted = 0; tlc.MessageType = "BREAKDOWN"; if (Convert.ToInt16(tlc.LossCodesLevel) == 2) { tlc.LossCodesLevel1ID = Level1; var duplosscode = db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCode == tlc.LossCode && m.LossCodesLevel1ID == tlc.LossCodesLevel1ID).ToList(); if (duplosscode.Count() == 0) { //Here check if Level1 code is used in tbllossofentry, if so then create new copy of it with Different LossID. var lossOfEntryData = db.tbllossofentries.Where(m => m.MessageCodeID == Level1).ToList(); if (lossOfEntryData.Count() > 0) { var lossPrvData = db.tbllossescodes.Where(m => m.LossCodeID == Level1 && m.IsDeleted == 0).FirstOrDefault(); tbllossescode tlcNewPrvLevel = new tbllossescode(); tlcNewPrvLevel.ContributeTo = lossPrvData.ContributeTo; tlcNewPrvLevel.CreatedBy = lossPrvData.CreatedBy; tlcNewPrvLevel.CreatedOn = lossPrvData.CreatedOn; tlcNewPrvLevel.IsDeleted = 0; tlcNewPrvLevel.LossCode = lossPrvData.LossCode; tlcNewPrvLevel.LossCodeDesc = lossPrvData.LossCodeDesc; tlcNewPrvLevel.LossCodesLevel = lossPrvData.LossCodesLevel; tlcNewPrvLevel.LossCodesLevel1ID = lossPrvData.LossCodesLevel1ID; tlcNewPrvLevel.LossCodesLevel2ID = lossPrvData.LossCodesLevel2ID; tlcNewPrvLevel.MessageType = lossPrvData.MessageType; tlcNewPrvLevel.ModifiedBy = lossPrvData.ModifiedBy; tlcNewPrvLevel.ModifiedOn = lossPrvData.ModifiedOn; db.tbllossescodes.Add(tlcNewPrvLevel); db.SaveChanges(); //Delete the Old one. lossPrvData.IsDeleted = 1; lossPrvData.ModifiedOn = DateTime.Now; lossPrvData.ModifiedBy = UserID; db.Entry(lossPrvData).State = EntityState.Modified; db.SaveChanges(); //Give new Level1 LossCodeID to 2nd level code. int Level1LossCodeID = tlcNewPrvLevel.LossCodeID; tlc.LossCodesLevel1ID = Level1LossCodeID; } db.tbllossescodes.Add(tlc); db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = "Breakdown code already Exist."; ViewData["Level1"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 1 && m.MessageType == "BREAKDOWN" && m.LossCodeID != 9999), "LossCodeID", "LossCode"); ViewData["Level2"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 2 && m.MessageType == "BREAKDOWN"), "LossCodeID", "LossCode"); return(View(tlc)); } } if (Convert.ToInt16(tlc.LossCodesLevel) == 3) { tlc.LossCodesLevel1ID = Level1; tlc.LossCodesLevel2ID = Level2; var duplosscode = db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCode == tlc.LossCode && m.LossCodesLevel1ID == tlc.LossCodesLevel1ID && m.LossCodesLevel2ID == tlc.LossCodesLevel2ID).ToList(); if (duplosscode.Count() == 0) { //Here check if Level1 code is used in tbllossofentry, if so then create new copy of it with Different LossID. var lossOfEntryData = db.tbllossofentries.Where(m => m.MessageCodeID == Level2).ToList(); if (lossOfEntryData.Count() > 0) { var lossPrvData = db.tbllossescodes.Where(m => m.LossCodeID == Level2 && m.IsDeleted == 0).FirstOrDefault(); tbllossescode tlcNewPrvLevel = new tbllossescode(); tlcNewPrvLevel.ContributeTo = lossPrvData.ContributeTo; tlcNewPrvLevel.CreatedBy = lossPrvData.CreatedBy; tlcNewPrvLevel.CreatedOn = lossPrvData.CreatedOn; tlcNewPrvLevel.IsDeleted = 0; tlcNewPrvLevel.LossCode = lossPrvData.LossCode; tlcNewPrvLevel.LossCodeDesc = lossPrvData.LossCodeDesc; tlcNewPrvLevel.LossCodesLevel = lossPrvData.LossCodesLevel; tlcNewPrvLevel.LossCodesLevel1ID = lossPrvData.LossCodesLevel1ID; tlcNewPrvLevel.LossCodesLevel2ID = lossPrvData.LossCodesLevel2ID; tlcNewPrvLevel.MessageType = lossPrvData.MessageType; tlcNewPrvLevel.ModifiedBy = lossPrvData.ModifiedBy; tlcNewPrvLevel.ModifiedOn = lossPrvData.ModifiedOn; db.tbllossescodes.Add(tlcNewPrvLevel); db.SaveChanges(); //Delete the Old one. lossPrvData.IsDeleted = 1; lossPrvData.ModifiedOn = DateTime.Now; lossPrvData.ModifiedBy = UserID; db.Entry(lossPrvData).State = EntityState.Modified; db.SaveChanges(); //Give new Level1 LossCodeID to 2nd level code. int Level2LossCodeID = tlcNewPrvLevel.LossCodeID; tlc.LossCodesLevel2ID = Level2LossCodeID; } db.tbllossescodes.Add(tlc); db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = "Breakdown code already Exist."; ViewData["Level1"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 1 && m.MessageType == "BREAKDOWN" && m.LossCodeID != 9999), "LossCodeID", "LossCode"); ViewData["Level2"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 2 && m.MessageType == "BREAKDOWN"), "LossCodeID", "LossCode"); return(View(tlc)); } } if (Convert.ToInt16(tlc.LossCodesLevel) == 1) { var duplosscode = db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCode == tlc.LossCode).ToList(); if (duplosscode.Count() == 0) { db.tbllossescodes.Add(tlc); db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = "Breakdown code already Exist."; ViewData["Level1"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 1 && m.MessageType == "BREAKDOWN" && m.LossCodeID != 9999), "LossCodeID", "LossCode"); ViewData["Level2"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 2 && m.MessageType == "BREAKDOWN"), "LossCodeID", "LossCode"); return(View(tlc)); } } return(RedirectToAction("Index")); }
public ActionResult Create(tbl_autoreportsetting tee) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); #region//ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); //string CompleteModificationdetail = "New Creation"; //Action = "Create"; // ActiveLogStorage Obj = new ActiveLogStorage(); // Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End #endregion //Email validation string RL1 = Convert.ToString(tee.ReportID); string RL2 = Convert.ToString(tee.BasedOn); string RL3 = Convert.ToString(tee.AutoReportTimeID); string ValidEscalation = null; //ValidEscalation = IsItValidEscalation(RL1, RL2, RL3); if (tee.AutoReportTimeID == 1) //day { tee.NextRunDate = Convert.ToDateTime("2018-12-27 17:35:00"); //tee.NextRunDate = DateTime.Now.AddDays(1); } else if (tee.AutoReportTimeID == 2) //week { DateTime begining, end; GetWeek(DateTime.Now, new CultureInfo("fr-FR"), out begining, out end); tee.NextRunDate = end.AddDays(1); } else if (tee.AutoReportTimeID == 3) //month { DateTime Temp2 = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 01, 00, 00, 01); tee.NextRunDate = Temp2; } else if (tee.AutoReportTimeID == 4) //year { DateTime Temp2 = new DateTime(DateTime.Now.AddYears(1).Year, 01, 01, 00, 00, 01); tee.NextRunDate = Temp2; } var DupData = db.tbl_autoreportsetting.Where(m => m.ReportID == tee.ReportID && m.BasedOn == tee.BasedOn && m.AutoReportTimeID == tee.AutoReportTimeID && m.PlantID == tee.PlantID && m.ShopID == tee.ShopID && m.CellID == tee.CellID && m.MachineID == tee.MachineID).FirstOrDefault(); if (DupData != null) { ValidEscalation += " Duplicate Entry "; } if (ValidEscalation == null) { tee.CreatedBy = UserID; tee.CreatedOn = DateTime.Now; tee.IsDeleted = 0; db.tbl_autoreportsetting.Add(tee); db.SaveChanges(); } else { Session["Error"] = ValidEscalation; ViewBag.RL1 = new SelectList(db.tbl_reportmaster.Where(m => m.IsDeleted == 0), "ReportID", "ReportDispName", tee.ReportID); ViewBag.RL2 = new SelectList(db.tbl_autoreportbasedon.Where(m => m.IsDeleted == 0), "BasedOnID", "BasedOn", tee.BasedOn); ViewBag.RL3 = new SelectList(db.tbl_autoreporttime.Where(m => m.IsDeleted == 0), "AutoReportTimeID", "AutoReportTime", tee.AutoReportTimeID); ViewBag.Plant = new SelectList(db.tblplants.Where(m => m.IsDeleted == 0), "PlantID", "PlantName", tee.PlantID); ViewBag.Shop = new SelectList(db.tblshops.Where(m => m.IsDeleted == 0 && m.PlantID == tee.PlantID), "ShopID", "ShopName", tee.ShopID); ViewBag.Cell = new SelectList(db.tblcells.Where(m => m.IsDeleted == 0 && m.PlantID == tee.ShopID), "CellID", "CellName", tee.CellID); ViewBag.WorkCenter = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.IsNormalWC == 0 && m.PlantID == tee.PlantID && m.ShopID == tee.ShopID && m.CellID == tee.CellID), "MachineID", "MachineInvNo", tee.MachineID); return(View(tee)); } return(RedirectToAction("Index")); }
public ActionResult ImportPartWiseSP(HttpPostedFileBase file) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } //Deleting Excel file #region string fileLocation1 = Server.MapPath("~/Content/"); DirectoryInfo di = new DirectoryInfo(fileLocation1); FileInfo[] files = di.GetFiles("*.xlsx").Where(p => p.Extension == ".xlsx").ToArray(); foreach (FileInfo file1 in files) { try { file1.Attributes = FileAttributes.Normal; System.IO.File.Delete(file1.FullName); } catch { } } #endregion 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 = @"C:\TataReport\ReportsList" + Request.Files["file"].FileName; if (System.IO.File.Exists(fileLocation)) { try { System.IO.File.Delete(fileLocation); } catch { } } 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(); } if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; StringBuilder sb = new StringBuilder(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string result = ""; double SurfaceArea = 0; double Perimeter = 0; string PartName = ""; string a = ds.Tables[0].Rows[i][1].ToString(); if (string.IsNullOrEmpty(a) == false) { try { SurfaceArea = Math.Round(Convert.ToDouble(ds.Tables[0].Rows[i][1]), 3); } catch { result = result + "surface area " + SurfaceArea + "should not be empty and should be number.\n"; continue; } try { Perimeter = Math.Round(Convert.ToDouble(ds.Tables[0].Rows[i][2]), 3); } catch { result = result + "Perimeter " + Perimeter + "should not be empty and should be number.\n"; continue; } try { PartName = Convert.ToString(ds.Tables[0].Rows[i][0]); } catch { result = result + "PartName " + PartName + "should not be empty and should be string value.\n"; continue; } tblpartwisesp obj = new tblpartwisesp(); String Username = Session["Username"].ToString(); obj.CreatedBy = Convert.ToInt32(Session["UserId"]); obj.CreatedOn = DateTime.Now; obj.IsDeleted = 0; obj.SurfaceArea = SurfaceArea; obj.Perimeter = Perimeter; obj.PartName = PartName; if (result == "") { db.tblpartwisesps.Add(obj); db.SaveChanges(); } } sb.Append(result); } if (sb.Length != 0) { TempData["SurafaceArea"] = sb; } else { TempData["SurafaceArea"] = "Please Upload a Valid Excel File for Parts"; } } return(RedirectToAction("Index", "Dashboard")); }
public ActionResult ImportOperatorData(HttpPostedFileBase file, string UploadType) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } string UserId = Session["UserId"].ToString(); //Deleting Excel file #region string fileLocation1 = Server.MapPath("~/Content/"); DirectoryInfo di = new DirectoryInfo(fileLocation1); FileInfo[] files = di.GetFiles("*.xlsx").Where(p => p.Extension == ".xlsx").ToArray(); foreach (FileInfo file1 in files) { try { file1.Attributes = FileAttributes.Normal; System.IO.File.Delete(file1.FullName); } catch { } } #endregion 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(); } if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"].ToString().ToUpper(); ViewBag.roleid = Session["RoleID"]; string text = ""; string ErrorMsg = null; if (UploadType == "New") // Delete Duplicate and Insert New. // if not Duplicate insert that { #region for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tbloperatordetail tblmp = new tbloperatordetail(); String Username = Session["Username"].ToString(); tblmp.CreatedBy = Convert.ToInt32(Session["UserId"]); tblmp.CreatedOn = DateTime.Now; tblmp.isDeleted = 0; string Dept = null, OperatorName = null; int OperatorID = 0; Dept = Convert.ToString(ds.Tables[0].Rows[i][0]); OperatorName = Convert.ToString(ds.Tables[0].Rows[i][1]); OperatorID = Convert.ToInt32(ds.Tables[0].Rows[i][2]); bool check = ValidationCheckForInsertion(OperatorID); if (check == true) { using (i_facility_tamlEntities db = new i_facility_tamlEntities()) { if (string.IsNullOrEmpty(Dept) || string.IsNullOrEmpty(OperatorName) || OperatorID == 0) { text = text + htmlerrorMaker(Dept, OperatorName, OperatorID, "Dept, OperatorName or OperatorID cannot be empty/Check the format"); continue; } else { try { tblmp.Dept = Dept.Trim(); tblmp.OperatorName = OperatorName.Trim(); tblmp.OperatorID = OperatorID; tblmp.CreatedBy = Convert.ToInt32(UserId); tblmp.CreatedOn = DateTime.Now; } catch { } } } db.tbloperatordetails.Add(tblmp); try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } } #endregion } else if (UploadType == "Update") // Delete Duplicate and Insert New. // if not Duplicate insert that { #region for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tbloperatordetail tblmp = new tbloperatordetail(); String Username = Session["Username"].ToString(); tblmp.CreatedBy = Convert.ToInt32(Session["UserId"]); tblmp.CreatedOn = DateTime.Now; tblmp.isDeleted = 0; string Dept = null, OperatorName = null; int OperatorID = 0; Dept = Convert.ToString(ds.Tables[0].Rows[i][0]); OperatorName = Convert.ToString(ds.Tables[0].Rows[i][1]); OperatorID = Convert.ToInt32(ds.Tables[0].Rows[i][2]); bool check = ValidationCheckForInsertion(OperatorID); if (check == true) { using (i_facility_tamlEntities db1 = new i_facility_tamlEntities()) { if (string.IsNullOrEmpty(Dept) || string.IsNullOrEmpty(OperatorName) || OperatorID == 0) { text = text + htmlerrorMaker(Dept, OperatorName, OperatorID, "Dept, OperatorName or OperatorID cannot be empty/Check the format"); continue; } else { try { tblmp.Dept = Dept.Trim(); tblmp.OperatorName = OperatorName.Trim(); tblmp.OperatorID = OperatorID; tblmp.CreatedBy = Convert.ToInt32(UserId); tblmp.CreatedOn = DateTime.Now; } catch { } } } db.tbloperatordetails.Add(tblmp); try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } else { using (i_facility_tamlEntities db1 = new i_facility_tamlEntities()) { if (string.IsNullOrEmpty(Dept) || string.IsNullOrEmpty(OperatorName) || OperatorID == 0) { text = text + htmlerrorMaker(Dept, OperatorName, OperatorID, "Dept, OperatorName or OperatorID cannot be empty/Check the format"); continue; } else { var OPTDet = db.tbloperatordetails.Where(m => m.isDeleted == 0 && m.OperatorID == OperatorID).FirstOrDefault(); OPTDet.isDeleted = 1; db.Entry(OPTDet).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); try { tblmp.Dept = Dept.Trim(); tblmp.OperatorName = OperatorName.Trim(); tblmp.OperatorID = OperatorID; tblmp.CreatedBy = Convert.ToInt32(UserId); tblmp.CreatedOn = DateTime.Now; } catch { } } } db.tbloperatordetails.Add(tblmp); try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } } #endregion } else if (UploadType == "OverWrite") // Delete Duplicate and Insert New. // if not Duplicate insert that { #region for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tbloperatordetail tblmp = new tbloperatordetail(); String Username = Session["Username"].ToString(); tblmp.CreatedBy = Convert.ToInt32(Session["UserId"]); tblmp.CreatedOn = DateTime.Now; tblmp.isDeleted = 0; string Dept = null, OperatorName = null; int OperatorID = 0; Dept = Convert.ToString(ds.Tables[0].Rows[i][0]); OperatorName = Convert.ToString(ds.Tables[0].Rows[i][1]); OperatorID = Convert.ToInt32(ds.Tables[0].Rows[i][2]); bool check = ValidationCheckForInsertion(OperatorID); if (check == true) { using (i_facility_tamlEntities db1 = new i_facility_tamlEntities()) { if (string.IsNullOrEmpty(Dept) || string.IsNullOrEmpty(OperatorName) || OperatorID == 0) { text = text + htmlerrorMaker(Dept, OperatorName, OperatorID, "Dept, OperatorName or OperatorID cannot be empty/Check the format"); continue; } else { try { tblmp.Dept = Dept.Trim(); tblmp.OperatorName = OperatorName.Trim(); tblmp.OperatorID = OperatorID; tblmp.CreatedBy = Convert.ToInt32(UserId); tblmp.CreatedOn = DateTime.Now; } catch { } } } db.tbloperatordetails.Add(tblmp); try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } else { var OPTDet = db.tbloperatordetails.Where(m => m.isDeleted == 0 && m.OperatorID == OperatorID).FirstOrDefault(); using (i_facility_tamlEntities db1 = new i_facility_tamlEntities()) { if (string.IsNullOrEmpty(Dept) || string.IsNullOrEmpty(OperatorName) || OperatorID == 0) { text = text + htmlerrorMaker(Dept, OperatorName, OperatorID, "Dept, OperatorName or OperatorID cannot be empty/Check the format"); continue; } else { try { OPTDet.Dept = Dept.Trim(); OPTDet.OperatorName = OperatorName.Trim(); OPTDet.ModifiedBy = Convert.ToInt32(UserId); OPTDet.ModifiedOn = DateTime.Now; db.Entry(OPTDet).State = System.Data.Entity.EntityState.Modified; } catch { } } } //db.tbloperatordetails.Add(OPTDet); try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } } #endregion } //TempData["txtShow"] = text; //// ViewBag.text = text; //Session["PartNo"] = ErrorMsg; } //return RedirectToAction("Index", "MasterParts"); return(RedirectToAction("Index", "OperatorModule")); }
public ActionResult Edit(IEnumerable <tblshiftdetail> tblp, int ShiftMethod = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); int UserID = Convert.ToInt32(Session["UserID"]); var shiftmethodiddata = db.tblshiftmethods.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).SingleOrDefault(); int noofshifts = shiftmethodiddata.NoOfShifts; int rowscount = 0; //insert isedited and other details into old rows and insert the new rows. var shiftDetailsData = db.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).ToList(); //check if shift method is in use or was used and now its being modified. ShiftDetails sd = new ShiftDetails(); int shiftmethodid = Convert.ToInt32(ShiftMethod); bool tick = sd.IsThisShiftMethodIsInActionOrEnded(shiftmethodid); try { foreach (var shift in tblp) { if (rowscount < noofshifts) { using (i_facility_tamlEntities db3 = new i_facility_tamlEntities()) { // calculate duration int duration = 0; string starttimestring = "2016-06-02" + " " + shift.ShiftStartTime; DateTime starttimedatetime = Convert.ToDateTime(starttimestring); string endtimestring = null; TimeSpan tsStart = (System.TimeSpan)shift.ShiftStartTime; TimeSpan tsEnd = (System.TimeSpan)shift.ShiftEndTime; int result = TimeSpan.Compare(tsStart, tsEnd); if (result < 0) { endtimestring = "2016-06-02" + " " + shift.ShiftEndTime; } else if (result > 0) { endtimestring = "2016-06-03" + " " + shift.ShiftEndTime; shift.NextDay = 1; } DateTime endtimedatetime = Convert.ToDateTime(endtimestring); TimeSpan ts = endtimedatetime.Subtract(starttimedatetime); duration = Convert.ToInt32(ts.TotalMinutes); if (tick) { //create new object/row int shiftid = shift.ShiftDetailsID; int oldcreatedby = 0; DateTime oldcreatedon = DateTime.Now; using (i_facility_tamlEntities db1 = new i_facility_tamlEntities()) { var getShiftId = db1.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftDetailsID == shiftid).SingleOrDefault(); getShiftId.IsShiftDetailsEdited = 1; getShiftId.IsDeleted = 1; getShiftId.ShiftMethodID = ShiftMethod; getShiftId.ShiftDetailsEditedDate = DateTime.Now; oldcreatedon = Convert.ToDateTime(getShiftId.CreatedOn); oldcreatedby = Convert.ToInt32(getShiftId.CreatedBy); ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName", shift.ShiftMethodID); db1.Entry(getShiftId).State = EntityState.Modified; db1.SaveChanges(); } tblshiftdetail tsd = new tblshiftdetail(); tsd.Duration = duration; tsd.IsDeleted = 0; tsd.CreatedBy = oldcreatedby; tsd.CreatedOn = oldcreatedon; tsd.ModifiedBy = UserID; tsd.ModifiedOn = DateTime.Now; tsd.IsDeleted = 0; tsd.NextDay = shift.NextDay; tsd.ShiftMethodID = ShiftMethod; tsd.ShiftDetailsDesc = shift.ShiftDetailsName; tsd.ShiftDetailsName = shift.ShiftDetailsDesc; tsd.ShiftEndTime = shift.ShiftEndTime; tsd.ShiftStartTime = shift.ShiftStartTime; db.tblshiftdetails.Add(tsd); db.SaveChanges(); } else { //create new object/row shift.ModifiedBy = UserID; shift.ModifiedOn = DateTime.Now; shift.Duration = duration; shift.IsDeleted = 0; shift.ShiftMethodID = ShiftMethod; db3.Entry(shift).State = EntityState.Modified; db3.SaveChanges(); } } } rowscount++; } } catch (Exception e) { ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName", ShiftMethod); return(View(tblp)); } return(RedirectToAction("Index")); }
public ActionResult Index(IList <UnIdentifiedLossCorrection> UnIdentifiedL) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } string MacIDs = null; int i = 0; string CorrectedDate = null; if (UnIdentifiedL != null) { foreach (var row in UnIdentifiedL) { int LossCodeID = 0, LossID = 0; if (row.Level3 != 0) { LossCodeID = Convert.ToInt32(row.Level3); LossID = Convert.ToInt32(row.LossID); } else if (row.Level2 != 0) { LossCodeID = Convert.ToInt32(row.Level2); LossID = Convert.ToInt32(row.LossID); } else if (row.Level1 != 0 && row.Level1 != 999) { LossCodeID = Convert.ToInt32(row.Level1); LossID = Convert.ToInt32(row.LossID); } var LossData = db.tbllossofentries.Find(LossID); if (LossData != null) { //Get MacNumber if it doesn't exist in String(MacIDs) string MacID = Convert.ToString(LossData.MachineID); if (MacIDs == null) { MacIDs += MacID; } else { MacIDs += "," + MacID; } if (i == 0) { CorrectedDate = LossData.CorrectedDate; i++; } LossData.MessageCodeID = LossCodeID; string LossName = Convert.ToString(db.tbllossescodes.Where(m => m.LossCodeID == LossCodeID).Select(m => m.LossCode).FirstOrDefault()); LossData.MessageCode = LossName; LossData.MessageDesc = LossName; db.Entry(LossData).State = EntityState.Modified; db.SaveChanges(); } } } //Delete Data from tblworeport table and tbloeedashboardvariables string StartDate = Convert.ToString(CorrectedDate); MsqlConnection mcDeleteRows = new MsqlConnection(); try { try { DataTable LossCodesData = new DataTable(); string query = @"SELECT Distinct(HMIID) FROM i_facility_taml.dbo.tblworeport WHERE MachineID IN ( " + MacIDs + ") and CorrectedDate = '" + CorrectedDate + "';"; using (MsqlConnection mcLossCodes = new MsqlConnection()) { mcLossCodes.open(); SqlDataAdapter daLossCodesData = new SqlDataAdapter(query, mcLossCodes.msqlConnection); daLossCodesData.Fill(LossCodesData); mcLossCodes.close(); } mcDeleteRows.open(); SqlCommand cmdDeleteWOData = new SqlCommand("DELETE FROM i_facility_taml.dbo.tblworeport WHERE MachineID IN ( " + MacIDs + ") and CorrectedDate = '" + CorrectedDate + "';", mcDeleteRows.msqlConnection); cmdDeleteWOData.ExecuteNonQuery(); for (int l = 0; l < LossCodesData.Rows.Count; l++) { SqlCommand cmdDeleteWOLosses = new SqlCommand("DELETE FROM i_facility_taml.dbo.tblwolossess WHERE HMIID = '" + LossCodesData.Rows[l][0] + "' ", mcDeleteRows.msqlConnection); cmdDeleteWOLosses.ExecuteNonQuery(); } } catch (Exception e) { } try { SqlCommand cmdDeleteOEEData = new SqlCommand("DELETE FROM i_facility_taml.dbo.tbloeedashboardvariables WHERE WCID IN ( " + MacIDs + ") and StartDate = '" + StartDate + "';", mcDeleteRows.msqlConnection); cmdDeleteOEEData.ExecuteNonQuery(); } catch (Exception e) { } } catch (Exception e) { } finally { mcDeleteRows.close(); } //Insert New Data try { CalOEE_WODetails cwod = new CalOEE_WODetails(); cwod.CalculateOEEForYesterday(Convert.ToDateTime(CorrectedDate), Convert.ToDateTime(CorrectedDate)); cwod.CalWODataForYesterday(Convert.ToDateTime(CorrectedDate), Convert.ToDateTime(CorrectedDate)); } catch (Exception e) { } return(RedirectToAction("Index")); }