Beispiel #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.daikuan_repay DataRowToModel(DataRow row)
 {
     Model.daikuan_repay model = new Model.daikuan_repay();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["daikuan_id"] != null && row["daikuan_id"].ToString() != "")
         {
             model.daikuan_id = int.Parse(row["daikuan_id"].ToString());
         }
         if (row["amount"] != null && row["amount"].ToString() != "")
         {
             model.amount = decimal.Parse(row["amount"].ToString());
         }
         if (row["add_time"] != null && row["add_time"].ToString() != "")
         {
             model.add_time = DateTime.Parse(row["add_time"].ToString());
         }
         //相册信息
         model.albums = new daikuan_repay_albums().GetList(model.id, 0);
     }
     return(model);
 }
Beispiel #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.daikuan_repay GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 * from daikuan_repay");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.daikuan_repay model)
 {
     return(dal.Update(model));
 }
Beispiel #4
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.daikuan_repay model)
 {
     return(dal.Add(model));
 }
Beispiel #5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.daikuan_repay model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        #region 添加主表数据====================
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into daikuan_repay(");
                        strSql.Append("daikuan_id,amount,add_time)");
                        strSql.Append(" values (");
                        strSql.Append("@daikuan_id,@amount,@add_time)");
                        strSql.Append(";select @@IDENTITY");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@daikuan_id", SqlDbType.Int,     4),
                            new SqlParameter("@amount",     SqlDbType.Decimal, 9),
                            new SqlParameter("@add_time",   SqlDbType.DateTime)
                        };
                        parameters[0].Value = model.daikuan_id;
                        parameters[1].Value = model.amount;
                        parameters[2].Value = model.add_time;
                        //添加主表数据
                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务
                        model.id = Convert.ToInt32(obj);
                        #endregion

                        #region 添加图片相册====================
                        if (model.albums != null)
                        {
                            StringBuilder strSql3;
                            foreach (Model.daikuan_repay_albums modelt in model.albums)
                            {
                                strSql3 = new StringBuilder();
                                strSql3.Append("insert into daikuan_repay_albums(");
                                strSql3.Append("daikuan_id,thumb_path,original_path,remark,link_url)");
                                strSql3.Append(" values (");
                                strSql3.Append("@daikuan_id,@thumb_path,@original_path,@remark,@link_url)");
                                SqlParameter[] parameters3 =
                                {
                                    new SqlParameter("@daikuan_id",    SqlDbType.Int,        4),
                                    new SqlParameter("@thumb_path",    SqlDbType.NVarChar, 255),
                                    new SqlParameter("@original_path", SqlDbType.NVarChar, 255),
                                    new SqlParameter("@remark",        SqlDbType.NVarChar, 500),
                                    new SqlParameter("@link_url",      SqlDbType.NVarChar, 200)
                                };
                                parameters3[0].Value = model.id;
                                parameters3[1].Value = modelt.thumb_path;
                                parameters3[2].Value = modelt.original_path;
                                parameters3[3].Value = modelt.remark;
                                parameters3[4].Value = modelt.link_url;
                                DbHelperSQL.GetSingle(conn, trans, strSql3.ToString(), parameters3); //带事务
                            }
                        }
                        #endregion

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
Beispiel #6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.daikuan_repay model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        #region 修改主表数据==========================
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update daikuan_repay set ");
                        strSql.Append("daikuan_id=@daikuan_id,");
                        strSql.Append("amount=@amount,");
                        strSql.Append("add_time=@add_time");
                        strSql.Append(" where id=@id");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@daikuan_id", SqlDbType.Int,       4),
                            new SqlParameter("@amount",     SqlDbType.Decimal,   9),
                            new SqlParameter("@add_time",   SqlDbType.DateTime),
                            new SqlParameter("@id",         SqlDbType.Int, 4)
                        };
                        parameters[0].Value = model.daikuan_id;
                        parameters[1].Value = model.amount;
                        parameters[2].Value = model.add_time;
                        parameters[3].Value = model.id;
                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);
                        #endregion

                        #region 修改图片相册==========================
                        //删除已删除的图片
                        new daikuan_repay_albums().DeleteList(conn, trans, model.albums, model.id);
                        //添加/修改相册
                        if (model.albums != null)
                        {
                            StringBuilder strSql3;
                            foreach (Model.daikuan_repay_albums modelt in model.albums)
                            {
                                strSql3 = new StringBuilder();
                                if (modelt.id > 0)
                                {
                                    strSql3.Append("update daikuan_repay_albums set ");
                                    strSql3.Append("daikuan_id=@daikuan_id,");
                                    strSql3.Append("thumb_path=@thumb_path,");
                                    strSql3.Append("original_path=@original_path,");
                                    strSql3.Append("remark=@remark,");
                                    strSql3.Append("link_url=@link_url");
                                    strSql3.Append(" where id=@id");
                                    SqlParameter[] parameters3 =
                                    {
                                        new SqlParameter("@daikuan_id",    SqlDbType.Int,        4),
                                        new SqlParameter("@thumb_path",    SqlDbType.NVarChar, 255),
                                        new SqlParameter("@original_path", SqlDbType.NVarChar, 255),
                                        new SqlParameter("@remark",        SqlDbType.NVarChar, 500),
                                        new SqlParameter("@link_url",      SqlDbType.NVarChar, 200),
                                        new SqlParameter("@id",            SqlDbType.Int, 4)
                                    };
                                    parameters3[0].Value = modelt.daikuan_id;
                                    parameters3[1].Value = modelt.thumb_path;
                                    parameters3[2].Value = modelt.original_path;
                                    parameters3[3].Value = modelt.remark;
                                    parameters3[4].Value = modelt.link_url;
                                    parameters3[5].Value = modelt.id;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql3.ToString(), parameters3);
                                }
                                else
                                {
                                    strSql3.Append("insert into daikuan_repay_albums(");
                                    strSql3.Append("daikuan_repay_id,thumb_path,original_path,remark,link_url)");
                                    strSql3.Append(" values (");
                                    strSql3.Append("@daikuan_repay_id,@thumb_path,@original_path,@remark,@link_url)");
                                    SqlParameter[] parameters3 =
                                    {
                                        new SqlParameter("@daikuan_repay_id", SqlDbType.Int,        4),
                                        new SqlParameter("@thumb_path",       SqlDbType.NVarChar, 255),
                                        new SqlParameter("@original_path",    SqlDbType.NVarChar, 255),
                                        new SqlParameter("@remark",           SqlDbType.NVarChar, 500),
                                        new SqlParameter("@link_url",         SqlDbType.NVarChar, 200)
                                    };
                                    parameters3[0].Value = modelt.daikuan_id;
                                    parameters3[1].Value = modelt.thumb_path;
                                    parameters3[2].Value = modelt.original_path;
                                    parameters3[3].Value = modelt.remark;
                                    parameters3[4].Value = modelt.link_url;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql3.ToString(), parameters3);
                                }
                            }
                        }
                        #endregion

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #7
0
        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            BLL.daikuan       bll      = new BLL.daikuan();
            BLL.daikuan_repay repayBll = new BLL.daikuan_repay();
            var model = bll.GetModel(id);

            var repayModel = new Model.daikuan_repay();

            repayModel.daikuan_id = id;
            repayModel.amount     = Utils.StrToDecimal(txtAmount.Text.Trim(), 0);
            repayModel.add_time   = DateTime.Now;

            model.yh_amount += repayModel.amount;
            model.wh_amount  = model.amount + model.zy_amount - model.yh_amount;
            if (repayModel.amount == 0)
            {
                JscriptMsg("请填写正确金额!", "daikuan_repay.aspx?id=" + this.id);
                return;
            }
            if (model.yh_amount > model.amount + model.zy_amount)
            {
                JscriptMsg("已还金额超出借款金额!", "daikuan_repay.aspx?id=" + this.id);
                return;
            }
            if (model.wh_amount > 0)
            {
                model.hk_status = 0;
            }
            if (model.wh_amount == 0)
            {
                model.hk_status = 1;
            }

            #region 保存相册====================
            string[] albumArr    = Request.Form.GetValues("hid_photo_name");
            string[] remarkArr   = Request.Form.GetValues("hid_photo_remark");
            string[] link_urlArr = Request.Form.GetValues("hid_photo_link_url");
            if (albumArr != null && albumArr.Length > 0)
            {
                List <Model.daikuan_repay_albums> ls = new List <Model.daikuan_repay_albums>();
                for (int i = 0; i < albumArr.Length; i++)
                {
                    string[] imgArr = albumArr[i].Split('|');
                    if (imgArr.Length == 3)
                    {
                        if (!string.IsNullOrEmpty(link_urlArr[i]))
                        {
                            ls.Add(new Model.daikuan_repay_albums {
                                original_path = imgArr[1], thumb_path = imgArr[2], link_url = link_urlArr[i]
                            });
                        }
                        if (!string.IsNullOrEmpty(remarkArr[i]))
                        {
                            ls.Add(new Model.daikuan_repay_albums {
                                original_path = imgArr[1], thumb_path = imgArr[2], remark = remarkArr[i]
                            });
                        }
                        else
                        {
                            ls.Add(new Model.daikuan_repay_albums {
                                original_path = imgArr[1], thumb_path = imgArr[2]
                            });
                        }
                    }
                }
                repayModel.albums = ls;
            }
            #endregion

            repayBll.Add(repayModel);
            if (bll.Update(model))
            {
                JscriptMsg("还款成功!", "daikuan_manager_list.aspx");
            }
        }