Beispiel #1
0
        /// <summary>
        /// 根据类别ID获取model
        /// </summary>
        /// <param name="classid">classid</param>
        /// <returns></returns>
        public Mproductclass GetMproductclassByClassid(int classid)
        {
            string sql = "  SELECT classid,supclassid,classname,priority,isDelete,isEffective,great_time,modify_time,imgpath from productclass where 1=1 and classid = ?classid;";

            MySqlParameter[] parameterList = new MySqlParameter[1];
            parameterList[0]       = new MySqlParameter("?classid", MySqlDbType.Int32);
            parameterList[0].Value = classid;

            using (MySqlDataReader sqlDataReader = PKMySqlHelper.ExecuteReader(sql, parameterList))
            {
                if (sqlDataReader != null)
                {
                    if (sqlDataReader.Read())
                    {
                        Mproductclass model = new Mproductclass();
                        model.classid     = sqlDataReader["classid"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["classid"].ToString()) : 0;
                        model.supclassid  = sqlDataReader["supclassid"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["supclassid"].ToString()) : 0;
                        model.priority    = sqlDataReader["priority"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["priority"].ToString()) : 0;
                        model.classname   = sqlDataReader["classname"] != DBNull.Value ? sqlDataReader["classname"].ToString() : string.Empty;
                        model.great_time  = sqlDataReader["great_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["great_time"].ToString()) : DateTime.MinValue;
                        model.modify_time = sqlDataReader["modify_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["modify_time"].ToString()) : DateTime.MinValue;
                        model.imgpath     = sqlDataReader["imgpath"] != DBNull.Value ? sqlDataReader["imgpath"].ToString() : string.Empty;
                        return(model);
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// 新增产品分类方法接口
        /// </summary>
        /// <returns></returns>
        public string AddProductclassMeth(Mproductclass model)
        {
            if (!base.CheckIsLogin())
            {
                return("-1");
            }
            HttpPostedFileBase productimgurl = Request.Files["productimgurl"];

            return(new ProductBus().AddProductclasses(model, productimgurl, Server.MapPath("/")));
        }
Beispiel #3
0
        /// <summary>
        /// 新增产品类别
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddProductclass(Mproductclass model)
        {
            //// sql语句
            string sql = "INSERT INTO productclass(supclassid,classname,priority,isDelete,isEffective,great_time,modify_time,imgpath) " +
                         "VALUES (?supclassid,?classname,?priority,?isDelete,?isEffective,?great_time,?modify_time,?imgpath)";

            List <MySqlParameter> parameterList = new List <MySqlParameter>();
            MySqlParameter        parameter     = new MySqlParameter("?supclassid", MySqlDbType.Int32);

            parameter.Value = model.supclassid;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?classname", MySqlDbType.VarChar, 50);
            parameter.Value = model.classname;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?priority", MySqlDbType.Int32);
            parameter.Value = model.priority;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?isDelete", MySqlDbType.Int16, 1);
            parameter.Value = model.isDelete;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?isEffective", MySqlDbType.Int16, 1);
            parameter.Value = model.isEffective;
            parameterList.Add(parameter);

            DateTime dateTime = System.DateTime.Now;

            parameter       = new MySqlParameter("?great_time", MySqlDbType.DateTime);
            parameter.Value = dateTime;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?modify_time", MySqlDbType.DateTime);
            parameter.Value = dateTime;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?imgpath", MySqlDbType.VarChar, 255);
            parameter.Value = model.imgpath;
            parameterList.Add(parameter);

            //// 执行操作
            return(PKMySqlHelper.ExecuteNonQuery(sql, parameterList.ToArray()) > 0);
        }
Beispiel #4
0
        /// <summary>
        /// 编辑产品类别
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string EditProductclass(Mproductclass model, HttpPostedFileBase productimgurl, string path)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            try
            {
                //// 数据合法性检查
                if (model == null || model.classid < 1 || string.IsNullOrEmpty(model.classname))
                {
                    mwxResult.errmsg = "操作失败,新增数据不能为空!";
                }

                if (productimgurl != null)
                {
                    string savePath = string.Empty;
                    string fileSave = FileOpert.UploadImg(productimgurl, path + "uploadFile\\" + System.DateTime.Now.ToString("yyyy") + "\\", out savePath);
                    if (string.IsNullOrEmpty(fileSave))
                    {
                        model.imgpath = savePath.Replace(path, "");
                    }
                }

                //// 数据落地入库
                if (!new ProductclassService().EditProductclass(model))
                {
                    mwxResult.errmsg = "操作失败";
                }
                else
                {
                    mwxResult.errcode         = 0;
                    mwxResult.errmsg          = "操作成功";
                    CacheData.allProductClass = null;
                }
            }
            catch (Exception ex)
            {
                mwxResult.errmsg = "操作失败:系统异常!";
            }

            return(JsonHelper.GetJson <MwxResult>(mwxResult));
        }
        /// <summary>
        /// 产品类别编辑页面
        /// </summary>
        /// <returns></returns>
        public ActionResult EditProductclass(string classid)
        {
            if (!base.CheckIsLogin())
            {
                return(RedirectToAction("Index", "Login"));
            }

            int id = 0;

            int.TryParse(classid, out id);

            ViewData["AllPersonClass"] = new ProductBus().GetProductclassesBySupclassid(0);
            Mproductclass model = new ProductBus().GetMproductclassById(id);

            if (model == null)
            {
                model = new Mproductclass();
            }
            return(View(model));
        }
Beispiel #6
0
        /// <summary>
        /// 编辑产品类别
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool EditProductclass(Mproductclass model)
        {
            //// sql语句
            string sql = "update  productclass set supclassid=?supclassid, classname=?classname,priority=?priority ,modify_time=?modify_time";

            if (!string.IsNullOrEmpty(model.imgpath))
            {
                sql = sql + ",imgpath=?imgpath ";
            }

            sql = sql + " where classid=?classid;";

            List <MySqlParameter> parameterList = new List <MySqlParameter>();
            MySqlParameter        parameter     = new MySqlParameter("?classid", MySqlDbType.Int32);

            parameter.Value = model.classid;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?supclassid", MySqlDbType.Int32);
            parameter.Value = model.supclassid;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?classname", MySqlDbType.VarChar, 50);
            parameter.Value = model.classname;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?priority", MySqlDbType.Int32);
            parameter.Value = model.priority;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?modify_time", MySqlDbType.DateTime);
            parameter.Value = System.DateTime.Now;
            parameterList.Add(parameter);

            parameter       = new MySqlParameter("?imgpath", MySqlDbType.VarChar, 255);
            parameter.Value = model.imgpath;
            parameterList.Add(parameter);

            //// 执行操作
            return(PKMySqlHelper.ExecuteNonQuery(sql, parameterList.ToArray()) > 0);
        }
Beispiel #7
0
        /// <summary>
        /// 直接获取所有分类
        /// </summary>
        /// <returns></returns>
        public List <Mproductclass> GetMproductclasses(int supclassid)
        {
            string sql = "  SELECT classid,supclassid,classname,priority,isDelete,isEffective,great_time,modify_time,imgpath from productclass where 1=1 ";

            if (supclassid >= 0)
            {
                sql = sql + " and supclassid = ?supclassid ";
            }
            sql = sql + " order by priority asc;";
            MySqlParameter[] parameterList = new MySqlParameter[1];
            parameterList[0]       = new MySqlParameter("?supclassid", MySqlDbType.Int32);
            parameterList[0].Value = supclassid;

            List <Mproductclass> listModel = null;

            using (MySqlDataReader sqlDataReader = PKMySqlHelper.ExecuteReader(sql, parameterList))
            {
                if (sqlDataReader != null)
                {
                    listModel = new List <Mproductclass>();
                    while (sqlDataReader.Read())
                    {
                        Mproductclass model = new Mproductclass();
                        model.classid     = sqlDataReader["classid"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["classid"].ToString()) : 0;
                        model.supclassid  = sqlDataReader["supclassid"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["supclassid"].ToString()) : 0;
                        model.priority    = sqlDataReader["priority"] != DBNull.Value ? Convert.ToInt32(sqlDataReader["priority"].ToString()) : 0;
                        model.classname   = sqlDataReader["classname"] != DBNull.Value ? sqlDataReader["classname"].ToString() : string.Empty;
                        model.great_time  = sqlDataReader["great_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["great_time"].ToString()) : DateTime.MinValue;
                        model.modify_time = sqlDataReader["modify_time"] != DBNull.Value ? Convert.ToDateTime(sqlDataReader["modify_time"].ToString()) : DateTime.MinValue;
                        model.imgpath     = sqlDataReader["imgpath"] != DBNull.Value ? sqlDataReader["imgpath"].ToString() : string.Empty;
                        listModel.Add(model);
                    }
                }
            }

            return(listModel);
        }
Beispiel #8
0
        /// <summary>
        /// 新增产品类别
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string AddProductclasses(Mproductclass model, HttpPostedFileBase productimgurl, string path)
        {
            MwxResult mwxResult = new MwxResult()
            {
                errcode = -1
            };

            try
            {
                //// 数据合法性检查
                if (model == null || string.IsNullOrEmpty(model.classname))
                {
                    mwxResult.errmsg = "操作失败,新增数据不能为空!";
                }

                if (productimgurl == null)
                {
                    mwxResult.errmsg = "图片不能为空!";
                    return(JsonHelper.GetJson <MwxResult>(mwxResult));
                }

                string savePath = string.Empty;

                //// 存图片
                string fileSave = FileOpert.UploadImg(productimgurl, path + "uploadFile\\" + System.DateTime.Now.ToString("yyyy") + "\\", out savePath);
                if (string.IsNullOrEmpty(fileSave))
                {
                    model.imgpath = savePath.Replace(path, "");
                }
                else
                {
                    //// 构建错误信息并返回
                    mwxResult.errmsg = fileSave;
                    return(JsonHelper.GetJson <MwxResult>(mwxResult));
                }

                //// 时间相关参数赋值
                model.great_time  = System.DateTime.Now;
                model.modify_time = model.great_time;
                model.isDelete    = 0;
                model.isEffective = 1;

                //// 数据落地入库
                if (!new ProductclassService().AddProductclass(model))
                {
                    mwxResult.errmsg = "操作失败";
                }
                else
                {
                    mwxResult.errcode         = 0;
                    mwxResult.errmsg          = "操作成功";
                    CacheData.allProductClass = null;
                }
            }
            catch (Exception ex)
            {
                mwxResult.errmsg = "操作失败:系统异常!";
            }

            return(JsonHelper.GetJson <MwxResult>(mwxResult));
        }
 /// <summary>
 /// 编辑产品类别
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool EditProductclass(Mproductclass model)
 {
     return(opertService.EditProductclass(model));
 }
 /// <summary>
 /// 新增产品类别
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool AddProductclass(Mproductclass model)
 {
     return(opertService.AddProductclass(model));
 }