public ActionResult DeleteSkills(int ID)
        {
            M_Skills skill = new M_Skills();

            skill = (from u in db.M_Skills.ToList()
                     where u.ID == ID
                     select u).FirstOrDefault();
            skill.IsDeleted       = true;
            skill.UpdateDate      = DateTime.Now;
            skill.UpdateID        = user.UserName;
            db.Entry(skill).State = EntityState.Modified;
            db.SaveChanges();
            return(Json(new { msg = "Success" }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult UploadImageLogo(int SkillID)
        {
            try
            {
                #region Save to Server
                //bool isSuccess = false;
                //string serverMessage = string.Empty;
                //var fileOne = Request.Files[0] as HttpPostedFileBase;
                //string uploadPath = Server.MapPath(@"~/PictureResources/ProcessLogo/");
                //string newFileOne = Path.Combine(uploadPath, fileOne.FileName);
                //fileOne.SaveAs(newFileOne);
                #endregion
                #region Save to Server
                bool   isSuccess     = false;
                string serverMessage = string.Empty;
                var    fileOne       = Request.Files[0] as HttpPostedFileBase;
                string uploadPath    = Server.MapPath(@"~/PictureResources/ProcessLogo/");
                string newFileOne    = Path.Combine(uploadPath, fileOne.FileName);
                //fileOne.SaveAs(newFileOne);
                //fileOne.SaveAs(HttpContext.Server.MapPath("~/PictureResources/ProcessLogo/") + Path.GetFileName(fileOne.FileName));
                fileOne.SaveAs(HttpContext.Server.MapPath("~/PictureResources/ProcessLogo/") + Path.GetFileName(Regex.Replace(fileOne.FileName, @"\s+", "")));

                #endregion

                #region ImageSet
                M_Skills pack = (from c in db.M_Skills where c.ID == SkillID select c).FirstOrDefault();
                string[] data = fileOne.FileName.Split('\\');
                //pack.SkillLogo = data[data.Length - 1];//fileOne.FileName;
                pack.SkillLogo = Regex.Replace(data[data.Length - 1], @"\s+", "");//fileOne.FileName;

                db.Entry(pack).State = EntityState.Modified;
                db.SaveChanges();
                #endregion
            }
            catch (Exception err)
            {
                Error_Logs error = new Error_Logs();
                error.PageModule = "Master - Skills";
                error.ErrorLog   = err.Message;
                error.DateLog    = DateTime.Now;
                error.Username   = user.UserName;
                db.Error_Logs.Add(error);
                db.SaveChanges();
            }
            return(Json(new { wew = "" }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult EditSkills(M_Skills data)
        {
            try
            {
                M_Skills skill = new M_Skills();
                skill = (from u in db.M_Skills.ToList()
                         where u.ID == data.ID
                         select u).FirstOrDefault();
                skill.Skill = data.Skill;
                skill.Count = data.Count;
                //skill.Status = data.Status;

                skill.UpdateID   = user.UserName;
                skill.UpdateDate = DateTime.Now;

                M_Skills checker = (from c in db.M_Skills
                                    where c.Skill == data.Skill &&
                                    c.Line == data.Line &&
                                    c.Count == data.Count
                                    //&& c.Status == data.Status
                                    && c.IsDeleted == false
                                    select c).FirstOrDefault();
                if (checker == null)
                {
                    db.Entry(skill).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    return(Json(new { msg = "Failed" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception err)
            {
                Error_Logs error = new Error_Logs();
                error.PageModule = "Master - Skills";
                error.ErrorLog   = err.Message;
                error.DateLog    = DateTime.Now;
                error.Username   = user.UserName;
                db.Error_Logs.Add(error);
                db.SaveChanges();
            }

            return(Json(new { msg = "Success" }, JsonRequestBehavior.AllowGet));
        }
 public ActionResult CreateSkills(M_Skills data)
 {
     try
     {
         data.CreateID   = user.UserName;
         data.CreateDate = DateTime.Now;
         data.UpdateID   = user.UserName;
         data.UpdateDate = DateTime.Now;
         data.IsDeleted  = false;
         //data.Status = true;
         M_Skills checker = (from c in db.M_Skills
                             where c.Skill == data.Skill &&
                             c.Line == data.Line
                             //&& c.Status == data.Status
                             && c.IsDeleted == false
                             select c).FirstOrDefault();
         if (checker == null)
         {
             db.M_Skills.Add(data);
             db.SaveChanges();
             return(Json(new { msg = "Success" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { msg = "Failed" }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception err)
     {
         Error_Logs error = new Error_Logs();
         error.PageModule = "Master - Skills";
         error.ErrorLog   = err.Message;
         error.DateLog    = DateTime.Now;
         error.Username   = user.UserName;
         db.Error_Logs.Add(error);
         db.SaveChanges();
         return(Json(new { msg = err.Message }, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult UploadSkills(long LineID)
        {
            var    postedFile = Request.Files[0] as HttpPostedFileBase;
            string filePath   = string.Empty;

            if (postedFile != null)
            {
                string path = Server.MapPath("~/Uploads/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                filePath = path + Path.GetFileName(postedFile.FileName);
                string extension = Path.GetExtension(postedFile.FileName);
                postedFile.SaveAs(filePath);
                string conString = string.Empty;
                switch (extension.ToLower())
                {
                case ".xls":     //Excel 97-03.
                    conString = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
                    break;

                case ".xlsx":     //Excel 07 and above.
                    conString = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
                    break;
                }
                conString = string.Format(conString, filePath);

                using (OleDbConnection connExcel = new OleDbConnection(conString))
                {
                    using (OleDbCommand cmdExcel = new OleDbCommand())
                    {
                        using (OleDbDataAdapter odaExcel = new OleDbDataAdapter())
                        {
                            DataTable dt = new DataTable();
                            cmdExcel.Connection = connExcel;
                            string sheetName = "Process";
                            try
                            {
                                connExcel.Open();

                                cmdExcel.CommandText   = "SELECT Process, IdealManPower FROM [" + sheetName + "$]";//ung * is column name, ung sheetname ay settings
                                odaExcel.SelectCommand = cmdExcel;

                                odaExcel.Fill(dt);
                                connExcel.Close();


                                #region Additional Column
                                DataColumn col_CreateID = new System.Data.DataColumn("CreateID", typeof(System.String));
                                col_CreateID.DefaultValue = user.UserName;
                                dt.Columns.Add(col_CreateID);

                                DataColumn col_CreateDate = new System.Data.DataColumn("CreateDate", typeof(System.DateTime));
                                col_CreateDate.DefaultValue = DateTime.Now;
                                dt.Columns.Add(col_CreateDate);

                                DataColumn col_UpdateID = new System.Data.DataColumn("UpdateID", typeof(System.String));
                                col_UpdateID.DefaultValue = user.UserName;
                                dt.Columns.Add(col_UpdateID);

                                DataColumn col_UpdateDate = new System.Data.DataColumn("UpdateDate", typeof(System.DateTime));
                                col_UpdateDate.DefaultValue = DateTime.Now;
                                dt.Columns.Add(col_UpdateDate);

                                DataColumn Line = new System.Data.DataColumn("Line", typeof(long));
                                Line.DefaultValue = LineID;
                                dt.Columns.Add(Line);

                                DataColumn Status = new System.Data.DataColumn("Status", typeof(bool));
                                Status.DefaultValue = true;
                                dt.Columns.Add(Status);


                                DataColumn IsDeleted = new System.Data.DataColumn("IsDeleted", typeof(bool));
                                IsDeleted.DefaultValue = false;
                                dt.Columns.Add(IsDeleted);
                                #endregion
                            }
                            catch (Exception err)
                            {
                                Error_Logs error = new Error_Logs();
                                error.PageModule = "Master - Process";
                                error.ErrorLog   = err.Message;
                                error.DateLog    = DateTime.Now;
                                error.Username   = user.UserName;
                                db.Error_Logs.Add(error);
                                db.SaveChanges();
                            }

                            try
                            {
                                //string conString2 = ConfigurationManager.ConnectionStrings["Brothers_AMSDB"].ConnectionString;
                                //using (SqlBulkCopy bulk = new SqlBulkCopy(conString2))
                                //{
                                //    bulk.ColumnMappings.Add("Line", "Line");
                                //    bulk.ColumnMappings.Add("Skill", "Skill");
                                //    bulk.ColumnMappings.Add("IdealManPower", "Count");
                                //    bulk.ColumnMappings.Add("IsDeleted", "IsDeleted");
                                //    bulk.ColumnMappings.Add("CreateID", "CreateID");
                                //    bulk.ColumnMappings.Add("CreateDate", "CreateDate");
                                //    bulk.ColumnMappings.Add("UpdateID", "UpdateID");
                                //    bulk.ColumnMappings.Add("UpdateDate", "UpdateDate");
                                //    bulk.DestinationTableName = "M_Skills";
                                //    bulk.WriteToServer(dt);
                                //}
                                for (int x = 0; x < dt.Rows.Count; x++)
                                {
                                    try
                                    {
                                        M_Skills Skilltb = new M_Skills();
                                        Skilltb.Line       = LineID;
                                        Skilltb.Skill      = dt.Rows[x]["Process"].ToString();
                                        Skilltb.Count      = Convert.ToInt32(dt.Rows[x]["IdealManPower"]);
                                        Skilltb.IsDeleted  = false;
                                        Skilltb.CreateDate = DateTime.Now;
                                        Skilltb.CreateID   = user.UserName;
                                        Skilltb.UpdateDate = DateTime.Now;
                                        Skilltb.UpdateID   = user.UserName;

                                        db.M_Skills.Add(Skilltb);
                                        db.SaveChanges();
                                    }
                                    catch (Exception err)
                                    {
                                        Error_Logs error = new Error_Logs();
                                        error.PageModule = "Master - Process";
                                        error.ErrorLog   = err.Message;
                                        error.DateLog    = DateTime.Now;
                                        error.Username   = user.UserName;
                                        db.Error_Logs.Add(error);
                                        db.SaveChanges();
                                    }
                                }



                                db.M_SP_Skillduplicateremover(LineID);
                            }
                            catch (Exception err)
                            {
                                Error_Logs error = new Error_Logs();
                                error.PageModule = "Master - Process";
                                error.ErrorLog   = err.Message;
                                error.DateLog    = DateTime.Now;
                                error.Username   = user.UserName;
                                db.Error_Logs.Add(error);
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }

            return(Json(new { }, JsonRequestBehavior.AllowGet));
        }