Exemplo n.º 1
0
        private void btn_restore_Click(object sender, EventArgs e)
        {
            string database = Unity.con.Database.ToString();

            try
            {
                if (btn_restore.Text == string.Empty)
                {
                    MessageBox.Show("Chưa chọn file retore CSDL");
                }
                else
                {
                    //mở kế nối
                    Unity.OpenConnection();
                    //string cmd = "BACKUP DATABASE [ " + database + "] TO DISK ='"+txt_backupFileLoc.Text+"\\"+"Database"+"-"+DateTime.Now.ToString("yyyy-mm-dd")+".bak'";
                    string cmd = "restore database " + database + " from  DISK ='" + txt_RestoreFileLoc.Text + "'";
                    MessageBox.Show(cmd);
                    //Unity.Excute(cmd);
                    Unity.con.Close();
                    MessageBox.Show("Restore thành công.");
                    btn_restore.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
 private void btn_luu_Click(object sender, EventArgs e)
 {
     //mở kế nối
     Unity.OpenConnection();
     MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK);
     if (them)
     {
         try
         {
             string sql = "Insert into ThanhPho values(" + "N'" + this.txt_thanhpho.Text.ToString() + "',N'" + this.txt_tenthanhpho.Text.ToString() + "')";
             //MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK);
             Unity.Excute(sql);
             this.showData("Select ThanhPho , TenThanhPho from ThanhPho");
             MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
             Unity.Close();
         }
         catch (SqlException)
         {
             MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK);
         }
     }
     else
     {
         //lấy thứ tự record hiện hành
         int r = dataGridViewQLDMTP.CurrentCell.RowIndex;
         //lấy thanhpho của record hiện hành
         string strThanhPho = dataGridViewQLDMTP.Rows[r].Cells[0].Value.ToString();
         string sql         = "Update ThanhPho set TenThanhPho = N'" + this.txt_tenthanhpho.Text.ToString() + "' where ThanhPho='" + strThanhPho + "'";
         Unity.Excute(sql);
         this.showData("Select ThanhPho , TenThanhPho from ThanhPho");
         MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
         Unity.Close();
     }
 }
Exemplo n.º 3
0
        private void btn_them_Click(object sender, EventArgs e)
        {
            them = true;
            //khoi tao lai cac text
            this.txt_diachi.ResetText();
            this.txt_dienthoai.ResetText();
            this.txt_maKH.ResetText();
            this.txt_tencongty.ResetText();
            this.cbx_thanhpho.ResetText();
            //khong Cho thao tác trên nút Thêm/Sửa/Xóa/Trở về.
            this.btn_them.Enabled  = false;
            this.btn_sua.Enabled   = false;
            this.btn_xoa.Enabled   = false;
            this.btn_trove.Enabled = false;
            //cho thao tác trên nút lưu, hũy
            this.btn_luu.Enabled   = true;
            this.btn_huybo.Enabled = true;
            this.panel.Enabled     = true;
            this.txt_maKH.Enabled  = true;
            //đưa dữ liệu lên combo box
            //tải dữ liệu vào bảng
            DataTable dt = new DataTable();

            Unity.OpenConnection();
            dt = Unity.getDatatable("select * from ThanhPho");
            this.cbx_thanhpho.DataSource = dt;
            //this.cbx_thanhpho.DisplayMember = "TenThanhPho";
            this.cbx_thanhpho.DisplayMember = "ThanhPho";
            this.cbx_thanhpho.ValueMember   = "ThanhPho";
            //đua trỏ
            this.txt_maKH.Focus();
        }
Exemplo n.º 4
0
        private void dataGridViewQLDMHD_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //lấy thứ tự record hiện hành
            int r = dataGridViewQLDMHD.CurrentCell.RowIndex;

            //lay gia tri tu luoi len cac text
            this.txt_maHD.Text = dataGridViewQLDMHD.Rows[r].Cells[0].Value.ToString();
            //lay gia tri combobox KH + NV
            //tải dữ liệu vào bảng KH
            DataTable dt = new DataTable();

            Unity.OpenConnection();
            dt = Unity.getDatatable("select * from KhachHang");
            this.cbx_MaKH.DataSource    = dt;
            this.cbx_MaKH.DisplayMember = "MaKH";
            this.cbx_MaKH.ValueMember   = "MaKH";
            this.cbx_MaKH.Text          = dataGridViewQLDMHD.Rows[r].Cells[1].Value.ToString();
            //tải dữ liệu vào bảng NV
            DataTable dt1 = new DataTable();

            Unity.OpenConnection();
            dt1 = Unity.getDatatable("select * from NhanVien");
            this.cbx_maNV.DataSource    = dt1;
            this.cbx_maNV.DisplayMember = "MaNV";
            this.cbx_maNV.ValueMember   = "MaNV";
            this.cbx_maNV.Text          = dataGridViewQLDMHD.Rows[r].Cells[2].Value.ToString();
            //lay gia tri tu luoi len cac text
            this.txt_ngaylap.Text  = dataGridViewQLDMHD.Rows[r].Cells[3].Value.ToString();
            this.txt_ngaynhan.Text = dataGridViewQLDMHD.Rows[r].Cells[4].Value.ToString();
            //đua trỏ
            this.txt_maHD.Focus();
        }
Exemplo n.º 5
0
 //hiển thị dữ liệu
 public void showData(string sql)
 {
     Unity.OpenConnection();
     //truy xuất đến bản Khachang
     dataGridViewDM.DataSource = Unity.getDatatable(sql);
     dataGridViewDM.AutoResizeColumns();
 }
Exemplo n.º 6
0
 private void btn_xoa_Click(object sender, EventArgs e)
 {
     try
     {
         //mở kế nối
         Unity.OpenConnection();
         //lấy thứ tự record hiện hành
         int r = dataGridViewTK.CurrentCell.RowIndex;
         //lấy thanhpho của record hiện hành
         string strtaikhoan = dataGridViewTK.Rows[r].Cells[0].Value.ToString();
         //câu lệnh SQL
         //string sql = "Delete From Chitiethoadon Where MaHD = '" + strmaHD + "'";
         string sql = "Delete From NguoiDung where taikhoan=N'" + strtaikhoan + "'";
         //MessageBox.Show("sql xóa: " + sql, "Cảnh báo", MessageBoxButtons.OK);
         Unity.Excute(sql);
         //MessageBox.Show("chại đến đây", "Cảnh báo", MessageBoxButtons.OK);
         String sqlload = "select * from NguoiDung";
         LoadDB(sqlload);
         MessageBox.Show("Xóa thành công!", "Thông báo", MessageBoxButtons.OK);
         Unity.Close();
     }
     catch (SqlException)
     {
         MessageBox.Show("Lỗi dữ liệu đã được dùng!", "Cảnh báo", MessageBoxButtons.OK);
     }
 }
Exemplo n.º 7
0
 //hiển thị dữ liệu
 public void LoadDB(string sql)
 {
     Unity.OpenConnection();
     //truy xuất đến bản Khachang
     this.dataGridViewQLDMNV.DataSource = Unity.getDatatable(sql);
     this.dataGridViewQLDMNV.AutoResizeColumns();
 }
Exemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (validate()) //kiểm tra dữ liệu k rỗng thì :
            {               //khai báo chuỗi lệnh sql
                Unity.OpenConnection();
                string sql = "select * from NguoiDung where taikhoan = '" + txt_taikhoan.Text + "' and matkhau = '" + txt_matkhau.Text + "'";
                //MessageBox.Show("cau lenh: "+sql);
                DataTable data = Unity.getDatatable(sql);

                if (data.Rows.Count <= 0)   //gọi hàm getTable từ lớp có giá trị truyền vào là chuỗi lênh select để lấy thông tin từ bảng nếu có số dòng <= 0 thì:
                {
                    MessageBox.Show("Sai tài khoản hoặc mật khẩu!");
                    Unity.Close();
                }
                else  //nếu số dòng lấy được > 0 thì :
                {
                    //lay dữ liệu quyền cho form 1 (main)
                    Form1.quyen = data.Rows[0][2].ToString().Trim();

                    MessageBox.Show("quyen: " + Form1.quyen);
                    MessageBox.Show("Đăng nhập thành công!", "Thông báo!", MessageBoxButtons.OK);
                    Form1 f2 = new Form1();
                    this.Visible = false;
                    f2.ShowDialog();
                    Unity.Close();
                }
                //else
                //{
                //     MessageBox.Show("Sai thông tin đăng nhập!", "Cảnh báo!", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 9
0
        private void btn_them_Click(object sender, EventArgs e)
        {
            them = true;
            //khoi tao lai cac text
            this.txt_taikhoan.ResetText();
            this.cbx_VT.ResetText();
            this.txt_matkhau.ResetText();
            //khong Cho thao tác trên nút Thêm/Sửa/Xóa/Trở về.
            this.btn_them.Enabled  = false;
            this.btn_sua.Enabled   = false;
            this.btn_xoa.Enabled   = false;
            this.btn_trove.Enabled = false;
            //cho thao tác trên nút lưu, hũy
            this.btn_luu.Enabled      = true;
            this.btn_huybo.Enabled    = true;
            this.panel.Enabled        = true;
            this.txt_taikhoan.Enabled = true;
            //đưa dữ liệu lên combo box
            //lấy thứ tự record hiện hành
            int r = dataGridViewTK.CurrentCell.RowIndex;
            //tải dữ liệu vào bảng VT
            DataTable dt = new DataTable();

            Unity.OpenConnection();
            dt = Unity.getDatatable("select * from Nguoidung");
            this.cbx_VT.DataSource    = dt;
            this.cbx_VT.DisplayMember = "Vaitro";
            this.cbx_VT.ValueMember   = "Vaitro";
            this.cbx_VT.Text          = dataGridViewTK.Rows[r].Cells[2].Value.ToString();
            Unity.Close();
            //đua trỏ
            this.txt_taikhoan.Focus();
        }
Exemplo n.º 10
0
        private void dataGridViewQLDMCTHD_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //lấy thứ tự record hiện hành
            int r = dataGridViewQLDMCTHD.CurrentCell.RowIndex;

            //lay gia tri tu luoi len cac text
            this.txt_soluong.Text = dataGridViewQLDMCTHD.Rows[r].Cells[2].Value.ToString();
            //lay gia tri combobox HD + SP
            //tải dữ liệu vào bảng HD
            DataTable dt = new DataTable();

            Unity.OpenConnection();
            dt = Unity.getDatatable("select * from HoaDon");
            this.cbx_MaHD.DataSource    = dt;
            this.cbx_MaHD.DisplayMember = "MaHD";
            this.cbx_MaHD.ValueMember   = "MaHD";
            this.cbx_MaHD.Text          = dataGridViewQLDMCTHD.Rows[r].Cells[0].Value.ToString();
            //tải dữ liệu vào bảng SP
            DataTable dt1 = new DataTable();

            Unity.OpenConnection();
            dt1 = Unity.getDatatable("select * from SanPham");
            this.cbx_maSP.DataSource    = dt1;
            this.cbx_maSP.DisplayMember = "MaSP";
            this.cbx_maSP.ValueMember   = "MaSP";
            this.cbx_maSP.Text          = dataGridViewQLDMCTHD.Rows[r].Cells[1].Value.ToString();
            //đua trỏ
            this.cbx_MaHD.Focus();
        }
