예제 #1
0
        private bool DoEdit(int _id)
        {
            bool result = false;

            BLL.express   bll   = new BLL.express();
            Model.express model = bll.GetModel(_id);

            model.title        = txtTitle.Text.Trim();
            model.express_code = txtExpressCode.Text.Trim();
            model.express_fee  = Utils.StrToDecimal(txtExpressFee.Text.Trim(), 0);
            model.website      = txtWebSite.Text.Trim();
            model.remark       = Utils.ToHtml(txtRemark.Text);
            if (cbIsLock.Checked == true)
            {
                model.is_lock = 0;
            }
            else
            {
                model.is_lock = 1;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            if (bll.Update(model))
            {
                AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "修改配送方式:" + model.title); //记录日志
                result = true;
            }

            return(result);
        }
예제 #2
0
파일: express.cs 프로젝트: wslyzhh/kuaisitu
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.express GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder();

            Model.express model = new Model.express();
            //利用反射获得属性的所有公共属性
            PropertyInfo[] pros = model.GetType().GetProperties();
            foreach (PropertyInfo p in pros)
            {
                str1.Append(p.Name + ",");//拼接字段
            }
            strSql.Append("select top 1 " + str1.ToString().Trim(','));
            strSql.Append(" from " + databaseprefix + "express");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;
            DataTable dt = DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0];

            if (dt.Rows.Count > 0)
            {
                return(DataRowToModel(dt.Rows[0]));
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
파일: express.cs 프로젝트: wslyzhh/kuaisitu
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.express model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder();

            //利用反射获得属性的所有公共属性
            PropertyInfo[]      pros  = model.GetType().GetProperties();
            List <SqlParameter> paras = new List <SqlParameter>();

            strSql.Append("update  " + databaseprefix + "express set ");
            foreach (PropertyInfo pi in pros)
            {
                //如果不是主键则追加sql字符串
                if (!pi.Name.Equals("id"))
                {
                    //判断属性值是否为空
                    if (pi.GetValue(model, null) != null && !pi.GetValue(model, null).ToString().Equals(""))
                    {
                        str1.Append(pi.Name + "=@" + pi.Name + ",");                          //声明参数
                        paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值
                    }
                }
            }
            strSql.Append(str1.ToString().Trim(','));
            strSql.Append(" where id=@id ");
            paras.Add(new SqlParameter("@id", model.id));
            return(DbHelperSQL.ExecuteSql(strSql.ToString(), paras.ToArray()) > 0);
        }
