Beispiel #1
0
 /// <summary>
 /// 更新数据
 /// 作者:章建国
 /// </summary>
 /// <param name="model">需要更新的模型</param>
 /// <returns></returns>
 private string UpdateDeviceOUT(tb_DeviceOUT model, string flag)
 {
     try
     {
         if (model != null && model.id > 0)
         {
             model.updateDate = DateTime.Now;
             model.updateUser = CurrentUserInfo.PersonnelID;
             var tempinmodel = _deviceoutbll.GetModel(model.id);
             var devicemodel = _devicebll.GetModel(model.deviceId.Value);
             if (_deviceoutbll.Update(model))
             {
                 if (model.amount > tempinmodel.amount)
                 {
                     devicemodel.amount -= model.amount - tempinmodel.amount;
                 }
                 else if (model.amount < tempinmodel.amount)
                 {
                     devicemodel.amount += tempinmodel.amount - model.amount;
                 }
                 if (_devicebll.Update(devicemodel))
                 {
                     flag = "1";
                 }
             }
         }
     }
     catch
     {
         flag = "0";
     }
     return(flag);
 }
Beispiel #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(tb_DeviceOUT model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_DeviceOUT(");
            strSql.Append("deviceId,amount,userId1,useFor,gDate,userId2,bDate,userId3,remark,createUser,createDate,updateUser,updateDate,temp1,temp2)");
            strSql.Append(" values (");
            strSql.Append("@deviceId,@amount,@userId1,@useFor,@gDate,@userId2,@bDate,@userId3,@remark,@createUser,@createDate,@updateUser,@updateDate,@temp1,@temp2)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@deviceId",   SqlDbType.Int,       4),
                new SqlParameter("@amount",     SqlDbType.Int,       4),
                new SqlParameter("@userId1",    SqlDbType.Int,       4),
                new SqlParameter("@useFor",     SqlDbType.Text),
                new SqlParameter("@gDate",      SqlDbType.DateTime),
                new SqlParameter("@userId2",    SqlDbType.Int,       4),
                new SqlParameter("@bDate",      SqlDbType.DateTime),
                new SqlParameter("@userId3",    SqlDbType.Int,       4),
                new SqlParameter("@remark",     SqlDbType.Text),
                new SqlParameter("@createUser", SqlDbType.Int,       4),
                new SqlParameter("@createDate", SqlDbType.DateTime),
                new SqlParameter("@updateUser", SqlDbType.Int,       4),
                new SqlParameter("@updateDate", SqlDbType.DateTime),
                new SqlParameter("@temp1",      SqlDbType.Text),
                new SqlParameter("@temp2",      SqlDbType.Text)
            };
            parameters[0].Value  = model.deviceId;
            parameters[1].Value  = model.amount;
            parameters[2].Value  = model.userId1;
            parameters[3].Value  = model.useFor;
            parameters[4].Value  = model.gDate;
            parameters[5].Value  = model.userId2;
            parameters[6].Value  = model.bDate;
            parameters[7].Value  = model.userId3;
            parameters[8].Value  = model.remark;
            parameters[9].Value  = model.createUser;
            parameters[10].Value = model.createDate;
            parameters[11].Value = model.updateUser;
            parameters[12].Value = model.updateDate;
            parameters[13].Value = model.temp1;
            parameters[14].Value = model.temp2;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #3
0
        /// <summary>
        /// 新建数据
        /// 作者:章建国
        /// </summary>
        /// <param name="model"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        private string NewDeviceOUT(tb_DeviceOUT model, string flag)
        {
            model.createDate = DateTime.Now;
            model.createUser = CurrentUserInfo.PersonnelID;
            model.updateDate = DateTime.Now;
            model.updateUser = CurrentUserInfo.PersonnelID;
            var devicemodel = _devicebll.GetModel(model.deviceId.Value);

            if (_deviceoutbll.Add(model) > 0)
            {
                devicemodel.amount -= model.amount;
                if (_devicebll.Update(devicemodel))
                {
                    flag = "1";
                }
            }
            return(flag);
        }
Beispiel #4
0
        /// <summary>
        /// 新建数据或更新数据
        /// 作者:章建国
        /// </summary>
        /// <param name="model">新输入的数据</param>
        /// <returns></returns>
        public string DeviceOUTCU(tb_DeviceOUT model)
        {
            string flag = "0";

            try
            {
                if (model.id > 0)
                {
                    flag = UpdateDeviceOUT(model, flag);
                }
                else
                {
                    flag = NewDeviceOUT(model, flag);
                }
            }
            catch
            {
                flag = "0";
            }
            return(flag);
        }
Beispiel #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public tb_DeviceOUT GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,deviceId,amount,userId1,useFor,gDate,userId2,bDate,userId3,remark,createUser,createDate,updateUser,updateDate,temp1,temp2 from tb_DeviceOUT ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            tb_DeviceOUT model = new tb_DeviceOUT();
            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 #6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(tb_DeviceOUT model)
 {
     return(dal.Update(model));
 }
