Esempio n. 1
0
        public IHttpActionResult ChangeStaffProductType(int user_id, List <int> product_type)
        {
            try
            {
                if (product_type == null || !product_type.Any())
                {
                    return(Json(new { result = "请求参数错误" }));
                }

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var staff = db.Staff.FirstOrDefault(a => a.id == user_id);
                    if (staff == null)
                    {
                        return(Json(new { result = "员工信息异常" }));
                    }

                    staff.sell_product_type = string.Join(",", product_type);
                    db.Entry(staff).State   = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() > 0)
                    {
                        return(Json(new { result = "操作成功" }));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "操作失败" }));
        }
Esempio n. 2
0
        public IHttpActionResult EditSchedule(int word_time_id, string week, string on_work, string off_work)
        {
            try
            {
                if (string.IsNullOrEmpty(week) || string.IsNullOrEmpty(on_work) || string.IsNullOrEmpty(off_work))
                {
                    return(Json(new { result = "请求参数错误" }));
                }

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var work_time = db.WorkTime.FirstOrDefault(a => a.id == word_time_id);
                    if (work_time == null)
                    {
                        return(Json(new { result = "排班信息异常" }));
                    }

                    work_time.week            = week;
                    work_time.on_work         = on_work;
                    work_time.off_work        = off_work;
                    work_time.update_time     = DateTime.Now;
                    db.Entry(work_time).State = System.Data.Entity.EntityState.Modified;
                    if (db.SaveChanges() < 0)
                    {
                        return(Json(new { result = "修改失败" }));
                    }

                    return(Json(new { result = "修改成功" }));
                }
            }
            catch (Exception ex)
            {
            }
            return(Json(new { result = "系统异常" }));
        }
Esempio n. 3
0
        public IHttpActionResult ChangeStaffLeader(int user_id, int leader_id)
        {
            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var staff = db.Staff.FirstOrDefault(a => a.id == user_id);
                    if (staff == null)
                    {
                        return(Json(new { result = "员工信息不存在" }));
                    }

                    var leader = db.Staff.FirstOrDefault(a => a.id == leader_id);
                    if (leader == null)
                    {
                        return(Json(new { result = "主管信息不存在" }));
                    }

                    staff.leader_id   = leader.id;
                    staff.update_time = DateTime.Now;

                    db.Entry(staff).State = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() > 0)
                    {
                        return(Json(new { result = "操作成功" }));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "操作失败" }));
        }
