public static void ThemPhongBan(PhongBan phongban)
        {
            string     sql = "insert into PHONGBAN(MaPB, TenPB, DiaChi, MaTP, TenTP) values(@mapb, @tenpb, @diachi, @matp, @tentp)";
            SqlCommand cmd = new SqlCommand(sql, conn);

            using (SqlCommand command = new SqlCommand(sql, conn))
            {
                command.Parameters.Add(new SqlParameter("@mapb", phongban.Mapb));
                command.Parameters.Add(new SqlParameter("@tenpb", phongban.Tenpb));
                command.Parameters.Add(new SqlParameter("@diachi", phongban.Diachi));
                command.Parameters.Add(new SqlParameter("@matp", phongban.Matp));
                command.Parameters.Add(new SqlParameter("@tentp", phongban.Tentp));

                int kq = command.ExecuteNonQuery();
                if (kq > 0)
                {
                    MessageBox.Show("Thêm phòng ban mới thành công!");
                }
                else
                {
                    MessageBox.Show("Thêm phòng ban mới thất bại!");
                }
                command.Cancel();
            }
        }
Ejemplo n.º 2
0
        private void btnThemPB_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    if (!db.KiemTra(txtMaPB.Text, "select MaPB from PhongBan"))
            //    {
            //        PhongBan temp = new PhongBan(txtMaPB.Text, txtTenPB.Text, txtDiaChi.Text, txtmaTP.Text, txtTenTp.Text);

            //        ConnectDatabase.ThemPhongBan(temp);
            //        load();
            //    }
            //    else
            //    {
            //        MessageBox.Show("Mã phòng này đã tòn tại bạn có thể thử mã phòng khác", "Trùng mã phòng", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    }
            //}
            //catch
            //{
            //    MessageBox.Show("Dữ liệu đầu vào không đúng");
            //}
            PhongBan temp = new PhongBan(txtMaPB.Text, txtTenPB.Text, txtDiaChi.Text, txtmaTP.Text, txtTenTp.Text);

            ConnectDatabase.ThemPhongBan(temp);
            load();
        }
        private void btnSuaPB_Click(object sender, EventArgs e)
        {
            PhongBan temp = new PhongBan(txtMPB.Text, txtTenPB.Text, txtdiadiem.Text, txtmaTP.Text, txtTenTP.Text);

            ConnectDatabase.SuaPhongBan(temp);
            dgvPhongBan.DataSource = ConnectDatabase.getAllPhongBan();
        }
        private void btnXoaPB_Click(object sender, EventArgs e)
        {
            PhongBan temp = new PhongBan(txtMPB.Text, txtTenPB.Text, txtdiadiem.Text, txtmaTP.Text, txtTenTP.Text);

            ConnectDatabase.XoaPhongBan(temp);
            dgvPhongBan.DataSource = ConnectDatabase.getAllPhongBan();
            MessageBox.Show("Xóa Phòng Ban Thành Công!!!");
        }
Ejemplo n.º 5
0
        private void XoaPhongBan()
        {
            PhongBan pb = db.PhongBans.Where(n => n.IDPhong == int.Parse(txtIDPhong.Text)).First();

            db.PhongBans.DeleteOnSubmit(pb);
            db.SubmitChanges();
            LoadDataPhongBan();
        }
        public static void XoaPhongBan(PhongBan pb)
        {
            string sql = "DELETE FROM PHONGBAN  where MaPB=@mapb";

            using (SqlCommand command = new SqlCommand(sql, conn))
            {
                command.Parameters.Add(new SqlParameter("@mapb", pb.Mapb));
                command.ExecuteNonQuery();
                command.Cancel();
            }
        }
Ejemplo n.º 7
0
        private void ThemPhongBan()
        {
            PhongBan pb = new PhongBan();

            pb.IDPhong       = db.PhongBans.Select(n => n.IDPhong).Max() + 1;
            pb.IDTruongPhong = null;
            pb.TenPhong      = txtTenPhong.Text;
            db.PhongBans.InsertOnSubmit(pb);
            db.SubmitChanges();
            ChiDoc();
            LoadDataPhongBan();
        }
Ejemplo n.º 8
0
 private void btnThemPB_Click(object sender, EventArgs e)
 {
     PhongBan temp = new PhongBan(txtMaPB.Text, txtTenPB.Text, txtDiaChi.Text, txtmaTP.Text, txtTenTp.Text);
     {
         if (ConnectDatabase.checkPhongBan(temp.Mapb) == 1)
         {
             MessageBox.Show("Mã phòng ban đã tồn tại. Xin mời nhập lại!!!");
             return;
         }
         ConnectDatabase.ThemPhongBan(temp);
         dgvThemPB.DataSource = ConnectDatabase.getAllPhongBan();
         load();
     }
 }
        public static void SuaPhongBan(PhongBan pb)
        {
            string sql = "UPDATE PHONGBAN set TenPB=@tenpb, DiaChi=@diadiem,MaTP=@matp,  TenTP=@tentp where MaPB=@mapb";

            using (SqlCommand command = new SqlCommand(sql, conn))
            {
                command.Parameters.Add(new SqlParameter("@tenpb", pb.Tenpb));
                command.Parameters.Add(new SqlParameter("@diadiem", pb.Diachi));
                command.Parameters.Add(new SqlParameter("@tentp", pb.Tentp));
                command.Parameters.Add(new SqlParameter("@matp", pb.Matp));
                command.Parameters.Add(new SqlParameter("@mapb", pb.Mapb));
                command.ExecuteNonQuery();
                command.Cancel();
            }
        }
Ejemplo n.º 10
0
        private void SuaPhongBan()
        {
            PhongBan pb = db.PhongBans.Where(n => n.IDPhong == int.Parse(txtIDPhong.Text)).First();

            pb.TenPhong = txtTenPhong.Text;
            if (cboTruongPhong.Text == "")
            {
                pb.IDTruongPhong = null;
            }
            else
            {
                pb.IDTruongPhong = (int)cboTruongPhong.SelectedValue;
            }
            db.SubmitChanges();
            ChiDoc();
            LoadDataPhongBan();
        }
Ejemplo n.º 11
0
 partial void DeletePhongBan(PhongBan instance);
Ejemplo n.º 12
0
 partial void UpdatePhongBan(PhongBan instance);
Ejemplo n.º 13
0
 partial void InsertPhongBan(PhongBan instance);