Esempio n. 1
0
        public ActionResult Edit(StdToolLife tblmp, int hdnpid = 0)
        {
            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 partno = tblmp.tblStdToolLife.FGCode;
            string opno   = tblmp.tblStdToolLife.OperationNo;
            string ToolNo = tblmp.tblStdToolLife.ToolNo;
            int    mid    = hdnpid;
            bool   check  = ValidationCheckForInsertion(partno, opno, ToolNo, mid);

            if (check == true)
            {
                tblStdToolLife obj = db.tblStdToolLives.Find(mid);
                obj.StdToolLife = tblmp.tblStdToolLife.StdToolLife;
                obj.OperationNo = tblmp.tblStdToolLife.OperationNo;
                obj.ModifiedOn  = DateTime.Now;;
                obj.ModifiedBy  = UserID;
                obj.FGCode      = tblmp.tblStdToolLife.FGCode;
                obj.ToolNo      = tblmp.tblStdToolLife.ToolNo;
                obj.ToolName    = tblmp.tblStdToolLife.ToolName;
                obj.CTCode      = tblmp.tblStdToolLife.CTCode;
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        // GET: ToolLifeManagement
        public ActionResult Index()
        {
            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 Username = Session["Username"].ToString();

            StdToolLife           STL      = new StdToolLife();
            tblStdToolLife        tstl     = new tblStdToolLife();
            List <tblStdToolLife> tstlList = new List <tblStdToolLife>();

            tstlList = db.tblStdToolLives.Where(m => m.IsDeleted == false).ToList();
            STL.tblStdToolLifeList = tstlList;
            return(View(STL));
        }
Esempio n. 3
0
        public ActionResult Delete(int id)
        {
            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         Username = Session["Username"].ToString();
            tblStdToolLife tblmp    = db.tblStdToolLives.Find(id);

            tblmp.IsDeleted       = true;
            tblmp.ModifiedBy      = UserID;
            tblmp.ModifiedOn      = DateTime.Now;
            db.Entry(tblmp).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        //public ActionResult ImportMasterPartsstsw(HttpPostedFileBase file, string UploadType)
        public ActionResult ImportToolLifeData(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++)
                    {
                        tblStdToolLife tblmp    = new tblStdToolLife();
                        String         Username = Session["Username"].ToString();
                        tblmp.CreatedBy = Convert.ToInt32(Session["UserId"]);
                        tblmp.CreatedOn = DateTime.Now;
                        tblmp.IsDeleted = false;

                        string PartName = null, OpNo = null, ToolNo = null, CTCode = null, ToolName = null, StdTooolLife = null;
                        PartName     = Convert.ToString(ds.Tables[0].Rows[i][0]);
                        OpNo         = Convert.ToString(ds.Tables[0].Rows[i][1]);
                        ToolNo       = Convert.ToString(ds.Tables[0].Rows[i][2]);
                        CTCode       = Convert.ToString(ds.Tables[0].Rows[i][3]);
                        ToolName     = Convert.ToString(ds.Tables[0].Rows[i][4]);
                        StdTooolLife = Convert.ToString(ds.Tables[0].Rows[i][5]);

                        bool check = ValidationCheckForInsertion(PartName, OpNo, ToolNo);
                        if (check == true)
                        {
                            using (i_facility_unimechEntities db1 = new i_facility_unimechEntities())
                            {
                                if (string.IsNullOrEmpty(PartName) || string.IsNullOrEmpty(OpNo) || string.IsNullOrEmpty(ToolNo) || string.IsNullOrEmpty(CTCode) || string.IsNullOrEmpty(StdTooolLife))
                                {
                                    text = text + htmlerrorMaker(PartName, OpNo, "FGCode or OpNo cannot be empty/Check the format");
                                    continue;
                                }
                                else
                                {
                                    try
                                    {
                                        tblmp.FGCode      = PartName.Trim();
                                        tblmp.OperationNo = OpNo.Trim();
                                        tblmp.ToolNo      = ToolNo.Trim();
                                        tblmp.CTCode      = CTCode.Trim();
                                        tblmp.ToolName    = ToolName.Trim();
                                        tblmp.StdToolLife = Convert.ToInt32(StdTooolLife.Trim());
                                        tblmp.CreatedBy   = Convert.ToInt32(UserId);
                                        tblmp.CreatedOn   = DateTime.Now;
                                    }
                                    catch {
                                    }
                                }
                            }
                            //check for dup and delete previous one.
                            var Dupdata = db.tblStdToolLives.Where(m => m.FGCode == PartName && m.OperationNo == OpNo && m.ToolNo == ToolNo && m.IsDeleted == false).FirstOrDefault();
                            if (Dupdata != null)
                            {
                                Dupdata.IsDeleted       = true;
                                Dupdata.ModifiedOn      = DateTime.Now;
                                Dupdata.ModifiedBy      = Convert.ToInt32(UserId);
                                db.Entry(Dupdata).State = System.Data.Entity.EntityState.Modified;
                                db.SaveChanges();
                            }

                            db.tblStdToolLives.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") // OverWrite Existing Values
                {
                    #region
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        tblStdToolLife tblmp    = new tblStdToolLife();
                        String         Username = Session["Username"].ToString();
                        tblmp.CreatedBy = Convert.ToInt32(Session["UserId"]);
                        tblmp.CreatedOn = DateTime.Now;
                        tblmp.IsDeleted = false;

                        string PartName = null, OpNo = null, ToolNo = null, CTCode = null, ToolName = null, StdTooolLife = null;
                        PartName     = Convert.ToString(ds.Tables[0].Rows[i][0]);
                        OpNo         = Convert.ToString(ds.Tables[0].Rows[i][1]);
                        ToolNo       = Convert.ToString(ds.Tables[0].Rows[i][2]);
                        CTCode       = Convert.ToString(ds.Tables[0].Rows[i][3]);
                        ToolName     = Convert.ToString(ds.Tables[0].Rows[i][4]);
                        StdTooolLife = Convert.ToString(ds.Tables[0].Rows[i][5]);

                        DateTime createdOn = DateTime.Now;

                        if (string.IsNullOrEmpty(PartName) || string.IsNullOrEmpty(OpNo) || string.IsNullOrEmpty(ToolNo) || string.IsNullOrEmpty(CTCode) || string.IsNullOrEmpty(StdTooolLife))
                        {
                            text = text + htmlerrorMaker(PartName, OpNo, "FGCode or OpNo cannot be empty/Check the format");
                            continue;
                        }
                        else
                        {
                            tblmp.FGCode      = PartName.Trim();
                            tblmp.OperationNo = OpNo.Trim();
                            tblmp.ToolNo      = ToolNo.Trim();
                            tblmp.CTCode      = CTCode.Trim();
                            tblmp.ToolName    = ToolName.Trim();
                            tblmp.StdToolLife = Convert.ToInt32(StdTooolLife.Trim());
                            tblmp.CreatedBy   = Convert.ToInt32(UserId);
                            tblmp.CreatedOn   = DateTime.Now;
                        }

                        var MasterStdPWTData = db.tblStdToolLives.Where(m => m.FGCode == PartName && m.OperationNo == OpNo && m.ToolNo == ToolNo && m.IsDeleted == false).FirstOrDefault();
                        if (MasterStdPWTData == null)
                        {
                            db.tblStdToolLives.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
                        {
                            MasterStdPWTData.ModifiedBy      = Convert.ToInt32(Session["UserId"]);
                            MasterStdPWTData.ModifiedOn      = DateTime.Now;
                            MasterStdPWTData.IsDeleted       = true;
                            db.Entry(MasterStdPWTData).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            db.tblStdToolLives.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
                }
                TempData["txtShow"] = text;
                // ViewBag.text = text;
                Session["PartNo"] = ErrorMsg;
            }

            //return RedirectToAction("Index", "MasterParts");
            return(RedirectToAction("Index", "ToolLifeManagement"));
        }