예제 #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.express GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 id,title,express_code,express_fee,website,remark,sort_id,is_lock");
            strSql.Append(" from " + databaseprefix + "express");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.express model = new Model.express();
            DataSet       ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
        private bool DoAdd()
        {
            Model.express model = new Model.express();
            BLL.express bll = new BLL.express();
            Model.wx_userweixin weixin = GetWeiXinCode();
            model.title = txtTitle.Text.Trim();
            model.express_code = txtExpressCode.Text.Trim();
            model.express_fee = Utils.StrToDecimal(txtExpressFee.Text.Trim(), 0);
            model.website = txtWebSite.Text.Trim();
            model.remark = Utils.ToHtml(txtRemark.Text);
            model.wid = weixin.id;
            if (cbIsLock.Checked == true)
            {
                model.is_lock = 0;
            }
            else
            {
                model.is_lock = 1;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            if (bll.Add(model) > 0)
            {
                AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加配送方式:" + model.title); //记录日志
                return true;
            }
            return false;
        }
예제 #6
0
        private bool DoAdd()
        {
            Model.express       model  = new Model.express();
            BLL.express         bll    = new BLL.express();
            Model.wx_userweixin weixin = GetWeiXinCode();
            model.title        = txtTitle.Text.Trim();
            model.express_code = txtExpressCode.Text.Trim();
            model.express_fee  = Utils.StrToDecimal(txtExpressFee.Text.Trim(), 0);
            model.website      = txtWebSite.Text.Trim();
            model.remark       = Utils.ToHtml(txtRemark.Text);
            model.wid          = weixin.id;
            if (cbIsLock.Checked == true)
            {
                model.is_lock = 0;
            }
            else
            {
                model.is_lock = 1;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            if (bll.Add(model) > 0)
            {
                AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加配送方式:" + model.title); //记录日志
                return(true);
            }
            return(false);
        }
예제 #7
0
        private bool DoAdd()
        {
            Model.express model = new Model.express();
            BLL.express   bll   = new BLL.express();

            model.title        = txtTitle.Text.Trim();
            model.express_code = txtExpressCode.Text.Trim();
            model.express_fee  = Vincent._DTcms.Utils.StrToDecimal(txtExpressFee.Text.Trim(), 0);
            model.img_url      = txtImgUrl.Text;
            model.website      = txtWebSite.Text.Trim();
            model.remark       = Vincent._DTcms.Utils.ToHtml(txtRemark.Text);
            if (cbIsLock.Checked == true)
            {
                model.is_lock = 0;
            }
            else
            {
                model.is_lock = 1;
            }
            model.sort_id = Vincent._DTcms.Utils.StrToInt(txtSortId.Text.Trim(), 99);

            if (bll.Add(model) > 0)
            {
                AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Add.ToString(), "添加配送方式:" + model.title); //记录日志
                return(true);
            }
            return(false);
        }
예제 #8
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.express GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,title,express_code,express_fee,website,remark,sort_id,is_lock,img_url,dealer_id from " + databaseprefix + "express ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.express model = new Model.express();
            DataSet       ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.title        = ds.Tables[0].Rows[0]["title"].ToString();
                model.express_code = ds.Tables[0].Rows[0]["express_code"].ToString();
                if (ds.Tables[0].Rows[0]["express_fee"].ToString() != "")
                {
                    model.express_fee = decimal.Parse(ds.Tables[0].Rows[0]["express_fee"].ToString());
                }
                model.website = ds.Tables[0].Rows[0]["website"].ToString();
                model.remark  = ds.Tables[0].Rows[0]["remark"].ToString();
                if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["is_lock"].ToString() != "")
                {
                    model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString());
                }
                if (ds.Tables[0].Rows[0]["img_url"].ToString() != "")
                {
                    model.img_url = ds.Tables[0].Rows[0]["img_url"].ToString();
                }
                if (ds.Tables[0].Rows[0]["dealer_id"].ToString() != "")
                {
                    model.dealer_id = int.Parse(ds.Tables[0].Rows[0]["dealer_id"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
예제 #9
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.express model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "express set ");
            strSql.Append("title=@title,");
            strSql.Append("express_code=@express_code,");
            strSql.Append("express_fee=@express_fee,");
            strSql.Append("website=@website,");
            strSql.Append("remark=@remark,");
            strSql.Append("sort_id=@sort_id,");
            strSql.Append("is_lock=@is_lock,");
            strSql.Append("img_url=@img_url,");
            strSql.Append("dealer_id=@dealer_id");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",        SqlDbType.NVarChar, 100),
                new SqlParameter("@express_code", SqlDbType.NVarChar, 100),
                new SqlParameter("@express_fee",  SqlDbType.Decimal,    5),
                new SqlParameter("@website",      SqlDbType.NVarChar, 255),
                new SqlParameter("@remark",       SqlDbType.NText),
                new SqlParameter("@sort_id",      SqlDbType.Int,        4),
                new SqlParameter("@is_lock",      SqlDbType.TinyInt,    1),
                new SqlParameter("@id",           SqlDbType.Int,        4),
                new SqlParameter("@img_url",      SqlDbType.NVarChar, 100),
                new SqlParameter("@dealer_id",    SqlDbType.Int, 10)
            };
            parameters[0].Value = model.title;
            parameters[1].Value = model.express_code;
            parameters[2].Value = model.express_fee;
            parameters[3].Value = model.website;
            parameters[4].Value = model.remark;
            parameters[5].Value = model.sort_id;
            parameters[6].Value = model.is_lock;
            parameters[7].Value = model.id;
            parameters[8].Value = model.img_url;
            parameters[9].Value = model.dealer_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #10
0
파일: express.cs 프로젝트: WayLeeLi/Tea
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.express DataRowToModel(DataRow row)
 {
     Model.express model = new Model.express();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["title"] != null)
         {
             model.title = row["title"].ToString();
         }
         if (row["express_code"] != null)
         {
             model.express_code = row["express_code"].ToString();
         }
         if (row["express_fee"] != null && row["express_fee"].ToString() != "")
         {
             model.express_fee = decimal.Parse(row["express_fee"].ToString());
         }
         if (row["website"] != null)
         {
             model.website = row["website"].ToString();
         }
         if (row["remark"] != null)
         {
             model.remark = row["remark"].ToString();
         }
         if (row["sort_id"] != null && row["sort_id"].ToString() != "")
         {
             model.sort_id = int.Parse(row["sort_id"].ToString());
         }
         if (row["is_lock"] != null && row["is_lock"].ToString() != "")
         {
             model.is_lock = int.Parse(row["is_lock"].ToString());
         }
         if (row["company"] != null && row["company"].ToString() != "")
         {
             model.company = int.Parse(row["company"].ToString());
         }
         if (row["maxmoney"] != null && row["maxmoney"].ToString() != "")
         {
             model.maxmoney = decimal.Parse(row["maxmoney"].ToString());
         }
     }
     return(model);
 }
