Exemplo n.º 1
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool w = false;
            //MD5Helper mD5 = new MD5Helper();
            Managerinfo managerinfo = new Managerinfo()
            {
                MId   = Convert.ToInt32(textBox1.Text.Trim()),
                Mname = txtname.Text.Trim(),
                Mpwd  = txtpwd.Text,
                MType = type0.Checked ? 0 : 1
            };

            if (btnSave.Text == "添加")
            {
                w = mibll.Addlist(managerinfo);
            }
            if (btnSave.Text == "保存")
            {
                w = mibll.UpdateList(managerinfo);
            }
            if (w)
            {
                //MessageBox.Show("插入成功");
                dataGridView1.DataSource = mibll.Getlist();
            }
            else
            {
                MessageBox.Show("插入失败!");
                btnmiss_Click(null, null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 返回查询的数据
        /// </summary>
        /// <returns></returns>
        public List <Managerinfo> GetList(Managerinfo mi)
        {
            List <Managerinfo>  list = new List <Managerinfo>();
            List <SqlParameter> pms  = new List <SqlParameter>();
            //SqlParameter[] pms=new SqlParameter[2];
            string sql = "select * from managerinfo ";

            if (mi != null)
            {
                sql += " where Mname= @Mname and MPwd=@MPwd";
                pms.Add(new SqlParameter("Mname", mi.Mname));
                pms.Add(new SqlParameter("MPwd", MD5Helper.GetMD5(mi.Mpwd)));
            }
            DataTable table = SqlHelper.GetList(sql, pms.ToArray());

            foreach (DataRow row in table.Rows)
            {
                list.Add(new Managerinfo()
                {
                    MId   = Convert.ToInt32(row["mid"]),
                    Mname = row["mname"].ToString(),
                    Mpwd  = row["mpwd"].ToString(),
                    MType = Convert.ToInt32(row["mtype"])
                });
            }
            return(list);
        }
Exemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //根据接收控件的值,用于构造对象。
            Managerinfo mi = new Managerinfo()
            {
                MName = txtName.Text,
                MPwd  = txtPwd.Text,
                MType = rb1.Checked ? 1 : 0,
            };

            //判断当前是应该执行添加操作,还是执行修改操作
            if (btnSave.Text == "添加")
            {
                if (miBll.Add(mi))
                {
                    LoadList();
                }
                else
                {
                    MessageBox.Show("添加失败,请稍后重试!");
                }
            }
            else
            {
                mi.MId = Convert.ToInt32(txtId.Text);
                if (miBll.Edit(mi))
                {
                    LoadList();
                }
                else
                {
                    MessageBox.Show("修改失败!请稍后重试!");
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 增加数据
        /// </summary>
        /// <param name="mi">数据对象</param>
        /// <returns></returns>
        public int Addlist(Managerinfo mi)
        {
            //string sql = "insert into managerinfo values(@MName,@MPwd,@MType)";
            SqlParameter[] pms =
            {
                new SqlParameter("@MName", mi.Mname),
                new SqlParameter("@MPwd",  MD5Helper.GetMD5(mi.Mpwd)),
                new SqlParameter("@MType", mi.MType)
            };
            int s = SqlHelper.AddList("insert into managerinfo values(@MName,@MPwd,@MType)", pms);

            return(s);
        }
Exemplo n.º 5
0
        public bool UpdateList(Managerinfo mi)
        {
            int r = miDal.Updatelist(mi);

            if (r > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 增加数据
        /// </summary>
        /// <param name="mi"></param>
        /// <returns></returns>
        public bool Addlist(Managerinfo mi)
        {
            int r = miDal.Addlist(mi);

            if (r > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        public bool Login(Managerinfo mi)
        {
            var list = miDal.GetList(mi);

            if (list.Count > 0)
            {
                mi.MType = list[0].MType;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 8
0
        public int Update(Managerinfo mi)
        {
            //这里要注意,密码是否修改必须判断后,进行不同的处理!
            string sql = "update Managerinfo set mid=@id,mname=@name,";
            List <SQLiteParameter> list = new List <SQLiteParameter>();

            list.Add(new SQLiteParameter("@id", mi.MId));
            list.Add(new SQLiteParameter("@name", mi.MName));
            if (!mi.MPwd.Equals("******"))
            {
                sql += "mpwd=@pwd,";
                list.Add(new SQLiteParameter("@pwd", MD5Helper.GetMd5(mi.MPwd)));
            }
            sql += "mtype=@type where mid=@id";
            list.Add(new SQLiteParameter("@type", mi.MType));

            return(SqliteHelper.ExecuteNonQuery(sql, list.ToArray()));
            //int b = -1;
            //if (mi.MPwd.Equals("******"))
            //{
            //    sql += "mtype=@type where mid=@id";
            //    SQLiteParameter[] ps =
            //   {
            //    new SQLiteParameter("@id",mi.MId),
            //    new SQLiteParameter("@name",mi.MName),
            //    new SQLiteParameter("@type",mi.MType),
            //    };
            //    b = SqliteHelper.ExecuteNonQuery(sql, ps);
            //}
            //else
            //{
            //    sql += "mpwd=@pwd,mtype=@type where mid=@id";
            //    SQLiteParameter[] ps =
            //   {
            //    new SQLiteParameter("@id",mi.MId),
            //    new SQLiteParameter("@name",mi.MName),
            //    new SQLiteParameter("@pwd",MD5Helper.GetMd5(mi.MPwd)),
            //    new SQLiteParameter("@type",mi.MType),
            //   };
            //    b = SqliteHelper.ExecuteNonQuery(sql, ps);
            //}

            //return b;
        }
Exemplo n.º 9
0
        public int Insert(Managerinfo mi)
        {
            #region 构造sql语句(这个里面的都是,有语句,还要有参数)
            //1.构造insert语句
            //sqlite要求插入的列必须指定
            string sql = "insert into Managerinfo(mname,mpwd,mtype) values(@name,@pwd,@type)";
            //数组初始化器

            SQLiteParameter[] ps =
            {
                new SQLiteParameter("@name", mi.MName),
                new SQLiteParameter("@pwd",  MD5Helper.GetMd5(mi.MPwd)),
                new SQLiteParameter("@type", mi.MType),
            };
            #endregion

            //执行
            return(SqliteHelper.ExecuteNonQuery(sql, ps));
        }
Exemplo n.º 10
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="mi"></param>
        /// <returns></returns>
        public int Updatelist(Managerinfo mi)
        {
            string sql = "update managerinfo set Mname=@Mname,";

            if (!mi.Mpwd.Equals("********"))
            {
                sql += "Mpwd=@Mpwd,";
            }
            sql += "Mtype=@Mtype where Mid=@Mid";
            SqlParameter[] pms =
            {
                new SqlParameter("@Mid",   mi.MId),
                new SqlParameter("@Mname", mi.Mname),
                new SqlParameter("@Mpwd",  MD5Helper.GetMD5(mi.Mpwd)),
                new SqlParameter("@MType", mi.MType)
            };
            int s = SqlHelper.updatelist(sql, pms);

            return(s);
        }
Exemplo n.º 11
0
        private void button1_Click(object sender, EventArgs e)
        {
            Managerinfo managerinfo = new Managerinfo
            {
                Mname = textBox1.Text.Trim(),
                Mpwd  = textBox2.Text.Trim()
            };
            managerinfobll managerinfobll = new managerinfobll();

            if (managerinfobll.Login(managerinfo))
            {
                MainForm mainForm = new MainForm();
                mainForm.Tag = managerinfo.MType;
                mainForm.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("失败");
            }
        }
Exemplo n.º 12
0
        public List <Managerinfo> GetList(Managerinfo mi)
        {
            //构造sql语句
            string sql = "select * from Managerinfo";
            //拼接查询,得到结果
            List <SQLiteParameter> listP = new List <SQLiteParameter>();

            if (mi != null)
            {
                sql += " where mname=@name and mpwd=@pwd";
                listP.Add(new SQLiteParameter("@name", mi.MName));
                listP.Add(new SQLiteParameter("@pwd", MD5Helper.GetMd5(mi.MPwd)));
            }


            //执行查询,获取数据
            DataTable table = SqliteHelper.GetList(sql, listP.ToArray());


            //构造集合对象
            //定义一个集合用于转存数据
            List <Managerinfo> list = new List <Managerinfo>();

            //逐行遍历数据,将表中的数据存到集合中
            foreach (DataRow row in table.Rows)
            {
                //1.list.Add()
                //2.new Managerinfo()
                //3.对象的初始化
                list.Add(new Managerinfo()
                {
                    MId   = Convert.ToInt32(row["mid"]),
                    MName = row["mname"].ToString(),
                    MPwd  = row["mpwd"].ToString(),
                    MType = Convert.ToInt32(row["mtype"])
                });
            }
            //返回数据
            return(list);
        }
Exemplo n.º 13
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            Managerinfo mi = new Managerinfo();

            mi.MName = txtName.Text;
            mi.MPwd  = txtPwd.Text;

            ManagerinfoBll miBll = new ManagerinfoBll();

            if (miBll.Login(mi))
            {
                //登录成功,打开主窗体
                MainForm mainForm = new MainForm();
                mainForm.Tag = mi.MType;
                mainForm.Show();
                this.Visible = false;
            }
            else
            {
                MessageBox.Show("用户名或密码错误!");
            }
        }
Exemplo n.º 14
0
 public bool Edit(Managerinfo mi)
 {
     return(miDal.Update(mi) > 0);
 }
Exemplo n.º 15
0
 //接受一个对象,层与层之间通过Model层的对象传递
 public bool Add(Managerinfo mi)
 {
     return(miDal.Insert(mi) > 0);
 }