Ejemplo n.º 1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //接收界面参数
            building t = new building();

            t.buildId   = int.Parse(this.txtTypeId.Text);
            t.buildName = this.txtTypeName.Text;
            t.dormCount = this.txtMemo.Text;
            t.dromFloor = this.txtdormFloor.Text;
            string reply1 = "亲,楼层名不能为空哦!";
            string reply2 = "亲,人数不能为空哦!";
            string reply3 = "亲,所在楼层不能为空哦!";

            //文本框校验
            if (Validation.checktxt(t.buildName, ref reply1))
            {
                return;
            }
            if (Validation.checktxt(t.dormCount, ref reply2))
            {
                return;
            }
            if (Validation.checktxt(t.dromFloor, ref reply3))
            {
                return;
            }
            wsm.update(t);

            //刷新manager窗体的dgv
            //SingleWindow.ttmf.flush();

            //关闭当前窗体
            this.Close();
            MessageBox.Show("修改成功!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
Ejemplo n.º 2
0
        public void update(building t)
        {
            SqlConnection conn = new SqlConnection("server=" + MyGlobal.ip + ";database=dormitory;UID=sa;PWD=zyh@197068;Integrated Security=False");

            conn.Open();
            string        mysql  = string.Format("update building set buildName = '{0}',dormCount = '{1}',dormFloor = '{2}' where buildId = {3}", t.buildName, t.dormCount, t.dromFloor, t.buildId);
            SqlCommand    sql    = new SqlCommand(mysql, conn);
            SqlDataReader reader = sql.ExecuteReader();

            reader.Close();
            conn.Close();
        }
Ejemplo n.º 3
0
        //专门用来添加数据的方法
        /// sql语句可以连接数据库进行操作数据
        public void insert(building t)
        {
            SqlConnection conn = new SqlConnection("server=" + MyGlobal.ip + ";database=dormitory;UID=sa;PWD=zyh@197068;Integrated Security=False");

            conn.Open();
            string        mysql  = string.Format("insert into building(buildName,dormCount,dormFloor) values('{0}','{1}','{2}')", t.buildName, t.dormCount, t.dromFloor);
            SqlCommand    sql    = new SqlCommand(mysql, conn);
            SqlDataReader reader = sql.ExecuteReader();

            reader.Close();
            conn.Close();
        }
Ejemplo n.º 4
0
        /*****************变量声明结束*******************************/

        public void flush()
        {
            //创建实体类对象
            building t = new building();

            //处理界面参数
            t.buildName = this.txtDromName.Text;
            //查询总条数
            page.count = wsm.count(t);
            //将数据库中的内容显示到界面上
            this.dgvbuilding.DataSource = wsm.findAll(t, page);

            //给页面上的控件赋值
            this.lblPage.Text = "当前:" + page.nowPage + "页   共:" + page.getTotalPage() + "页  总计:" + page.count + "条";
        }
Ejemplo n.º 5
0
        public int count(building t)
        {
            SqlConnection conn = new SqlConnection("server=" + MyGlobal.ip + ";database=dormitory;UID=sa;PWD=zyh@197068;Integrated Security=False");

            conn.Open();
            string        mysql  = string.Format("select * from building where buildName like '%{0}%'", t.buildName);
            SqlCommand    sql    = new SqlCommand(mysql, conn);
            SqlDataReader reader = sql.ExecuteReader();
            DataTable     dt     = new DataTable();

            while (reader.Read())//决定行数
            {
                dt.Columns.Add(reader.ToString());
            }
            reader.Close();
            conn.Close();
            return(dt.Rows.Count);
        }
Ejemplo n.º 6
0
        public DataTable findAll(building t, PageHelper page)
        {
            SqlConnection conn = new SqlConnection("server=" + MyGlobal.ip + ";database=dormitory;UID=sa;PWD=zyh@197068;Integrated Security=False");

            conn.Open();
            string        mysql  = string.Format("select * from building where buildName like '%{0}%' order by buildId asc limit {1},{2} ", t.buildName, page.getBegin(), page.pageSize);
            SqlCommand    sql    = new SqlCommand(mysql, conn);
            SqlDataReader reader = sql.ExecuteReader();
            DataTable     dt     = new DataTable();

            while (reader.Read())//决定行数
            {
                dt.Columns.Add(reader.ToString());
            }
            reader.Close();
            conn.Close();
            return(dt);
        }
Ejemplo n.º 7
0
        public void delete(building t)
        {
            SqlConnection conn = new SqlConnection("server=" + MyGlobal.ip + ";database=dormitory;UID=sa;PWD=zyh@197068;Integrated Security=False");

            conn.Open();
            string        mysql = string.Format("delete from building where buildId = {0}", t.buildId);
            SqlCommand    sql   = new SqlCommand(mysql, conn);
            SqlDataReader reader;

            try
            {
                reader = sql.ExecuteReader();
                reader.Close();
                conn.Close();
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("该项正在被使用,无法删除!", "温馨提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk);
            }
        }