예제 #11
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.express model)
        {
            int newId;

            using (OleDbConnection conn = new OleDbConnection(DbHelperOleDb.connectionString))
            {
                conn.Open();
                using (OleDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into " + databaseprefix + "express(");
                        strSql.Append("title,express_code,express_fee,website,remark,sort_id,is_lock)");
                        strSql.Append(" values (");
                        strSql.Append("@title,@express_code,@express_fee,@website,@remark,@sort_id,@is_lock)");
                        OleDbParameter[] parameters =
                        {
                            new OleDbParameter("@title",        OleDbType.VarChar,  100),
                            new OleDbParameter("@express_code", OleDbType.VarChar,  100),
                            new OleDbParameter("@express_fee",  OleDbType.Decimal,    5),
                            new OleDbParameter("@website",      OleDbType.VarChar,  255),
                            new OleDbParameter("@remark",       OleDbType.VarChar),
                            new OleDbParameter("@sort_id",      OleDbType.Integer,    4),
                            new OleDbParameter("@is_lock",      OleDbType.Integer, 4)
                        };
                        parameters[0].Value = model.title;
                        parameters[1].Value = model.express_code;
                        parameters[2].Value = model.express_fee;
                        parameters[3].Value = model.website;
                        parameters[4].Value = model.remark;
                        parameters[5].Value = model.sort_id;
                        parameters[6].Value = model.is_lock;
                        DbHelperOleDb.ExecuteSql(conn, trans, strSql.ToString(), parameters);
                        //取得新插入的ID
                        newId = GetMaxId(conn, trans);
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(-1);
                    }
                }
            }
            return(newId);
        }