Exemplo n.º 11
0
 private void btn_luu_Click(object sender, EventArgs e)
 {
     //mở kế nối
     Unity.OpenConnection();
     // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK);
     if (them)
     {
         try
         {
             string sql = "Insert into nguoidung values(" + "N'" + this.txt_taikhoan.Text.ToString() + "',N'" + this.txt_matkhau.Text.ToString() + "',N'" + this.cbx_VT.Text.ToString() + "')";
             //MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK);
             Unity.Excute(sql);
             String sqlload = "select * from nguoidung";
             LoadDB(sqlload);
             MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
             Unity.Close();
         }
         catch (SqlException)
         {
             MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK);
         }
     }
     else
     {
         //lấy thứ tự record hiện hành
         int    r   = dataGridViewTK.CurrentCell.RowIndex;
         string sql = "Update nguoidung set taikhoan = N'" + this.txt_taikhoan.Text.ToString() + "'," + "matkhau = N'" + this.txt_matkhau.Text.ToString() + "'," + "Vaitro = N'" + this.cbx_VT.Text.ToString() + "'where taikhoan=N'" + dataGridViewTK.Rows[r].Cells[0].Value.ToString() + "' AND matkhau =N'" + dataGridViewTK.Rows[r].Cells[1].Value.ToString() + "' AND Vaitro =N'" + dataGridViewTK.Rows[r].Cells[2].Value.ToString() + "'";
         //MessageBox.Show("sql sửa: " + sql, "Cảnh báo", MessageBoxButtons.OK);
         Unity.Excute(sql);
         String sqlload = "select * from nguoidung";
         LoadDB(sqlload);
         MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
         Unity.Close();
     }
 }
Exemplo n.º 12
0
        //hiển thị dữ liệu
        public void showData(string sql)
        {
            Unity.OpenConnection();
            //truy xuất đến bản Khachang
            dataGridViewQLDMTP.DataSource = Unity.getDatatable(sql);
            dataGridViewQLDMTP.AutoResizeColumns();

            //dataGridViewQLDMTP.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
        }
Exemplo n.º 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txt_taikhoan.Text.Trim() == "")
            {
                MessageBox.Show("Chưa nhập tên tài khoản!", "Cảnh báo", MessageBoxButtons.OK);
                txt_taikhoan.Focus();
            }
            else if (txt_matkhau.Text.Trim() == "")
            {
                MessageBox.Show("Chưa nhập mật khẩu!", "Cảnh báo", MessageBoxButtons.OK);
                txt_matkhau.Focus();
            }
            else if (txt_matkhaumoi.Text.Trim() == "")
            {
                MessageBox.Show("Chưa nhập mật khẩu mới!", "Cảnh báo", MessageBoxButtons.OK);
                txt_matkhaumoi.Focus();
            }
            else if (txt_matkhaumoilaplai.Text.Trim() == "")
            {
                MessageBox.Show("Chưa nhập mật khẩu mới nhập lại!", "Cảnh báo", MessageBoxButtons.OK);
                txt_matkhaumoilaplai.Focus();
            }
            else
            {
                //String userName ="******";
                //String passWord = "******";
                //changePassword(userName, passWord);

                //Doc du lieu
                if (Check(txt_taikhoan.Text, txt_matkhau.Text) == true)
                {
                    if (txt_matkhaumoi.Text.Trim() == txt_matkhaumoilaplai.Text.Trim())
                    {
                        MessageBox.Show("Đổi mật khẩu thành công!", "Thông báo", MessageBoxButtons.OK);
                        //xu ly cap nhat mat khau
                        string sql = "Update nguoidung set matkhau = N'" + this.txt_matkhaumoi.Text.ToString() + "'where taikhoan=N'" + this.txt_taikhoan.Text.ToString() + "'";
                        Unity.OpenConnection();
                        MessageBox.Show("sql capnhat: " + sql, "Cảnh báo", MessageBoxButtons.OK);
                        Unity.Excute(sql);
                        Unity.Close();
                        //String userName ="******";
                        //String passWord = "******";
                    }
                    else
                    {
                        MessageBox.Show("Mật khẩu mới không trùng nhau!", "Cảnh báo", MessageBoxButtons.OK);
                    }
                }
                else
                {
                    MessageBox.Show("Không tồn tại tài khoản này!", "Cảnh báo", MessageBoxButtons.OK);
                    txt_taikhoan.Focus();
                }
            }
        }
Exemplo n.º 14
0
        public FormQLKH_Theo_TP()
        {
            InitializeComponent();
            //đưa dữ liệu lên combo box
            //tải dữ liệu vào bảng
            DataTable dt = new DataTable();

            Unity.OpenConnection();
            dt = Unity.getDatatable("select TenThanhPho from ThanhPho");
            this.cbx_thanhpho.DataSource = dt;
            //this.cbx_thanhpho.DisplayMember = "TenThanhPho";
            this.cbx_thanhpho.DisplayMember = "TenThanhPho";
            this.cbx_thanhpho.ValueMember   = "TenThanhPho";
            //đua trỏ
        }
Exemplo n.º 15
0
        private Boolean Check(String taikhoan, String matkhau)
        {
            Unity.OpenConnection();
            string sql = "select * from NguoiDung where taikhoan = '" + taikhoan + "' and matkhau = '" + matkhau + "'";
            //MessageBox.Show("cau lenh: "+sql);
            DataTable data = Unity.getDatatable(sql);

            if (data.Rows.Count <= 0)  //gọi hàm getTable từ lớp có giá trị truyền vào là chuỗi lênh select để lấy thông tin từ bảng nếu có số dòng <= 0 thì:
            {
                Unity.Close();
                return(false);
            }
            else  //nếu số dòng lấy được > 0 thì :
            {
                Unity.Close();
                return(true);
            }
        }
Exemplo n.º 16
0
        //hàm đưa dữ liệu từ datagrid vào SQL
        public void them()
        {
            //mở kế nối
            Unity.OpenConnection();
            //======================
            for (int i = 1; i < dataGridView1.RowCount - 1; i++) //bỏ qua i= 0 là title của dadagridview
            {
                //câu lệnh SQl
                String sql = "Insert into ThanhPho values(N'" + dataGridView1.Rows[i].Cells["A"].Value + "',N'" + dataGridView1.Rows[i].Cells["B"].Value + "')";
                MessageBox.Show(sql);
                Unity.Excute(sql);
                MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
            }

            //======================
            //đóng kết nối
            Unity.Close();
        }
Exemplo n.º 17
0
        private void btn_them_Click(object sender, EventArgs e)
        {
            them = true;

            //khoi tao lai cac text
            this.txt_maHD.ResetText();
            this.txt_ngaylap.ResetText();
            this.txt_ngaynhan.ResetText();
            this.cbx_MaKH.ResetText();
            this.cbx_maNV.ResetText();
            //khong Cho thao tác trên nút Thêm/Sửa/Xóa/Trở về.
            this.btn_them.Enabled  = false;
            this.btn_sua.Enabled   = false;
            this.btn_xoa.Enabled   = false;
            this.btn_trove.Enabled = false;
            //cho thao tác trên nút lưu, hũy
            this.btn_luu.Enabled   = true;
            this.btn_huybo.Enabled = true;
            this.panel.Enabled     = true;
            this.txt_maHD.Enabled  = true;
            //đưa dữ liệu lên combo box
            //lấy thứ tự record hiện hành
            int r = dataGridViewQLDMHD.CurrentCell.RowIndex;
            //tải dữ liệu vào bảng KH
            DataTable dt = new DataTable();

            Unity.OpenConnection();
            dt = Unity.getDatatable("select * from KhachHang");
            this.cbx_MaKH.DataSource    = dt;
            this.cbx_MaKH.DisplayMember = "MaKH";
            this.cbx_MaKH.ValueMember   = "MaKH";
            this.cbx_MaKH.Text          = dataGridViewQLDMHD.Rows[r].Cells[1].Value.ToString();
            //tải dữ liệu vào bảng NV
            DataTable dt1 = new DataTable();

            Unity.OpenConnection();
            dt1 = Unity.getDatatable("select * from NhanVien");
            this.cbx_maNV.DataSource    = dt1;
            this.cbx_maNV.DisplayMember = "MaNV";
            this.cbx_maNV.ValueMember   = "MaNV";
            this.cbx_maNV.Text          = dataGridViewQLDMHD.Rows[r].Cells[2].Value.ToString();
            //đua trỏ
            this.txt_maHD.Focus();
        }
Exemplo n.º 18
0
        private void btn_them_Click(object sender, EventArgs e)
        {
            them = true;
            //khoi tao lai cac text
            this.cbx_MaHD.ResetText();
            this.cbx_maSP.ResetText();
            this.txt_soluong.ResetText();
            //khong Cho thao tác trên nút Thêm/Sửa/Xóa/Trở về.
            this.btn_them.Enabled  = false;
            this.btn_sua.Enabled   = false;
            this.btn_xoa.Enabled   = false;
            this.btn_trove.Enabled = false;
            //cho thao tác trên nút lưu, hũy
            this.btn_luu.Enabled   = true;
            this.btn_huybo.Enabled = true;
            this.panel.Enabled     = true;
            this.cbx_MaHD.Enabled  = true;
            //đưa dữ liệu lên combo box
            //lấy thứ tự record hiện hành
            int r = dataGridViewQLDMCTHD.CurrentCell.RowIndex;
            //tải dữ liệu vào bảng HD
            DataTable dt = new DataTable();

            Unity.OpenConnection();
            dt = Unity.getDatatable("select * from HoaDon");
            this.cbx_MaHD.DataSource    = dt;
            this.cbx_MaHD.DisplayMember = "MaHD";
            this.cbx_MaHD.ValueMember   = "MaHD";
            this.cbx_MaHD.Text          = dataGridViewQLDMCTHD.Rows[r].Cells[0].Value.ToString();
            Unity.Close();
            //tải dữ liệu vào bảng SP
            DataTable dt1 = new DataTable();

            Unity.OpenConnection();
            dt1 = Unity.getDatatable("select * from SanPham");
            this.cbx_maSP.DataSource    = dt1;
            this.cbx_maSP.DisplayMember = "MaSP";
            this.cbx_maSP.ValueMember   = "MaSP";
            this.cbx_maSP.Text          = dataGridViewQLDMCTHD.Rows[r].Cells[1].Value.ToString();
            Unity.Close();
            //đua trỏ
            this.cbx_MaHD.Focus();
        }
Exemplo n.º 19
0
        private void dataGridViewTK_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //lấy thứ tự record hiện hành
            int r = dataGridViewTK.CurrentCell.RowIndex;

            //lay gia tri tu luoi len cac text
            this.txt_taikhoan.Text = dataGridViewTK.Rows[r].Cells[0].Value.ToString();
            this.txt_matkhau.Text  = dataGridViewTK.Rows[r].Cells[1].Value.ToString();
            //lay gia tri combobox Vai trò
            DataTable dt = new DataTable();

            Unity.OpenConnection();
            dt = Unity.getDatatable("select * from nguoidung");
            this.cbx_VT.DataSource    = dt;
            this.cbx_VT.DisplayMember = "Vaitro";
            this.cbx_VT.ValueMember   = "Vaitro";
            this.cbx_VT.Text          = dataGridViewTK.Rows[r].Cells[2].Value.ToString();
            //đua trỏ
            this.txt_taikhoan.Focus();
        }
Exemplo n.º 20
0
 private void btn_xoa_Click(object sender, EventArgs e)
 {
     try
     {
         //mở kế nối
         Unity.OpenConnection();
         //lấy thứ tự record hiện hành
         int r = dataGridViewQLDMTP.CurrentCell.RowIndex;
         //lấy thanhpho của record hiện hành
         string strThanhPho = dataGridViewQLDMTP.Rows[r].Cells[0].Value.ToString();
         //câu lệnh SQL
         string sql = "Delete From ThanhPho Where ThanhPho = '" + strThanhPho + "'";
         Unity.Excute(sql);
         this.showData("Select ThanhPho , TenThanhPho from ThanhPho");
         MessageBox.Show("Xóa thành công!", "Thông báo", MessageBoxButtons.OK);
         Unity.Close();
     }
     catch (SqlException)
     {
         MessageBox.Show("Lỗi dữ liệu đã được dùng!", "Cảnh báo", MessageBoxButtons.OK);
     }
 }
Exemplo n.º 21
0
        private void dataGridViewQLDMKH_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //lấy thứ tự record hiện hành
            int r = dataGridViewQLDMKH.CurrentCell.RowIndex;

            //lay gia tri tu luoi len cac text
            this.txt_maKH.Text      = dataGridViewQLDMKH.Rows[r].Cells[0].Value.ToString();
            this.txt_diachi.Text    = dataGridViewQLDMKH.Rows[r].Cells[2].Value.ToString();
            this.txt_dienthoai.Text = dataGridViewQLDMKH.Rows[r].Cells[4].Value.ToString();
            this.txt_tencongty.Text = dataGridViewQLDMKH.Rows[r].Cells[1].Value.ToString();
            //this.txt_maKH.Enabled = false;
            //tải dữ liệu vào bảng
            DataTable dt = new DataTable();

            Unity.OpenConnection();
            dt = Unity.getDatatable("select * from ThanhPho");
            this.cbx_thanhpho.DataSource    = dt;
            this.cbx_thanhpho.DisplayMember = "ThanhPho";
            this.cbx_thanhpho.ValueMember   = "ThanhPho";
            //đua trỏ
            this.cbx_thanhpho.Text = dataGridViewQLDMKH.Rows[r].Cells[3].Value.ToString();
            this.txt_maKH.Focus();
        }
Exemplo n.º 22
0
 private void btn_luu_Click(object sender, EventArgs e)
 {
     //mở kế nối
     Unity.OpenConnection();
     // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK);
     if (them)
     {
         try
         {
             string sql = "Insert into Chitiethoadon values(" + "N'" + this.cbx_MaHD.Text.ToString() + "',N'" + this.cbx_maSP.Text.ToString() + "',N'" + this.txt_soluong.Text.ToString() + "')";
             //MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK);
             Unity.Excute(sql);
             String sqlload = "select * from Chitiethoadon";
             LoadDB(sqlload);
             MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
             Unity.Close();
         }
         catch (SqlException)
         {
             MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK);
         }
     }
     else
     {
         //lấy thứ tự record hiện hành
         int r = dataGridViewQLDMCTHD.CurrentCell.RowIndex;
         //lấy thanhpho của record hiện hành
         string strMaHD = dataGridViewQLDMCTHD.Rows[r].Cells[0].Value.ToString();
         string sql     = "Update Chitiethoadon set MaHD = N'" + this.cbx_MaHD.Text.ToString() + "'," + "MaSP = N'" + this.cbx_maSP.Text.ToString() + "'," + "Soluong = N'" + this.txt_soluong.Text.ToString() + "'where MaHD=N'" + dataGridViewQLDMCTHD.Rows[r].Cells[0].Value.ToString() + "' AND MaSP =N'" + dataGridViewQLDMCTHD.Rows[r].Cells[1].Value.ToString() + "' AND Soluong =N'" + dataGridViewQLDMCTHD.Rows[r].Cells[2].Value.ToString() + "'";
         MessageBox.Show("sql sửa: " + sql, "Cảnh báo", MessageBoxButtons.OK);
         Unity.Excute(sql);
         String sqlload = "select * from Chitiethoadon";
         LoadDB(sqlload);
         MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
         Unity.Close();
     }
 }
Exemplo n.º 23
0
 private void btn_luu_Click(object sender, EventArgs e)
 {
     //mở kế nối
     Unity.OpenConnection();
     // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK);
     if (them)
     {
         try
         {
             string sql = "Insert into SanPham values(" + "N'" + this.txt_maSP.Text.ToString() + "',N'" + this.txt_tensp.Text.ToString() + "',N'" + this.txt_dvt.Text.ToString() + "',N'" + this.txt_dongia.Text.ToString() + "','null'" + ")";
             MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK);
             Unity.Excute(sql);
             String sqlload = "select * from SanPham";
             LoadDB(sqlload);
             MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
             Unity.Close();
         }
         catch (SqlException)
         {
             MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK);
         }
     }
     else
     {
         //lấy thứ tự record hiện hành
         int r = dataGridViewQLDMSP.CurrentCell.RowIndex;
         //lấy thanhpho của record hiện hành
         string strMaSP = dataGridViewQLDMSP.Rows[r].Cells[0].Value.ToString();
         string sql     = "Update SanPham set MaSP = N'" + this.txt_maSP.Text.ToString() + "'," + "TenSP = N'" + this.txt_tensp.Text.ToString() + "'," + "Donvitinh = N'" + this.txt_dvt.Text.ToString() + "'," + "Dongia = N'" + this.txt_dongia.Text.ToString() + "',Hinh = 'null' where MaSP='" + strMaSP + "'";
         MessageBox.Show("chuoi: " + sql.ToString(), "Cảnh báo", MessageBoxButtons.OK);
         Unity.Excute(sql);
         String sqlload = "select * from SanPham";
         LoadDB(sqlload);
         MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
         Unity.Close();
     }
 }