Esempio n. 4
0
        public IHttpActionResult AddUser(string name, string password, int leader_id, string user_type, decimal salary, string sell_product_type)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    return(Json(new { result = "用户名不能为空" }));
                }

                Enum_User_Type userType;
                bool           convertResult = Enum.TryParse(user_type, out userType);
                if (convertResult == false)
                {
                    return(Json(new { result = "用户类型异常" }));
                }

                Staff user = new Staff();
                user.name              = name;
                user.password          = string.IsNullOrEmpty(password) ? SystemCommon.GetMD5Str(SystemCommon.Default_Password) : SystemCommon.GetMD5Str(password);
                user.leader_id         = leader_id;
                user.user_type         = user_type;
                user.salary            = salary;
                user.sell_product_type = sell_product_type;
                user.create_time       = DateTime.Now;
                user.update_time       = DateTime.Now;

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    db.Entry(user).State = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() < 0)
                    {
                        return(Json(new { result = "用户添加失败" }));
                    }
                }

                return(Json(new { result = "用户添加成功" }));
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }
Esempio n. 5
0
        public JsonResult ChangeStaffLeader(int user_id, int leader_id)
        {
            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var staff = db.Staff.FirstOrDefault(a => a.id == user_id);
                    if (staff == null)
                    {
                        return(Json("员工不存在", JsonRequestBehavior.AllowGet));
                    }

                    var leader = (from a in db.Staff
                                  join b in db.Staff_Auth on a.id equals b.staff_id
                                  select new { a.id, b.sell_product_type }).FirstOrDefault();

                    if (leader == null)
                    {
                        return(Json("主管不存在", JsonRequestBehavior.AllowGet));
                    }

                    Staff_Auth auth = new Staff_Auth();
                    auth.leader_id         = leader.id;
                    auth.staff_id          = staff.id;
                    auth.sell_product_type = leader.sell_product_type.Split(',').FirstOrDefault();
                    auth.create_time       = DateTime.Now;
                    auth.update_time       = DateTime.Now;

                    db.Entry(auth).State = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() > 0)
                    {
                        return(Json("操作成功", JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json("操作失败", JsonRequestBehavior.AllowGet));
        }
Esempio n. 6
0
        public IHttpActionResult AddSchedule(int user_id, string week, string on_work, string off_work)
        {
            try
            {
                if (string.IsNullOrEmpty(week) || string.IsNullOrEmpty(on_work) || string.IsNullOrEmpty(off_work))
                {
                    return(Json(new { result = "请求参数错误" }));
                }

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var staff = db.Staff.FirstOrDefault(a => a.id == user_id);
                    if (staff == null)
                    {
                        return(Json(new { result = "员工信息异常" }));
                    }

                    WorkTime work_time = new WorkTime();
                    work_time.staff_id        = staff.id;
                    work_time.staff_name      = staff.name;
                    work_time.week            = week;
                    work_time.on_work         = on_work;
                    work_time.off_work        = off_work;
                    work_time.create_time     = DateTime.Now;
                    work_time.update_time     = DateTime.Now;
                    db.Entry(work_time).State = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() < 0)
                    {
                        return(Json(new { result = "添加失败" }));
                    }

                    return(Json(new { result = "添加成功" }));
                }
            }
            catch (Exception ex)
            {
            }
            return(Json(new { result = "系统异常" }));
        }
Esempio n. 7
0
        public IHttpActionResult ChangeProductExpendRate(string product_id, double rate)
        {
            try
            {
                if (string.IsNullOrEmpty(product_id))
                {
                    return(Json(new { result = "参数错误" }));
                }

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var expend_rate = db.Product_Expend_Rate_Config.FirstOrDefault(a => a.product_id == product_id);
                    if (expend_rate == null)
                    {
                        var product_info = db.Product.FirstOrDefault(a => a.product_id == product_id);
                        if (product_info == null)
                        {
                            return(Json(new { result = "商品信息异常" }));
                        }

                        expend_rate                  = new Product_Expend_Rate_Config();
                        expend_rate.product_id       = product_info.product_id;
                        expend_rate.product_name     = product_info.product_name;
                        expend_rate.product_type     = product_info.product_type;
                        expend_rate.product_category = product_info.product_category;
                        expend_rate.high_expend_rate = product_info.product_category == (int)Product_Category_Enum.RiPei ? SystemCommon.Ri_Pei_High_Expend_Rate : SystemCommon.No_Ri_Pei_High_Expend_Rate;

                        if (rate > 0)
                        {
                            expend_rate.low_expend_rate = rate;
                        }
                        else
                        {
                            expend_rate.low_expend_rate = product_info.product_category == (int)Product_Category_Enum.RiPei ? SystemCommon.Ri_Pei_Low_Expend_Rate : SystemCommon.No_Ri_Pei_Low_Expend_Rate;
                        }

                        expend_rate.create_time     = DateTime.Now;
                        expend_rate.update_time     = DateTime.Now;
                        db.Entry(expend_rate).State = System.Data.Entity.EntityState.Added;
                        if (db.SaveChanges() < 0)
                        {
                            return(Json(new { result = "设置失败" }));
                        }

                        return(Json(new { result = "设置成功" }));
                    }

                    expend_rate.low_expend_rate = rate;
                    expend_rate.update_time     = DateTime.Now;
                    db.Entry(expend_rate).State = System.Data.Entity.EntityState.Modified;
                    if (db.SaveChanges() < 0)
                    {
                        return(Json(new { result = "设置失败" }));
                    }

                    return(Json(new { result = "设置成功" }));
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }