public string GetAccountPropertyByAccountModel(AccountDescription description)
 {
     StringBuilder stringBuilder = new StringBuilder();
     stringBuilder.Append(description.GameName.Trim());
     stringBuilder.Append("/");
     stringBuilder.Append(description.GameArea.Trim());
     stringBuilder.Append("/");
     stringBuilder.Append(description.ServerName.Trim());
     return stringBuilder.ToString();
 }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(AccountDescription model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update AccountDescription set ");

            strSql.Append(" productImgAUrl = @productImgAUrl , ");
            strSql.Append(" productImgBUrl = @productImgBUrl , ");
            strSql.Append(" ProductImgCUrl = @ProductImgCUrl , ");
            strSql.Append(" ProductImgDUrl = @ProductImgDUrl , ");
            strSql.Append(" SubmitTime = @SubmitTime , ");
            strSql.Append(" OrderStatus = @OrderStatus , ");
            strSql.Append(" OrderNo = @OrderNo , ");
            strSql.Append(" UserID = @UserID , ");
            strSql.Append(" Remark = @Remark , ");
            strSql.Append(" EditDate = @EditDate , ");
            strSql.Append(" GameName = @GameName , ");
            strSql.Append(" EditUser = @EditUser , ");
            strSql.Append(" GameArea = @GameArea , ");
            strSql.Append(" ServerName = @ServerName , ");
            strSql.Append(" AccountInfoID = @AccountInfoID , ");
            strSql.Append(" ProductProperty = @ProductProperty , ");
            strSql.Append(" ProductTitle = @ProductTitle , ");
            strSql.Append(" ProductDescription = @ProductDescription , ");
            strSql.Append(" Price = @Price  ");
            strSql.Append(" where ID=@ID ");

            SqlParameter[] parameters = {
                        new SqlParameter("@ID", SqlDbType.Int,4) ,
                        new SqlParameter("@productImgAUrl", SqlDbType.VarChar,255) ,
                        new SqlParameter("@productImgBUrl", SqlDbType.VarChar,255) ,
                        new SqlParameter("@ProductImgCUrl", SqlDbType.VarChar,255) ,
                        new SqlParameter("@ProductImgDUrl", SqlDbType.VarChar,255) ,
                        new SqlParameter("@SubmitTime", SqlDbType.DateTime) ,
                        new SqlParameter("@OrderStatus", SqlDbType.Int,4) ,
                        new SqlParameter("@OrderNo", SqlDbType.VarChar,255) ,
                        new SqlParameter("@UserID", SqlDbType.Int,4) ,
                        new SqlParameter("@Remark", SqlDbType.VarChar,500) ,
                        new SqlParameter("@EditDate", SqlDbType.DateTime) ,
                        new SqlParameter("@GameName", SqlDbType.VarChar,50) ,
                        new SqlParameter("@EditUser", SqlDbType.VarChar,50) ,
                        new SqlParameter("@GameArea", SqlDbType.VarChar,50) ,
                        new SqlParameter("@ServerName", SqlDbType.VarChar,50) ,
                        new SqlParameter("@AccountInfoID", SqlDbType.Int,4) ,
                        new SqlParameter("@ProductProperty", SqlDbType.VarChar,255) ,
                        new SqlParameter("@ProductTitle", SqlDbType.NChar,255) ,
                        new SqlParameter("@ProductDescription", SqlDbType.NChar,255) ,
                        new SqlParameter("@Price", SqlDbType.Decimal,9)

            };

            parameters[0].Value = model.ID;
            parameters[1].Value = model.ProductImgAUrl;
            parameters[2].Value = model.ProductImgBUrl;
            parameters[3].Value = model.ProductImgCUrl;
            parameters[4].Value = model.ProductImgDUrl;
            parameters[5].Value = model.SubmitTime;
            parameters[6].Value = model.OrderStatus;
            parameters[7].Value = model.OrderNo;
            parameters[8].Value = model.UserID;
            parameters[9].Value = model.Remark;
            parameters[10].Value = model.EditDate;
            parameters[11].Value = model.GameName;
            parameters[12].Value = model.EditUser;
            parameters[13].Value = model.GameArea;
            parameters[14].Value = model.ServerName;
            parameters[15].Value = model.AccountInfoID;
            parameters[16].Value = model.ProductProperty;
            parameters[17].Value = model.ProductTitle;
            parameters[18].Value = model.ProductDescription;
            parameters[19].Value = model.Price;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public List<AccountDescription> GetPagedAccountDescriptionsModelsByProc(int pageIndex, int pageSize, string whereStr,string orderStr, out int rowCount,
          out int pageCount)
        {
            List<AccountDescription> modelsList = new List<AccountDescription>();
            rowCount = 0;
            pageCount = 0;
            IDataParameter[] sqlParameters =
            {
                new SqlParameter("@TableName","AccountDescription"),
                new SqlParameter("@IDName","ID"),
                new SqlParameter("@PageIndex",pageIndex),
                new SqlParameter("@PageSize",pageSize),
                new SqlParameter("@Where",string.IsNullOrEmpty(whereStr)?"":whereStr),
                new SqlParameter("@OrderBy",string.IsNullOrEmpty(orderStr)?"order by ID":"order by "+orderStr),
                new SqlParameter("@RowCount",SqlDbType.Int,25),
                new SqlParameter("@PageCount",SqlDbType.Int,25),
            };
            sqlParameters[6].Direction =ParameterDirection.Output;
            sqlParameters[6].Value = DBNull.Value;
            sqlParameters[7].Direction = ParameterDirection.Output;
            sqlParameters[7].Value = DBNull.Value;

            //SqlDataReader dataReader = DbHelperSQL.RunProcedure("sp_GetPageDataOutRowPageCount", sqlParameters);
            using (SqlConnection connection = new SqlConnection(DbHelperSQL.connectionString))
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = connection;
                cmd.Parameters.AddRange(sqlParameters);
                cmd.CommandText = "sp_GetPageDataOutRowPageCount";
                SqlDataReader dataReader = cmd.ExecuteReader();
                using (dataReader)
                {
                    while (dataReader.Read())
                    {
                        AccountDescription infoModel = new AccountDescription();

                        infoModel.ID = Convert.ToInt32(dataReader["ID"]);
                        infoModel.SubmitTime =
                            Convert.ToDateTime(Convert.IsDBNull(dataReader["SubmitTime"])
                                ? DateTime.MinValue
                                : dataReader["SubmitTime"]);
                        infoModel.ProductTitle = Convert.ToString(dataReader["ProductTitle"]);
                        infoModel.ProductProperty = Convert.ToString(dataReader["ProductProperty"]);
                        infoModel.Price = Convert.ToDecimal(dataReader["Price"]);
                        infoModel.AccountInfoID = Convert.ToInt32(dataReader["AccountInfoID"]);
                        infoModel.ServerName = Convert.ToString(dataReader["ServerName"]);
                        infoModel.GameName = Convert.ToString(dataReader["GameName"]);
                        infoModel.GameArea = Convert.ToString(dataReader["GameArea"]);
                        infoModel.OrderNo = Convert.ToString(dataReader["OrderNo"]);
                        infoModel.OrderStatus = (OrderStatus) dataReader["OrderStatus"];
                        infoModel.UserID =Convert.IsDBNull(dataReader["UserID"])?0:Convert.ToInt32(dataReader["UserID"]);
                        infoModel.Remark = Convert.IsDBNull(dataReader["Remark"])
                            ? ""
                            : Convert.ToString(dataReader["Remark"]);
                        modelsList.Add(infoModel);
                    }
                }
                //只有在DataReader关闭后才能拿到输出参数!重要,重要
                rowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value);
                pageCount = Convert.ToInt32(cmd.Parameters["@PageCount"].Value);
            }
            return modelsList;
        }
 public List<AccountDescription> GetModelList(string where)
 {
     List<AccountDescription> list = new List<AccountDescription>();
     DataSet dataSet = GetList(where);
     DataTable dtTable = dataSet.Tables[0];
     foreach (DataRow dataRow in dtTable.Rows)
     {
         AccountDescription accountdescription = new AccountDescription();
         accountdescription.ID = Convert.ToInt32(dataRow["ID"]);
         accountdescription.OrderNo = Convert.ToString(dataRow["OrderNo"]);
         list.Add(accountdescription);
     }
     return list;
 }
        /// <summary>
        /// 根据AccountInfoID 拿到 AccountDescription
        /// </summary>
        /// <param name="accountInfoId"></param>
        /// <returns></returns>
        public AccountDescription GetModelByAccountInfoId(int accountInfoId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID, productImgAUrl, productImgBUrl, ProductImgCUrl, ProductImgDUrl, SubmitTime, OrderStatus, OrderNo, GameName, GameArea, ServerName, AccountInfoID, ProductProperty, ProductTitle, ProductDescription, Price,UserID,Remark,EditDate,EditUser ");
            strSql.Append("  from AccountDescription ");
            strSql.Append(" where AccountInfoID=@AccountInfoID");
            SqlParameter[] parameters = {
                    new SqlParameter("@AccountInfoID", SqlDbType.Int,4)
            };
            parameters[0].Value = accountInfoId;

            AccountDescription model = new AccountDescription();
            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.ProductImgAUrl = ds.Tables[0].Rows[0]["productImgAUrl"].ToString();
                model.ProductImgBUrl = ds.Tables[0].Rows[0]["productImgBUrl"].ToString();
                model.ProductImgCUrl = ds.Tables[0].Rows[0]["ProductImgCUrl"].ToString();
                model.ProductImgDUrl = ds.Tables[0].Rows[0]["ProductImgDUrl"].ToString();
                if (ds.Tables[0].Rows[0]["SubmitTime"].ToString() != "")
                {
                    model.SubmitTime = DateTime.Parse(ds.Tables[0].Rows[0]["SubmitTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["OrderStatus"].ToString() != "")
                {
                    model.OrderStatus = (OrderStatus)Enum.Parse(typeof(OrderStatus), ds.Tables[0].Rows[0]["OrderStatus"].ToString(), true);
                }
                model.OrderNo = ds.Tables[0].Rows[0]["OrderNo"].ToString();
                model.GameName = ds.Tables[0].Rows[0]["GameName"].ToString();
                model.GameArea = ds.Tables[0].Rows[0]["GameArea"].ToString();
                model.ServerName = ds.Tables[0].Rows[0]["ServerName"].ToString();
                if (ds.Tables[0].Rows[0]["AccountInfoID"].ToString() != "")
                {
                    model.AccountInfoID = int.Parse(ds.Tables[0].Rows[0]["AccountInfoID"].ToString());
                }
                model.ProductProperty = ds.Tables[0].Rows[0]["ProductProperty"].ToString();
                model.ProductTitle = ds.Tables[0].Rows[0]["ProductTitle"].ToString();
                model.ProductDescription = ds.Tables[0].Rows[0]["ProductDescription"].ToString();
                model.UserID = Convert.IsDBNull(ds.Tables[0].Rows[0]["UserID"]) ? 0 : Convert.ToInt32(ds.Tables[0].Rows[0]["UserID"]);
                if (ds.Tables[0].Rows[0]["Price"].ToString() != "")
                {
                    model.Price = decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Remark"].ToString() != "")
                {
                    model.Remark = Convert.ToString(ds.Tables[0].Rows[0]["Remark"]);
                }
                if (ds.Tables[0].Rows[0]["EditUser"].ToString() != "")
                {
                    model.EditUser = Convert.ToString(ds.Tables[0].Rows[0]["EditUser"]);
                }
                if (ds.Tables[0].Rows[0]["EditDate"].ToString() != "")
                {
                    model.EditDate = DateTime.Parse(ds.Tables[0].Rows[0]["EditDate"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(AccountDescription model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into AccountDescription(");
            strSql.Append("productImgAUrl,productImgBUrl,ProductImgCUrl,ProductImgDUrl,SubmitTime,OrderStatus,OrderNo,GameName,GameArea,ServerName,AccountInfoID,ProductProperty,ProductTitle,ProductDescription,Price,UserID,Remark,EditDate");
            strSql.Append(") values (");
            strSql.Append("@productImgAUrl,@productImgBUrl,@ProductImgCUrl,@ProductImgDUrl,@SubmitTime,@OrderStatus,@OrderNo,@GameName,@GameArea,@ServerName,@AccountInfoID,@ProductProperty,@ProductTitle,@ProductDescription,@Price,@UserID,@Remark,@EditDate");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                        new SqlParameter("@productImgAUrl", SqlDbType.VarChar,255) ,
                        new SqlParameter("@productImgBUrl", SqlDbType.VarChar,255) ,
                        new SqlParameter("@ProductImgCUrl", SqlDbType.VarChar,255) ,
                        new SqlParameter("@ProductImgDUrl", SqlDbType.VarChar,255) ,
                        new SqlParameter("@SubmitTime", SqlDbType.DateTime) ,
                        new SqlParameter("@OrderStatus", SqlDbType.Int,4) ,
                        new SqlParameter("@OrderNo", SqlDbType.VarChar,255) ,
                        new SqlParameter("@GameName", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@GameArea", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@ServerName", SqlDbType.NVarChar,50) ,
                        new SqlParameter("@AccountInfoID", SqlDbType.Int,4) ,
                        new SqlParameter("@ProductProperty", SqlDbType.NVarChar,255) ,
                        new SqlParameter("@ProductTitle", SqlDbType.NChar,255) ,
                        new SqlParameter("@ProductDescription", SqlDbType.NChar,255) ,
                        new SqlParameter("@Price", SqlDbType.Decimal,9)      ,
                        new SqlParameter("@UserID",SqlDbType.Int),
                        new SqlParameter("@Remark",SqlDbType.VarChar,500),
                        new SqlParameter("@EditDate",SqlDbType.DateTime),

            };

            parameters[0].Value = model.ProductImgAUrl;
            parameters[1].Value = model.ProductImgBUrl;
            parameters[2].Value = model.ProductImgCUrl;
            parameters[3].Value = model.ProductImgDUrl;
            parameters[4].Value = model.SubmitTime;
            parameters[5].Value = model.OrderStatus;
            parameters[6].Value = model.OrderNo;
            parameters[7].Value = model.GameName;
            parameters[8].Value = model.GameArea;
            parameters[9].Value = model.ServerName;
            parameters[10].Value = model.AccountInfoID;
            parameters[11].Value = model.ProductProperty;
            parameters[12].Value = model.ProductTitle;
            parameters[13].Value = model.ProductDescription;
            parameters[14].Value = model.Price;
            parameters[15].Value = model.UserID;
            parameters[16].Value = model.Remark;
            parameters[17].Value = model.EditDate;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {

                return Convert.ToInt32(obj);

            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     //todo:判断页面第一次加载减少数据读取次数
     //根据页面传过来的订单信息(AccountDescription)ID,查到订单详细信息
     string descriptionId = Request.QueryString.Get("acDes");
     int accountDescriptionId;
     if (!int.TryParse(descriptionId, out accountDescriptionId))
     {
         CurrentAccountDescription = new AccountDescription();
         ClientScript.RegisterClientScriptBlock(this.GetType(), "alert",
             "<script>alert('订单ID有误,请反回重试!');window.location.href='/BillList.aspx';</script>");
     }
     else
     {
         CurrentAccountDescription = _accountDescriptionDataAccess.GetModel(accountDescriptionId);
         descriptionID.Value = Convert.ToString(accountDescriptionId);
     }
 }
        /// <summary>
        /// 点击生成订单后处理用户上传的订单描述信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //商品属性
            string productPropertyStr = productProperty.Text;
            //标题
            string productTitleStr = productTitle.Text;
            //价格
            string productPriceStr = productPrice.Text;
            //产品描述
            string pdDescriptionStr =HttpUtility.HtmlEncode(pdDescription.Text);
            //四人图片地址
            decimal decPrice;
            #region 数据校验
            if (!decimal.TryParse(productPriceStr, out decPrice))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('价格输入有误,请重新输入!')</script>");
                return;
            }
            #endregion
            AccountDescription description = new AccountDescription();
            //用户前置订单ID
            string accountInfoIdStr = accountInfoID.Value;
            int accountInfoIdStrInt;
            if (!int.TryParse(accountInfoIdStr, out accountInfoIdStrInt))
            {
                ClientScript.RegisterClientScriptBlock(GetType(), "alert", "<script>alert('用户前置订单ID有误,请反回重试!');window.location.href='/accountInfo.aspx';</script>");
                return;
            }
            description.AccountInfoID = accountInfoIdStrInt;
            description.ProductDescription = pdDescriptionStr;
            description.ProductTitle = productTitleStr;
            description.ProductProperty = productPropertyStr;
            description.Price = decPrice;
            //拿到用户订单Info,添加订单冗余字段值
            AccountInfoModel accountinfoModel = _accountInfoDataAccess.GetModel(accountInfoIdStrInt);
            if (accountinfoModel == null || accountinfoModel.ID <= 0||accountinfoModel.OrderStatus!=OrderStatus.NotComplete)
            {
                ClientScript.RegisterClientScriptBlock(GetType(), "alert", "<script>alert('用户前置订单信息有误,请反回重试!');window.location.href='/accountInfo.aspx';</script>");
                return;
            }
            //给冗余字段赋值,方便做列表筛选
            description.GameArea = accountinfoModel.GameArea;
            description.GameName = accountinfoModel.GameName;
            description.ServerName = accountinfoModel.ServerName;
            if(!string.IsNullOrEmpty(hiddenimggameImgA.Value.Trim()))
            {
                description.ProductImgAUrl = hiddenimggameImgA.Value.Trim();
            }
            if (!string.IsNullOrEmpty(hiddenimggameImgB.Value.Trim()))
            {
                description.ProductImgBUrl = hiddenimggameImgB.Value.Trim();
            }
            if (!string.IsNullOrEmpty(hiddenimggameImgC.Value.Trim()))
            {
                description.ProductImgCUrl = hiddenimggameImgC.Value.Trim();
            }
            if (!string.IsNullOrEmpty(hiddenimggameImgD.Value.Trim()))
            {
                description.ProductImgDUrl = hiddenimggameImgD.Value.Trim();
            }

            //生成订单号  写入订单状态
            //检察订单号是否已存在
            string orderNoStr = GeneralOrderNo();
            description.OrderNo = orderNoStr;
            description.OrderStatus = OrderStatus.ShenHe;
            description.UserID = CurrentUser.ID;
            description.EditDate = DateTime.Now;
            int res = _accountDescriptionDataAccess.Add(description);
            if (res > 0)
            {
                //订单创建成功,更改前置订单状态
                accountinfoModel.OrderStatus = OrderStatus.ShenHe;
                bool resUpdate = _accountInfoDataAccess.Update(accountinfoModel);
                if (resUpdate)
                {
                    //跳转到订单列表页
                    Response.Redirect("AccountSaleList.aspx");
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "alert","<script>alert('订单提交成功,进入审核状态!')</script>");
                }
            }
        }