Пример #1
0
        public ActionResult EditCode(mCode code)
        {
            try
            {
                mCode codes = new mCode();
                codes = (from u in db.mCodes.ToList()
                         where u.Code == code.Code
                         select u).FirstOrDefault();
                codes.CodeName        = code.CodeName;
                codes.CodeDescription = code.CodeDescription;

                codes.Update_User = "******";
                codes.Update_Date = DateTime.Now;

                mCode checker = (from c in db.mCodes
                                 where c.CodeDescription == code.CodeDescription &&
                                 c.CodeName == code.CodeName &&
                                 c.Is_Deleted == false
                                 select c).FirstOrDefault();
                if (checker == null)
                {
                    db.Entry(codes).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    return(Json(new { result = "failed" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception err) { }

            return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult DeleteCode(string Code)
        {
            mCode code = new mCode();

            code = (from u in db.mCodes.ToList()
                    where u.Code == Code
                    select u).FirstOrDefault();
            code.Is_Deleted      = true;
            code.Update_Date     = DateTime.Now;
            code.Update_User     = user.UserID;
            db.Entry(code).State = EntityState.Modified;
            db.SaveChanges();
            return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet));
        }
        private void loadStages()
        {
            this.Stage.Items.Insert(0, "SELECT STAGE");
            this.Stage.SelectedIndex = 0;
            List <mCode> stageNameList = new List <mCode>();

            stageNameList = (from c in db.mCodes where c.CodeType.ToUpper().Contains("STAGE") && c.IsDeleted == false select c).ToList();

            foreach (object o in stageNameList)
            {
                mCode stage = (mCode)o;
                this.Stage.Items.Add(stage.CodeName);
            }
        }
Пример #4
0
        public ActionResult CreateCode(mCode code, string cc)
        {
            string gencode     = string.Empty;
            string lastgencode = (from u in db.mCodes.ToList()
                                  .Where(u => u.Code.Contains(cc))
                                  orderby u.Code descending
                                  select u.Code).FirstOrDefault();

            if (lastgencode == null)
            {
                switch (cc)
                {
                case "STC":
                    gencode = "STC0001";
                    break;

                case "INC":
                    gencode = "INC0001";
                    break;

                case "INS":
                    gencode = "INS0001";
                    break;

                case "CAC":
                    gencode = "CAC0001";
                    break;

                case "CLS":
                    gencode = "CLS0001";
                    break;

                case "OST":
                    gencode = "OST0001";
                    break;

                case "STU":
                    gencode = "STU0001";
                    break;

                case "OBC":
                    gencode = "OBC0001";
                    break;

                case "OBT":
                    gencode = "OBT0001";
                    break;

                case "OWN":
                    gencode = "OWN0001";
                    break;

                case "CAP":
                    gencode = "CAP0001";
                    break;
                }
            }
            else
            {
                gencode = lastgencode.Substring(3);
                int upId = Convert.ToInt32(gencode.TrimStart(new char[] { '0' })) + 1;
                gencode = string.Format(cc + "{0}", upId.ToString().PadLeft(4, '0'));
            }


            code.Code        = gencode;
            code.Is_Deleted  = false;
            code.Create_Date = DateTime.Now;
            code.Create_User = user.UserID;
            code.Update_Date = DateTime.Now;
            code.Update_User = user.UserID;


            mCode checker = (from c in db.mCodes
                             where c.Code == code.Code &&
                             c.CodeDescription == code.CodeDescription &&
                             c.Is_Deleted == false
                             select c).FirstOrDefault();

            if (checker == null)
            {
                try
                {
                    db.mCodes.Add(code);
                    db.SaveChanges();
                }
                catch (Exception err) { }
            }
            else
            {
                return(Json(new { result = "failed" }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new { result = "success" }, JsonRequestBehavior.AllowGet));
        }