예제 #12
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.express model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "express set ");
            strSql.Append("title=@title,");
            strSql.Append("express_code=@express_code,");
            strSql.Append("express_fee=@express_fee,");
            strSql.Append("website=@website,");
            strSql.Append("remark=@remark,");
            strSql.Append("sort_id=@sort_id,");
            strSql.Append("is_lock=@is_lock");
            strSql.Append(" where id=@id");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@title",        OleDbType.VarChar,  100),
                new OleDbParameter("@express_code", OleDbType.VarChar,  100),
                new OleDbParameter("@express_fee",  OleDbType.Decimal,    5),
                new OleDbParameter("@website",      OleDbType.VarChar,  255),
                new OleDbParameter("@remark",       OleDbType.VarChar),
                new OleDbParameter("@sort_id",      OleDbType.Integer,    4),
                new OleDbParameter("@is_lock",      OleDbType.Integer,    4),
                new OleDbParameter("@id",           OleDbType.Integer, 4)
            };
            parameters[0].Value = model.title;
            parameters[1].Value = model.express_code;
            parameters[2].Value = model.express_fee;
            parameters[3].Value = model.website;
            parameters[4].Value = model.remark;
            parameters[5].Value = model.sort_id;
            parameters[6].Value = model.is_lock;
            parameters[7].Value = model.id;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #13
0
파일: express.cs 프로젝트: wslyzhh/kuaisitu
 /// <summary>
 /// 将对象转换实体
 /// </summary>
 public Model.express DataRowToModel(DataRow row)
 {
     Model.express model = new Model.express();
     if (row != null)
     {
         //利用反射获得属性的所有公共属性
         Type modelType = model.GetType();
         for (int i = 0; i < row.Table.Columns.Count; i++)
         {
             //查找实体是否存在列表相同的公共属性
             PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
             if (proInfo != null && row[i] != DBNull.Value)
             {
                 proInfo.SetValue(model, row[i], null);//用索引值设置属性值
             }
         }
     }
     return(model);
 }
예제 #14
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.express model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "express(");
            strSql.Append("title,express_code,express_fee,website,remark,sort_id,is_lock,img_url,dealer_id)");
            strSql.Append(" values (");
            strSql.Append("@title,@express_code,@express_fee,@website,@remark,@sort_id,@is_lock,@img_url,@dealer_id)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",        SqlDbType.NVarChar, 100),
                new SqlParameter("@express_code", SqlDbType.NVarChar, 100),
                new SqlParameter("@express_fee",  SqlDbType.Decimal,    5),
                new SqlParameter("@website",      SqlDbType.NVarChar, 255),
                new SqlParameter("@remark",       SqlDbType.NText),
                new SqlParameter("@sort_id",      SqlDbType.Int,        4),
                new SqlParameter("@is_lock",      SqlDbType.TinyInt,    1),
                new SqlParameter("@img_url",      SqlDbType.NVarChar, 100),
                new SqlParameter("@dealer_id",    SqlDbType.Int, 10)
            };
            parameters[0].Value = model.title;
            parameters[1].Value = model.express_code;
            parameters[2].Value = model.express_fee;
            parameters[3].Value = model.website;
            parameters[4].Value = model.remark;
            parameters[5].Value = model.sort_id;
            parameters[6].Value = model.is_lock;
            parameters[7].Value = model.img_url;
            parameters[8].Value = model.dealer_id;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #15
0
        private void ShowInfo(int _id)
        {
            BLL.express   bll   = new BLL.express();
            Model.express model = bll.GetModel(_id);

            txtTitle.Text       = model.title;
            txtExpressCode.Text = model.express_code;
            txtExpressFee.Text  = model.express_fee.ToString();
            txtWebSite.Text     = model.website;
            txtRemark.Text      = Utils.ToTxt(model.remark);
            if (model.is_lock == 0)
            {
                cbIsLock.Checked = true;
            }
            else
            {
                cbIsLock.Checked = false;
            }
            txtSortId.Text = model.sort_id.ToString();
        }