Beispiel #7
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(tb_DeviceOUT model)
 {
     return(dal.Add(model));
 }
Beispiel #8
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public tb_DeviceOUT DataRowToModel(DataRow row)
        {
            tb_DeviceOUT model = new tb_DeviceOUT();

            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["deviceId"] != null && row["deviceId"].ToString() != "")
                {
                    model.deviceId = int.Parse(row["deviceId"].ToString());
                }
                if (row["amount"] != null && row["amount"].ToString() != "")
                {
                    model.amount = int.Parse(row["amount"].ToString());
                }
                if (row["userId1"] != null && row["userId1"].ToString() != "")
                {
                    model.userId1 = int.Parse(row["userId1"].ToString());
                }
                if (row["useFor"] != null)
                {
                    model.useFor = row["useFor"].ToString();
                }
                if (row["gDate"] != null && row["gDate"].ToString() != "")
                {
                    model.gDate = DateTime.Parse(row["gDate"].ToString());
                }
                if (row["userId2"] != null && row["userId2"].ToString() != "")
                {
                    model.userId2 = int.Parse(row["userId2"].ToString());
                }
                if (row["bDate"] != null && row["bDate"].ToString() != "")
                {
                    model.bDate = DateTime.Parse(row["bDate"].ToString());
                }
                if (row["userId3"] != null && row["userId3"].ToString() != "")
                {
                    model.userId3 = int.Parse(row["userId3"].ToString());
                }
                if (row["remark"] != null)
                {
                    model.remark = row["remark"].ToString();
                }
                if (row["createUser"] != null && row["createUser"].ToString() != "")
                {
                    model.createUser = int.Parse(row["createUser"].ToString());
                }
                if (row["createDate"] != null && row["createDate"].ToString() != "")
                {
                    model.createDate = DateTime.Parse(row["createDate"].ToString());
                }
                if (row["updateUser"] != null && row["updateUser"].ToString() != "")
                {
                    model.updateUser = int.Parse(row["updateUser"].ToString());
                }
                if (row["updateDate"] != null && row["updateDate"].ToString() != "")
                {
                    model.updateDate = DateTime.Parse(row["updateDate"].ToString());
                }
                if (row["temp1"] != null)
                {
                    model.temp1 = row["temp1"].ToString();
                }
                if (row["temp2"] != null)
                {
                    model.temp2 = row["temp2"].ToString();
                }
            }
            return(model);
        }
Beispiel #9
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(tb_DeviceOUT model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tb_DeviceOUT set ");
            strSql.Append("deviceId=@deviceId,");
            strSql.Append("amount=@amount,");
            strSql.Append("userId1=@userId1,");
            strSql.Append("useFor=@useFor,");
            strSql.Append("gDate=@gDate,");
            strSql.Append("userId2=@userId2,");
            strSql.Append("bDate=@bDate,");
            strSql.Append("userId3=@userId3,");
            strSql.Append("remark=@remark,");
            strSql.Append("createUser=@createUser,");
            strSql.Append("createDate=@createDate,");
            strSql.Append("updateUser=@updateUser,");
            strSql.Append("updateDate=@updateDate,");
            strSql.Append("temp1=@temp1,");
            strSql.Append("temp2=@temp2");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@deviceId",   SqlDbType.Int,       4),
                new SqlParameter("@amount",     SqlDbType.Int,       4),
                new SqlParameter("@userId1",    SqlDbType.Int,       4),
                new SqlParameter("@useFor",     SqlDbType.Text),
                new SqlParameter("@gDate",      SqlDbType.DateTime),
                new SqlParameter("@userId2",    SqlDbType.Int,       4),
                new SqlParameter("@bDate",      SqlDbType.DateTime),
                new SqlParameter("@userId3",    SqlDbType.Int,       4),
                new SqlParameter("@remark",     SqlDbType.Text),
                new SqlParameter("@createUser", SqlDbType.Int,       4),
                new SqlParameter("@createDate", SqlDbType.DateTime),
                new SqlParameter("@updateUser", SqlDbType.Int,       4),
                new SqlParameter("@updateDate", SqlDbType.DateTime),
                new SqlParameter("@temp1",      SqlDbType.Text),
                new SqlParameter("@temp2",      SqlDbType.Text),
                new SqlParameter("@id",         SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.deviceId;
            parameters[1].Value  = model.amount;
            parameters[2].Value  = model.userId1;
            parameters[3].Value  = model.useFor;
            parameters[4].Value  = model.gDate;
            parameters[5].Value  = model.userId2;
            parameters[6].Value  = model.bDate;
            parameters[7].Value  = model.userId3;
            parameters[8].Value  = model.remark;
            parameters[9].Value  = model.createUser;
            parameters[10].Value = model.createDate;
            parameters[11].Value = model.updateUser;
            parameters[12].Value = model.updateDate;
            parameters[13].Value = model.temp1;
            parameters[14].Value = model.temp2;
            parameters[15].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }