Beispiel #1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMachatlieu.Text.Trim().Length == 0 || txtTenchatlieu.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn chưa nhập dữ liệu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // Kiểm tra key Mã Chất Liệu
                sql = "Select MaChatlieu From tblChatlieu where MaChatlieu='" + txtMachatlieu.Text.Trim() + "'";
                if (FunctionConnect.checkkey(sql))
                {
                    MessageBox.Show("Mã chất liệu hiện tại đang tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtMachatlieu.Focus();
                    return;
                }

                // Thêm dữ liệu
                if (MessageBox.Show("Bạn có muốn thêm không", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    sql = "INSERT INTO tblChatlieu (Machatlieu, Tenchatlieu) VALUES ('" + txtMachatlieu.Text + "','" + txtTenchatlieu.Text + "')";
                    FunctionConnect.runsql(sql);
                    Load_DataGridView();

                    MessageBox.Show("Thêm thành công !");

                    txtMachatlieu.Enabled = false;
                    btnLuu.Enabled        = false;
                    btnBoqua.Enabled      = false;
                }
            }
        }
Beispiel #2
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMachatlieu.Text.Trim().Length == 0 || txtTenchatlieu.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn chưa nhập dữ liệu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                sql = "SELECT Machatlieu From tblChatlieu where Machatlieu ='" + txtMachatlieu.Text.Trim() + "'";
                if (FunctionConnect.checkkey(sql))
                {
                    MessageBox.Show("Thông tin bạn cập nhập đã tồn tại !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtMachatlieu.Focus();
                    return;
                }
                if (MessageBox.Show("Bạn có muốn sửa không ?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    sql = "UPDATE tblChatlieu Tenchatlieu = '" + txtTenchatlieu.Text + "' WHERE Machatlieu = '" + txtMachatlieu.Text + "'";
                    FunctionConnect.runsql(sql);
                    Load_DataGridView();

                    MessageBox.Show("Sửa thành công !");

                    //txtMachatlieu.Enabled = false;
                    btnLuu.Enabled   = false;
                    btnBoqua.Enabled = false;
                }
            }
        }
Beispiel #3
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                if (chkGioitinh.CheckState == CheckState.Checked)
                {
                    gioitinh = "Nam";
                }
                else if (chkGioitinh.CheckState == CheckState.Unchecked)
                {
                    gioitinh = "Nữ";
                }

                string sql;
                if (txtManhanvien.Text.Trim().Length == 0 || txtTennhanvien.Text.Trim().Length == 0 ||
                    txtDiachi.Text.Trim().Length == 0 || mskDienthoai.Text.Trim().Length == 0)
                {
                    MessageBox.Show("Bạn cần điền đầy đủ thông tin \nĐể có thể lưu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    sql = "SELECT Manhanvien FROM tblNhanvien WHERE Manhanvien ='" + txtManhanvien.Text.Trim() + "'";
                    if (FunctionConnect.checkkey(sql))
                    {
                        MessageBox.Show("Mã bạn muốn lưu đã tồn tại ! \nVui lòng chọn mã khácƯ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtManhanvien.Focus();
                        return;
                    }
                    if (MessageBox.Show("Bạn có muốn lưu không ?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        sql = "INSERT INTO " +
                              "tblNhanvien (Manhanvien, Tennhanvien, Gioitinh, Diachi, Dienthoai, Ngaysinh) " +
                              "VALUES ('" + txtManhanvien.Text + "','" + txtTennhanvien.Text + "','" + gioitinh + "','" + txtDiachi.Text + "','" + mskDienthoai.Text + "','" + mskNgaysinh.Value.ToString("yyyy/MM/dd") + "')";
                        FunctionConnect.runsql(sql);
                        Load_DataGridView();
                        MessageBox.Show("Thêm thành công !");

                        Disable_Entity();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Có lỗi: ", ex.Message);
            }
        }
Beispiel #4
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     try
     {
         string sql;
         if (txtMahang.Text.Trim().Length == 0 || txtTenhang.Text.Trim().Length == 0 ||
             txtDongianhap.Text.Trim().Length == 0 || txtDongiaban.Text.Trim().Length == 0)
         {
             MessageBox.Show("Bạn cần điền đầy đủ thông tin \nĐể có thể lưu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             sql = "SELECT Mahang FROM tblHang WHERE Mahang ='" + txtMahang.Text.Trim() + "'";
             if (FunctionConnect.checkkey(sql))
             {
                 MessageBox.Show("Mã bạn muốn lưu đã tồn tại ! \nVui lòng chọn mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 txtMahang.Focus();
                 return;
             }
             if (MessageBox.Show("Bạn có muốn lưu không ?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 sql = "INSERT INTO " +
                       "tblHang (Mahang, Tenhang, Machatlieu, Soluong, Dongianhap, Dongiaban, Anh, Ghichu) " +
                       "VALUES ('" + txtMahang.Text + "','" + txtTenhang.Text + "','" + cboMachatlieu.Text + "','" + txtSoluong.Text + "','" + txtDongianhap.Text + "','" + txtDongiaban.Text + "','" + txtAnh.Text + "','" + txtGhichu.Text + "')";
                 FunctionConnect.runsql(sql);
                 Load_DataGridView();
                 MessageBox.Show("Thêm thành công !");
             }
             Disable_Enitity();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Đã xảy ra lỗi trong quá trình lưu lưu phát sinh lỗi ! \nError: " + ex.Message);
     }
 }
Beispiel #5
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     try
     {
         string sql;
         if (txtMakhach.Text.Trim().Length == 0 || txtTenkhach.Text.Trim().Length == 0 ||
             txtDiachi.Text.Trim().Length == 0 || mskDienthoai.Text.Trim().Length == 0)
         {
             MessageBox.Show("Bạn cần điền đầy đủ thông tin \nĐể có thể lưu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             sql = "SELECT Makhach FROM tblKhach WHERE Makhach ='" + txtMakhach.Text.Trim() + "'";
             if (FunctionConnect.checkkey(sql))
             {
                 MessageBox.Show("Mã khách bạn muốn lưu đã tồn tại ! \nVui lòng chọn mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 txtMakhach.Focus();
                 return;
             }
             if (MessageBox.Show("Bạn có muốn lưu không ?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 sql = "INSERT INTO " +
                       "tblKhach (Makhach, Tenkhach, Diachi, Dienthoai) " +
                       "VALUES ('" + txtMakhach.Text + "','" + txtTenkhach.Text + "','" + txtDiachi.Text + "','" + mskDienthoai.Text + "')";
                 FunctionConnect.runsql(sql);
                 Load_DataGridView();
                 MessageBox.Show("Thêm thành công !");
             }
         }
         Disable_Button();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Có lỗi: ", ex.Message);
     }
 }