예제 #16
0
파일: express.cs 프로젝트: wslyzhh/kuaisitu
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.express model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder(); //数据字段
            StringBuilder str2   = new StringBuilder(); //数据参数

            //利用反射获得属性的所有公共属性
            PropertyInfo[]      pros  = model.GetType().GetProperties();
            List <SqlParameter> paras = new List <SqlParameter>();

            strSql.Append("insert into " + databaseprefix + "express(");
            foreach (PropertyInfo pi in pros)
            {
                //如果不是主键则追加sql字符串
                if (!pi.Name.Equals("id"))
                {
                    //判断属性值是否为空
                    if (pi.GetValue(model, null) != null && !pi.GetValue(model, null).ToString().Equals(""))
                    {
                        str1.Append(pi.Name + ",");                                           //拼接字段
                        str2.Append("@" + pi.Name + ",");                                     //声明参数
                        paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值
                    }
                }
            }
            strSql.Append(str1.ToString().Trim(','));
            strSql.Append(") values (");
            strSql.Append(str2.ToString().Trim(','));
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY;");
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), paras.ToArray());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #17
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.express DataRowToModel(DataRow row)
 {
     Model.express model = new Model.express();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["title"] != null)
         {
             model.title = row["title"].ToString();
         }
         if (row["express_code"] != null)
         {
             model.express_code = row["express_code"].ToString();
         }
         if (row["express_fee"] != null && row["express_fee"].ToString() != "")
         {
             model.express_fee = decimal.Parse(row["express_fee"].ToString());
         }
         if (row["website"] != null)
         {
             model.website = row["website"].ToString();
         }
         if (row["remark"] != null)
         {
             model.remark = row["remark"].ToString();
         }
         if (row["sort_id"] != null && row["sort_id"].ToString() != "")
         {
             model.sort_id = int.Parse(row["sort_id"].ToString());
         }
         if (row["is_lock"] != null && row["is_lock"].ToString() != "")
         {
             model.is_lock = int.Parse(row["is_lock"].ToString());
         }
     }
     return model;
 }
예제 #18
0
 /// <summary>
 /// OnInit事件,检查用户是否登录
 /// </summary>
 void UserPage_Init(object sender, EventArgs e)
 {
     if (!IsUserLogin())
     {
         //跳转URL
         HttpContext.Current.Response.Redirect(linkurl("login"));
         return;
     }
     //获得登录用户信息
     userModel  = GetUserInfo();
     groupModel = new BLL.user_groups().GetModel(userModel.group_id);
     if (groupModel == null)
     {
         groupModel = new Model.user_groups();
     }
     expressModel = new BLL.express().GetModel(userModel.express_id);
     if (expressModel == null)
     {
         expressModel = new Model.express();
     }
     InitPage();
 }
예제 #19
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.express GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 id,title,express_code,express_fee,website,[remark],sort_id,is_lock");
            strSql.Append(" from " + databaseprefix + "express");
            strSql.Append(" where id=@id");
            OleDbParameter[] parameters = {
                    new OleDbParameter("@id", OleDbType.Integer,4)};
            parameters[0].Value = id;

            Model.express model = new Model.express();
            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
예제 #20
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.express model)
 {
     return(dal.Update(model));
 }
예제 #21
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.express model)
 {
     return(dal.Add(model));
 }
예제 #22
0
        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public Model.express GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,title,express_code,express_fee,website,remark,sort_id,is_lock from " + databaseprefix + "express ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = id;

            Model.express model = new Model.express();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.title = ds.Tables[0].Rows[0]["title"].ToString();
                model.express_code = ds.Tables[0].Rows[0]["express_code"].ToString();
                if (ds.Tables[0].Rows[0]["express_fee"].ToString() != "")
                {
                    model.express_fee = decimal.Parse(ds.Tables[0].Rows[0]["express_fee"].ToString());
                }
                model.website = ds.Tables[0].Rows[0]["website"].ToString();
                model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
                if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["is_lock"].ToString() != "")
                {
                    model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
예제 #23
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            BLL.wx_shop_cart            cartBll  = new BLL.wx_shop_cart();
            string                      _action  = MyCommFun.QueryString("myact");
            string                      openid   = MyCommFun.RequestOpenid(); //得到微信用户的openid
            Dictionary <string, string> jsonDict = new Dictionary <string, string>();

            if (_action == "addCart")
            {
                #region 添加购物车
                try
                {
                    int     wid        = MyCommFun.RequestInt("wid");
                    int     productId  = MyCommFun.RequestInt("productid");
                    int     skuId      = MyCommFun.RequestInt("mid");
                    string  skuInfo    = MyCommFun.QueryString("attr");
                    int     productNum = MyCommFun.RequestInt("bc");
                    decimal totalPrice = (decimal)MyCommFun.RequestFloat("totprice", 0);

                    Model.wx_shop_cart cart = new Model.wx_shop_cart();

                    IList <Model.wx_shop_cart> cartList = cartBll.GetModelList("productId=" + productId + " and openid='" + openid + "' and skuId=" + skuId);
                    bool isAdd = true;
                    if (cartList != null && cartList.Count > 0)
                    {
                        isAdd = false;
                        cart  = cartList[0];
                    }
                    if (isAdd)
                    {
                        cart.createDate = DateTime.Now;
                        cart.openid     = openid;
                        cart.productId  = productId;
                        cart.productNum = productNum;
                        cart.skuId      = skuId;
                        cart.skuInfo    = skuInfo;
                        cart.totPrice   = totalPrice * productNum;
                        cart.wid        = wid;
                        int ret = cartBll.Add(cart);
                        if (ret > 0)
                        {
                            jsonDict.Add("errCode", "false");
                        }
                        else
                        {
                            jsonDict.Add("errCode", "true");
                        }
                    }
                    else
                    {
                        cart.openid = openid;

                        cart.productNum += productNum;
                        cart.skuId       = skuId;
                        cart.skuInfo     = skuInfo;
                        cart.totPrice   += totalPrice * productNum;
                        cart.wid         = wid;
                        bool ret = cartBll.Update(cart);
                        if (ret)
                        {
                            jsonDict.Add("errCode", "false");
                        }
                        else
                        {
                            jsonDict.Add("errCode", "true");
                        }
                    }
                }
                catch (Exception ex)
                {
                    jsonDict.Add("errCode", "true");
                }
                finally
                {
                    context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                }
                #endregion
            }
            else if (_action == "pcount")
            {
                #region 购物车商品数量
                jsonDict = new Dictionary <string, string>();
                int wid   = MyCommFun.RequestInt("wid");
                int count = cartBll.GetRecordCount("wid=" + wid + " and openid='" + openid + "'");
                jsonDict.Add("data", count.ToString());
                context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                #endregion
            }
            else if (_action == "remove")
            {
                #region 移除购物车商品
                jsonDict = new Dictionary <string, string>();
                int cartId = MyCommFun.RequestInt("id");
                cartBll.Delete(cartId);
                jsonDict.Add("errCode", "false");
                context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                #endregion
            }
            else if (_action == "modifyNum")
            {
                #region 修改购物车商品数量
                jsonDict = new Dictionary <string, string>();
                int cartId = MyCommFun.RequestInt("ic");
                int newNum = MyCommFun.RequestInt("bc");
                cartBll.UpdateNum(cartId, newNum);
                jsonDict.Add("errCode", "false");
                context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                #endregion
            }
            else if (_action == "getCity")
            {
                #region  择省份,改变城市列表
                int privice = MyCommFun.RequestInt("pvid");
                BLL.pre_common_district           areaBll = new BLL.pre_common_district();
                IList <Model.pre_common_district> disList = areaBll.GetModelList("upid=" + privice + " and level=2");
                Model.pre_common_district         dis;
                StringBuilder jsonStr = new StringBuilder("{\"errCode\":0,\"retCode\":0,\"msgType\":0,\"errMsg\":\"\",\"data\":[");
                for (int i = 0; i < disList.Count; i++)
                {
                    dis = new Model.pre_common_district();
                    if (i != disList.Count - 1)
                    {
                        jsonStr.Append("{\"id\":" + disList[i].id + ",\"name\":\"" + disList[i].name + "\"},");
                    }
                    else
                    {
                        jsonStr.Append("{\"id\":" + disList[i].id + ",\"name\":\"" + disList[i].name + "\"}");
                    }
                }
                jsonStr.Append("]}");
                context.Response.Write(jsonStr);
                #endregion
            }
            else if (_action == "getArea")
            {
                #region  择城市,改变区域列表
                int ctid = MyCommFun.RequestInt("ctid");
                BLL.pre_common_district           areaBll = new BLL.pre_common_district();
                IList <Model.pre_common_district> disList = areaBll.GetModelList("upid=" + ctid + " and level=3");
                Model.pre_common_district         dis;
                StringBuilder jsonStr = new StringBuilder("{\"errCode\":0,\"retCode\":0,\"msgType\":0,\"errMsg\":\"\",\"data\":[");
                for (int i = 0; i < disList.Count; i++)
                {
                    dis = new Model.pre_common_district();
                    if (i != disList.Count - 1)
                    {
                        jsonStr.Append("{\"id\":" + disList[i].id + ",\"name\":\"" + disList[i].name + "\"},");
                    }
                    else
                    {
                        jsonStr.Append("{\"id\":" + disList[i].id + ",\"name\":\"" + disList[i].name + "\"}");
                    }
                }
                jsonStr.Append("]}");
                context.Response.Write(jsonStr);
                #endregion
            }
            else if (_action == "order_save")
            {
                #region 保存订单信息
                //获得传参信息
                int wid = MyCommFun.RequestInt("wid");

                int payment_id = MyCommFun.RequestInt("pc");    //支付方式:1货到付款;3微支付
                int express_id = MyCommFun.RequestInt("mtype"); //物流方式
                // string orderStrList = MyCommFun.QueryString("orderStrList");

                //检查物流方式
                if (express_id == 0)
                {
                    context.Response.Write("{\"errCode\":3, \"msg\":\"对不起,请选择配送方式!\"}");
                    return;
                }
                BLL.wx_shop_user_addr           uAddrBll  = new BLL.wx_shop_user_addr();
                IList <Model.wx_shop_user_addr> uaddrList = uAddrBll.GetOpenidAddrName(openid, wid);
                if (uaddrList == null || uaddrList.Count <= 0 || uaddrList[0].id <= 0)
                {
                    context.Response.Write("{\"errCode\":3, \"msg\":\"收货地址不存在,无法结算!\"}");
                    return;
                }


                //检查购物车商品
                IList <Model.cartProduct> cartList = cartBll.GetCartList(openid, wid);
                if (cartList == null)
                {
                    context.Response.Write("{\"errCode\":3, \"msg\":\"对不起,购物车为空,无法结算!\"}");
                    return;
                }
                //统计购物车
                decimal payable_amount = cartList.Sum(c => c.totPrice);
                //物流费用
                BLL.express   expressBll = new BLL.express();
                Model.express expModel   = expressBll.GetModel(express_id);
                //支付方式
                BLL.payment   pbll     = new BLL.payment();
                Model.payment payModel = pbll.GetModelBypTypeId(payment_id);
                //保存订单=======================================================================
                Model.orders model = new Model.orders();
                model.order_no = "b" + Utils.GetOrderNumber(); //订单号B开头为商品订单

                model.wid             = wid;
                model.openid          = openid;
                model.modelName       = "微商城";
                model.modelCode       = "shop";
                model.modelActionName = "";
                model.modelActionId   = 0;
                model.user_id         = 0;
                model.user_name       = "";
                model.payment_id      = payment_id;
                model.express_id      = express_id;
                model.accept_name     = uaddrList[0].contractPerson;
                model.post_code       = "";
                model.telphone        = uaddrList[0].tel;
                model.mobile          = uaddrList[0].tel;
                model.area            = uaddrList[0].province;
                model.city            = uaddrList[0].city;
                model.district        = uaddrList[0].area;
                model.address         = uaddrList[0].province + " " + uaddrList[0].city + " " + uaddrList[0].area + " " + uaddrList[0].addrDetail;
                model.message         = "";
                model.payable_amount  = payable_amount; //应付商品总金额
                model.real_amount     = payable_amount; //实际商品总金额,
                model.status          = 1;
                model.express_status  = 1;
                model.express_fee     = expModel.express_fee; //物流费用

                if (payment_id == 1)
                {                             //货到付款,需要确认订单
                    model.payment_status = 0; //标记未付款
                }
                else
                {                             //先款后货
                    model.payment_status = 1; //标记未付款
                }
                bool quicklyFH = false;
                //如果是先款后货的话
                if (payment_id == 3)
                {
                    if (payModel.poundage_type == 1) //百分比
                    {
                        model.payment_fee = model.real_amount * payModel.poundage_amount / 100;
                    }
                    else //固定金额
                    {
                        model.payment_fee = payModel.poundage_amount;
                    }
                    BLL.wx_payment_wxpay   wxBll = new BLL.wx_payment_wxpay();
                    Model.wx_payment_wxpay wxpay = wxBll.GetModelByWid(wid);
                    quicklyFH = wxpay.quicklyFH;
                }
                if (quicklyFH)
                {
                    model.express_status = 0;
                }
                //订单总金额=实付商品金额+运费+支付手续费
                model.order_amount = model.real_amount + model.express_fee + model.payment_fee;
                //购物积分,可为负数
                model.point    = 0;
                model.add_time = DateTime.Now;
                //商品详细列表
                List <Model.order_goods> gls = new List <Model.order_goods>();
                foreach (Model.cartProduct item in cartList)
                {
                    gls.Add(new Model.order_goods {
                        goods_id = item.productId, goods_title = item.productName, goods_price = item.avgPrice, real_price = item.avgPrice, quantity = item.productNum, point = 0
                    });
                }
                model.order_goods = gls;
                int result = new BLL.orders().Add(model);
                if (result < 1)
                {
                    context.Response.Write("{\"errCode\":3, \"msg\":\"订单保存过程中发生错误,请重新提交!\"}");
                    return;
                }

                //清空购物车,此步骤移到确认支付页面
                //
                //提交成功,返回URL  order_no
                context.Response.Write("{\"errCode\":true,\"payType\":\"" + payment_id + "\", \"order_no\":\"" + model.order_no + "\",\"orderid\":\"" + result + "\",\"wid\":\"" + wid + "\",\"openid\":\"" + openid + "\",\"payable_amount\":\"" + payable_amount + "\", \"msg\":\"恭喜您,订单已成功提交!\"}");
                return;

                #endregion
            }
            else if (_action == "order_canel")
            {
                #region  //取消订单
                int        orderid = MyCommFun.RequestInt("order_id");
                BLL.orders oBll    = new BLL.orders();
                oBll.UpdateField(orderid, "status=4");
                context.Response.Write("{\"errCode\":true, \"msg\":\"订单已取消!\"}");
                #endregion
            }
            else if (_action == "shouhuo")
            {
                #region  //确认收货
                int          orderid = MyCommFun.RequestInt("order_id");
                BLL.orders   oBll    = new BLL.orders();
                Model.orders order   = oBll.GetModel(orderid);
                if (order.payment_id == 1)
                {
                    //货到付款
                    oBll.UpdateField(orderid, "express_status=2,payment_status=2 , status=3");
                }
                else
                {
                    //在线支付
                    oBll.UpdateField(orderid, "express_status=2,payment_status=2 , status=3");
                }

                context.Response.Write("{\"errCode\":true, \"msg\":\"确认收货!\"}");
                #endregion
            }
            else if (_action == "clearMyOrder")
            {
                #region 清空我的购物车订单,在支付页面,支付成功后执行此功能
                int wid = MyCommFun.RequestInt("wid");
                cartBll.RemoveCartInfo(wid, openid);
                #endregion
            }
        }