Exemplo n.º 24
0
 private void btn_luu_Click(object sender, EventArgs e)
 {
     //mở kế nối
     Unity.OpenConnection();
     // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK);
     if (them)
     {
         try
         {
             string sql = "Insert into NhanVien values(" + "N'" + this.txt_maNV.Text.ToString() + "',N'" + this.txt_holot.Text.ToString() + "',N'" + this.txt_ten.Text.ToString() + "',N'" + this.txt_ngaysinh.Text.ToString() + "',N'" + this.txt_diachi.Text.ToString() + "',N'" + this.txt_dienthoai.Text.ToString() + "')";
             MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK);
             Unity.Excute(sql);
             String sqlload = "select * from NhanVien";
             LoadDB(sqlload);
             MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
             Unity.Close();
         }
         catch (SqlException)
         {
             MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK);
         }
     }
     else
     {
         //lấy thứ tự record hiện hành
         int r = dataGridViewQLDMNV.CurrentCell.RowIndex;
         //lấy thanhpho của record hiện hành
         string strMaNV = dataGridViewQLDMNV.Rows[r].Cells[0].Value.ToString();
         string sql     = "Update NhanVien set MaNV = N'" + this.txt_maNV.Text.ToString() + "'," + "Holot = N'" + this.txt_holot.Text.ToString() + "'," + "Ten = N'" + this.txt_ten.Text.ToString() + "'," + "Ngaysinh = N'" + this.txt_ngaysinh.Text.ToString() + "'," + "Diachi = N'" + this.txt_diachi.Text.ToString() + "'," + "Dienthoai = N'" + this.txt_dienthoai.Text.ToString() + "'where MaNV='" + strMaNV + "'";
         MessageBox.Show("chuoi: " + sql.ToString(), "Cảnh báo", MessageBoxButtons.OK);
         Unity.Excute(sql);
         String sqlload = "select * from NhanVien";
         LoadDB(sqlload);
         MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
         Unity.Close();
     }
 }
Exemplo n.º 25
0
 private void btn_luu_Click(object sender, EventArgs e)
 {
     //mở kế nối
     Unity.OpenConnection();
     // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK);
     if (them)
     {
         try
         {
             string sql = "Insert into KhachHang values(" + "N'" + this.txt_maKH.Text.ToString() + "',N'" + this.txt_tencongty.Text.ToString() + "',N'" + this.txt_diachi.Text.ToString() + "',N'" + this.cbx_thanhpho.Text.ToString() + "',N'" + this.txt_dienthoai.Text.ToString() + "')";
             //MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK);
             Unity.Excute(sql);
             String sqlload = "select * from Khachhang";
             LoadDB(sqlload);
             MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
             Unity.Close();
         }
         catch (SqlException)
         {
             MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK);
         }
     }
     else
     {
         //lấy thứ tự record hiện hành
         int r = dataGridViewQLDMKH.CurrentCell.RowIndex;
         //lấy thanhpho của record hiện hành
         string strMaKH = dataGridViewQLDMKH.Rows[r].Cells[0].Value.ToString();
         string sql     = "Update KhachHang set MaKH = N'" + this.txt_maKH.Text.ToString() + "'," + "TenCty = N'" + this.txt_tencongty.Text.ToString() + "'," + "Diachi = N'" + this.txt_diachi.Text.ToString() + "'," + "ThanhPho = N'" + this.cbx_thanhpho.Text.ToString() + "'," + "Dienthoai = N'" + this.txt_dienthoai.Text.ToString() + "'where MaKH='" + strMaKH + "'";
         Unity.Excute(sql);
         String sqlload = "select * from Khachhang";
         LoadDB(sqlload);
         MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
         Unity.Close();
     }
 }