Ejemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">The model<see cref="Model.ContactGroup"/></param>
        /// <returns>The <see cref="bool"/></returns>
        public bool Add(Model.ContactGroup model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ContactGroup(");
            strSql.Append("GroupName,Memo)");
            strSql.Append(" values (");
            strSql.Append("@GroupName,@Memo)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@GroupName", SqlDbType.NVarChar, 50),
                new SqlParameter("@Memo",      SqlDbType.NVarChar, 200)
            };
            parameters[0].Value = model.GroupName;
            parameters[1].Value = model.Memo;

            int rows = SqlDbHelper.ExecuteNonQuery(strSql.ToString(), CommandType.Text, parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新分组信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(Model.ContactGroup model)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("update ContactGroup set ");
            sql.Append("GroupName=@GroupName,[Memo]=@Memo ");
            sql.Append("where Id=@Id");

            OleDbParameter[] para =
            {
                new OleDbParameter("@GroupName", OleDbType.VarChar,  50),
                new OleDbParameter("@Memo",      OleDbType.VarChar, 200),
                new OleDbParameter("@id",        OleDbType.Integer, 4)
            };
            para[0].Value = model.GroupName;
            para[1].Value = model.Memo;
            para[2].Value = model.Id;

            int n = OleDbHelper.ExecuteNonQuery(sql.ToString(), para);

            if (n > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Add(Model.ContactGroup model)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("insert into ContactGroup ");
            sql.Append("values(@GroupName,@Memo);");
            sql.Append("select @@IDENTITY");    // 得到上一次插入记录时自动产生的ID

            SqlParameter[] para =
            {
                new SqlParameter("@GroupName", SqlDbType.NVarChar, 50),
                new SqlParameter("@Memo",      SqlDbType.NVarChar, 200)
            };
            para[0].Value = model.GroupName;
            para[1].Value = model.Memo;
            int n = SqlDbHelper.ExecuteNonQuery(sql.ToString(), para);

            if (n > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Add(Model.ContactGroup model)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("insert into ContactGroup(GroupName,[Memo]) ");
            sql.Append("values(@GroupName,@Memo)");
            //sql.Append("select @@IDENTITY");    // Access 只支持一次一条SQL

            OleDbParameter[] para =
            {
                new OleDbParameter("@GroupName", OleDbType.VarChar, 50),
                new OleDbParameter("@Memo",      OleDbType.VarChar, 200)
            };
            para[0].Value = model.GroupName;
            para[1].Value = model.Memo;
            int n = OleDbHelper.ExecuteNonQuery(sql.ToString(), para);

            if (n > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.ContactGroup model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ContactGroup(");
            strSql.Append("GroupName,[Memo])");
            strSql.Append(" values(");
            strSql.Append("@GroupName,@Memo)");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@GroupName", OleDbType.VarChar, 50),
                new OleDbParameter("@Memo",      OleDbType.VarChar, 200)
            };
            parameters[0].Value = model.GroupName;
            parameters[1].Value = model.Memo;

            int rows = OleDbHelper.ExecuteNonQuery(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// The Update
        /// </summary>
        /// <param name="model">The model<see cref="Model.ContactGroup"/></param>
        /// <returns>The <see cref="bool"/></returns>
        public bool Update(Model.ContactGroup model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ContactGroup set ");
            strSql.Append("GroupName=@GroupName,");
            strSql.Append("Memo=@Memo");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@GroupName", SqlDbType.NVarChar,  50),
                new SqlParameter("@Memo",      SqlDbType.NVarChar, 200),
                new SqlParameter("@Id",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.GroupName;
            parameters[1].Value = model.Memo;
            parameters[2].Value = model.Id;

            int rows = SqlDbHelper.ExecuteNonQuery(strSql.ToString(), CommandType.Text, parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
 public bool Update(Model.ContactGroup model, out string msg)
 {
     if (!CheckModel(model, out msg))
     {
         return(false);
     }
     else
     {
         return(group.Update(model));
     }
 }
Ejemplo n.º 8
0
        public bool CheckModel(Model.ContactGroup model, out string msg)
        {
            bool check = true;

            msg = "";
            if (model.GroupName == "")
            {
                msg   = "分组名称不能为空";
                check = false;
            }
            return(check);
        }
Ejemplo n.º 9
0
 private void FormGroupDetail_Load(object sender, EventArgs e)
 {
     txtId.Text = id.ToString();
     BLL.ContactGroup   bll   = new BLL.ContactGroup();
     Model.ContactGroup model = bll.GetModel(id);
     if (model == null)
     {
         MessageBox.Show("数据出错");
         return;
     }
     else
     {
         txtGroupName.Text = model.GroupName;
         txtGroupMemo.Text = model.Memo;
     }
 }
Ejemplo n.º 10
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     Model.ContactGroup model = new Model.ContactGroup();
     model.GroupName = txtGroupName .Text.Trim();
     model.Memo = txtGroupMemo.Text.Trim();
     BLL.ContactGroup bll = new BLL.ContactGroup();
     string msg;
     if (bll.Add(model, out msg))
     {
         MessageBox.Show ("添加分组信息成功");
     }
     else
     {
         MessageBox.Show(msg );
     }
 }
Ejemplo n.º 11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Model.ContactGroup model = new Model.ContactGroup();
            model.GroupName = txtGroupName.Text.Trim();
            model.Memo      = txtGroupMemo.Text.Trim();
            BLL.ContactGroup bll = new BLL.ContactGroup();
            string           msg;

            if (bll.Add(model, out msg))
            {
                MessageBox.Show("添加分组成功!");
            }
            else
            {
                MessageBox.Show(msg);
            }
        }
Ejemplo n.º 12
0
 public bool Add(Model.ContactGroup model, out string msg)
 {
     if (!CheckModel(model, out msg))
     {
         return(false);
     }
     else
     {
         Model.ContactGroup modelcheck = GetModel(model.GroupName);
         if (modelcheck != null)
         {
             msg = "分组名称重复";
             return(false);
         }
         else
         {
             return(group.Add(model));
         }
     }
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 根据分组编号获取分组信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.ContactGroup GetModel(int Id)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("select top 1 Id,GroupName,[Memo] from ContactGroup ");
            sql.Append("where Id = @id");

            OleDbParameter[] para =
            {
                new OleDbParameter("@id", OleDbType.Integer, 4)
            };
            para[0].Value = Id;

            Model.ContactGroup model = new Model.ContactGroup();
            DataTable          dt    = OleDbHelper.ExecuteDataTable(sql.ToString(), para);

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["Id"] != null && dt.Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(dt.Rows[0]["Id"].ToString());
                }
                if (dt.Rows[0]["GroupName"] != null && dt.Rows[0]["GroupName"].ToString() != "")
                {
                    model.GroupName = dt.Rows[0]["GroupName"].ToString();
                }
                if (dt.Rows[0]["Memo"] != null && dt.Rows[0]["Memo"].ToString() != "")
                {
                    model.Memo = dt.Rows[0]["Memo"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 根据分组名称获取分组信息
        /// </summary>
        /// <param name="groupName"></param>
        /// <returns></returns>
        public Model.ContactGroup GetModel(string groupName)
        {
            StringBuilder sql = new StringBuilder();

            sql.Append("select top 1 Id,GroupName,Memo from ContactGroup ");
            sql.Append("where GroupName = @GroupName");

            SqlParameter[] para =
            {
                new SqlParameter("@GroupName", SqlDbType.NVarChar, 50)
            };
            para[0].Value = groupName;

            Model.ContactGroup model = new Model.ContactGroup();
            DataTable          dt    = SqlDbHelper.ExecuteDataTable(sql.ToString(), para);

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["Id"] != null && dt.Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(dt.Rows[0]["Id"].ToString());
                }
                if (dt.Rows[0]["GroupName"] != null && dt.Rows[0]["GroupName"].ToString() != "")
                {
                    model.GroupName = dt.Rows[0]["GroupName"].ToString();
                }
                if (dt.Rows[0]["Memo"] != null && dt.Rows[0]["Memo"].ToString() != "")
                {
                    model.Memo = dt.Rows[0]["Memo"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// The GetModel
        /// </summary>
        /// <param name="Id">The Id<see cref="int"/></param>
        /// <returns>The <see cref="Model.ContactGroup"/></returns>
        public Model.ContactGroup GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,GroupName,Memo from ContactGroup ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            Model.ContactGroup model = new Model.ContactGroup();
            DataTable          dt    = SqlDbHelper.ExecuteDataTable(strSql.ToString(), CommandType.Text, parameters);

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["Id"] != null && dt.Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(dt.Rows[0]["Id"].ToString());
                }
                if (dt.Rows[0]["GroupName"] != null && dt.Rows[0]["GroupName"].ToString() != "")
                {
                    model.GroupName = dt.Rows[0]["GroupName"].ToString();
                }
                if (dt.Rows[0]["Memo"] != null && dt.Rows[0]["Memo"].ToString() != "")
                {
                    model.Memo = dt.Rows[0]["Memo"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 16
0
        //根据分组编号,获取分组信息
        public Model.ContactGroup GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 Id, GroupName, Memo from [ContactGroup] ");
            strSql.Append("where Id = @Id ");
            SqlParameter[] parameters ={ new SqlParameter ("@Id", SqlDbType.Int, 4) };
            parameters[0].Value = Id;

            Model.ContactGroup model = new Model.ContactGroup();
            DataTable dt = SqlDbHelper.ExecuteDataTable(strSql.ToString(),
                                   CommandType.Text, parameters);
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["Id"] != null && dt.Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(dt.Rows[0]["Id"].ToString());
                }
                if (dt.Rows[0]["GroupName"] != null && dt.Rows[0]["GroupName"].ToString() != "")
                {
                    model.GroupName = dt.Rows[0]["GroupName"].ToString();
                }
                if (dt.Rows[0]["Memo"] != null && dt.Rows[0]["Memo"].ToString() != "")
                {
                    model.Memo = dt.Rows[0]["Memo"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 17
0
        //////////根据分组名称,获取分组信息
        public Model.ContactGroup GetModel(string groupName)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 Id,GroupName,Memo from ContactGroup  ");
            strSql.Append("where GroupName=@GroupName ");
            OleDbParameter[] parameters ={
                           new OleDbParameter ("@GroupName",OleDbType.VarChar,50) };

            parameters[0].Value = groupName;
            Model.ContactGroup model = new Model.ContactGroup();
            DataTable dt = OleDbHelper.ExecuteDataTable(strSql.ToString(), parameters);
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["Id"] != null && dt.Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(dt.Rows[0]["Id"].ToString());
                }
                if (dt.Rows[0]["GroupName"] != null && dt.Rows[0]["GroupName"].ToString() != "")
                {
                    model.GroupName = dt.Rows[0]["GroupName"].ToString();
                }
                if (dt.Rows[0]["Memo"] != null && dt.Rows[0]["Memo"].ToString() != "")
                {
                    model.Memo = dt.Rows[0]["Memo"].ToString();
                }
                return model;

            }
            else
            {
                return null;
            }
        }