Esempio n. 1
0
 /// <summary>
 /// 取得数据
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 private CarSpirits.Model.OrderInfo GetData(int id)
 {
     CarSpirits.Model.OrderInfo model = new CarSpirits.Model.OrderInfo();
     if (id > 0)
     {
         model = bll.GetModel(id);
     }
     else
     {
     }
     model.PlateNumber = Request.Form["ipt_platenumber"] != "" ? Request.Form["ipt_platenumber"] : "";
     model.GasStation  = Request.Form["ipt_gasstation"] != "" ? Request.Form["ipt_gasstation"] : "";
     model.GasOline    = Request.Form["ipt_gasoline"] != "" ? Request.Form["ipt_gasoline"] : "";
     model.Price       = decimal.Parse(Request.Form["ipt_price"] != "" ? Request.Form["ipt_price"] : "");
     return(model);
 }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CarSpirits.Model.OrderInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update OrderInfo set ");
            strSql.Append("CustomerID=@CustomerID,");
            strSql.Append("OrderID=@OrderID,");
            strSql.Append("PlateNumber=@PlateNumber,");
            strSql.Append("GasStation=@GasStation,");
            strSql.Append("GasOline=@GasOline,");
            strSql.Append("Price=@Price,");
            strSql.Append("OrderTime=@OrderTime");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CustomerID",  SqlDbType.NVarChar,  50),
                new SqlParameter("@OrderID",     SqlDbType.NVarChar,  50),
                new SqlParameter("@PlateNumber", SqlDbType.NVarChar,  50),
                new SqlParameter("@GasStation",  SqlDbType.NVarChar,  50),
                new SqlParameter("@GasOline",    SqlDbType.NVarChar,  20),
                new SqlParameter("@Price",       SqlDbType.Decimal,    5),
                new SqlParameter("@OrderTime",   SqlDbType.DateTime),
                new SqlParameter("@id",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.CustomerID;
            parameters[1].Value = model.OrderID;
            parameters[2].Value = model.PlateNumber;
            parameters[3].Value = model.GasStation;
            parameters[4].Value = model.GasOline;
            parameters[5].Value = model.Price;
            parameters[6].Value = model.OrderTime;
            parameters[7].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public CarSpirits.Model.OrderInfo DataRowToModel(DataRow row)
 {
     CarSpirits.Model.OrderInfo model = new CarSpirits.Model.OrderInfo();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["CustomerID"] != null)
         {
             model.CustomerID = row["CustomerID"].ToString();
         }
         if (row["OrderID"] != null)
         {
             model.OrderID = row["OrderID"].ToString();
         }
         if (row["PlateNumber"] != null)
         {
             model.PlateNumber = row["PlateNumber"].ToString();
         }
         if (row["GasStation"] != null)
         {
             model.GasStation = row["GasStation"].ToString();
         }
         if (row["GasOline"] != null)
         {
             model.GasOline = row["GasOline"].ToString();
         }
         if (row["Price"] != null && row["Price"].ToString() != "")
         {
             model.Price = decimal.Parse(row["Price"].ToString());
         }
         if (row["OrderTime"] != null && row["OrderTime"].ToString() != "")
         {
             model.OrderTime = DateTime.Parse(row["OrderTime"].ToString());
         }
     }
     return(model);
 }
Esempio n. 4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(CarSpirits.Model.OrderInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into OrderInfo(");
            strSql.Append("CustomerID,OrderID,PlateNumber,GasStation,GasOline,Price,OrderTime)");
            strSql.Append(" values (");
            strSql.Append("@CustomerID,@OrderID,@PlateNumber,@GasStation,@GasOline,@Price,@OrderTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CustomerID",  SqlDbType.NVarChar, 50),
                new SqlParameter("@OrderID",     SqlDbType.NVarChar, 50),
                new SqlParameter("@PlateNumber", SqlDbType.NVarChar, 50),
                new SqlParameter("@GasStation",  SqlDbType.NVarChar, 50),
                new SqlParameter("@GasOline",    SqlDbType.NVarChar, 20),
                new SqlParameter("@Price",       SqlDbType.Decimal,   5),
                new SqlParameter("@OrderTime",   SqlDbType.DateTime)
            };
            parameters[0].Value = model.CustomerID;
            parameters[1].Value = model.OrderID;
            parameters[2].Value = model.PlateNumber;
            parameters[3].Value = model.GasStation;
            parameters[4].Value = model.GasOline;
            parameters[5].Value = model.Price;
            parameters[6].Value = model.OrderTime;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CarSpirits.Model.OrderInfo GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,CustomerID,OrderID,PlateNumber,GasStation,GasOline,Price,OrderTime from OrderInfo ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 添加或修改数据
        /// </summary>
        private void UpdateData()
        {
            int id = Request.Form["id"] != "" ? Convert.ToInt32(Request.Form["id"]) : 0;

            CarSpirits.Model.OrderInfo model = GetData(id);
            string writeMsg = "操作失败!";

            if (model != null)
            {
                if (id < 1)
                {
                    if (bll.Add(model) > 0)
                    {
                        writeMsg = "增加成功!";
                    }
                    else
                    {
                        writeMsg = "增加失败!";
                    }
                }
                else
                {
                    if (bll.Update(model))
                    {
                        writeMsg = "更新成功!";
                    }
                    else
                    {
                        writeMsg = "更新失败!";
                    }
                }
            }
            Response.Clear();
            Response.Write(writeMsg);
            Response.End();
        }