Esempio n. 1
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            //验证单位名称

            if (txtUnit.Text.Trim() == "")
            {
                MessageBoxEx.Show("请输入商品单位!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUnit.Focus();
                return;
            }



            Dong.BLL.Unit   bUnit = new Dong.BLL.Unit();
            Dong.Model.Unit model = new Dong.Model.Unit();
            model.Name = txtUnit.Text;
            model.Id   = int.Parse(this.Tag.ToString());
            if (bUnit.Update(model))
            {
                MessageBoxEx.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                frmUnit fvip = (frmUnit)this.Owner;
                fvip.refreshData();
                this.Close();
            }
            else
            {
                MessageBoxEx.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Dong.Model.Unit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Unit set ");
            strSql.Append("Name=@Name");
            strSql.Append(" where Id=@Id");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@Name", OleDbType.VarChar, 50),
                new OleDbParameter("@Id",   OleDbType.Integer, 4)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Dong.Model.Unit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Unit(");
            strSql.Append("Name)");
            strSql.Append(" values (");
            strSql.Append("@Name)");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@Name", OleDbType.VarChar, 50)
            };
            parameters[0].Value = model.Name;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
 private void frmEditUnit_Load(object sender, EventArgs e)
 {
     Dong.BLL.Unit   bll   = new Dong.BLL.Unit();
     Dong.Model.Unit model = new Dong.Model.Unit();
     model = bll.GetModel(int.Parse(this.Tag.ToString()));
     if (model != null)
     {
         txtUnit.Text = model.Name;
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Dong.Model.Unit DataRowToModel(DataRow row)
 {
     Dong.Model.Unit model = new Dong.Model.Unit();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["Name"] != null)
         {
             model.Name = row["Name"].ToString();
         }
     }
     return(model);
 }
Esempio n. 6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Dong.Model.Unit GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Id,Name from Unit ");
            strSql.Append(" where Id=@Id");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@Id", OleDbType.Integer, 4)
            };
            parameters[0].Value = Id;

            Dong.Model.Unit model = new Dong.Model.Unit();
            DataSet         ds    = DbHelperOleDb.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }