Esempio n. 1
0
        private void AddDH()
        {
            DONDATHANG ddh = new DONDATHANG();
            //CT_DONDH ct = new CT_DONDH();
            Random ran = new Random();
            int    so  = ran.Next(01, 99999);

            ddh.MADH = txtsohoadon.Text;
            var v3Value = cmbnhacungcap.Properties.GetDataSourceValue("MANCC", cmbnhacungcap.ItemIndex);

            ddh.MANCC     = v3Value.ToString();
            ddh.MANV      = nHANVIENTableAdapter.tennv(_message).Rows[0][0].ToString();
            ddh.NGAYDH    = DateTime.Parse(cmbngaylap.Text);
            ddh.TONGTIEN  = decimal.Parse(txttongcong.Text);
            ddh.TINHTRANG = false;
            BH.DONDATHANGs.InsertOnSubmit(ddh);
            BH.SubmitChanges();
            for (int j = 0; j < cthd3DataGridView.Rows.Count; j++)
            {
                CT_DONDH ct   = new CT_DONDH();
                Random   ran1 = new Random();
                int      so1  = ran1.Next(01, 99999);
                ct.MA_CT_DH  = "CTDH" + DateTime.Now.ToString("ddMMyy") + so1;
                ct.MADH      = txtsohoadon.Text;
                ct.MASP      = cthd3DataGridView.Rows[j].Cells[4].Value.ToString();
                ct.SOLUONG   = int.Parse(cthd3DataGridView.Rows[j].Cells[1].Value.ToString());
                ct.DONGIA    = decimal.Parse(cthd3DataGridView.Rows[j].Cells[2].Value.ToString());
                ct.THANHTIEN = decimal.Parse(cthd3DataGridView.Rows[j].Cells[3].Value.ToString());
                BH.CT_DONDHs.InsertOnSubmit(ct);
                BH.SubmitChanges();
            }

            XtraMessageBox.Show("Lưu thành công", "Thông báo");
        }
Esempio n. 2
0
        // them khách hàng
        private void AddKH()
        {
            KHANH_HANG kh  = new KHANH_HANG();
            HOADON     hd  = new HOADON();
            Random     ran = new Random();
            int        so  = ran.Next(0, 9999999);

            kh.MAKH     = hd.MAKH = "KH" + DateTime.Now.ToString("ddMMyy") + so;
            kh.TenKH    = txtkhachang.Text;
            kh.SDT      = txtsdt.Text;
            hd.MAHD     = txthoadon.Text;
            hd.MANV     = nHANVIENTableAdapter.tennv(_message).Rows[0][0].ToString();
            hd.NGAYLAP  = Convert.ToDateTime(cmbngaylap.EditValue.ToString());
            hd.TONGTIEN = decimal.Parse(txttongtien.Text);
            hd.GHICHU   = txtghichu.Text;
            BH.HOADONs.InsertOnSubmit(hd);
            BH.KHANH_HANGs.InsertOnSubmit(kh);
            BH.SubmitChanges();
        }
Esempio n. 3
0
        private void groupControl2_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            if (Convert.ToInt32(e.Button.Properties.Tag) == 3)
            {
                string vValue = txtMa.Text;
                if (kiemtratrung(vValue) == 0)
                {
                    if (txtEmail.Text == "")
                    {
                        XtraMessageBox.Show("Nhập email.", "Thông báo");
                    }
                    else if (isEmail(txtEmail.Text) == false)
                    {
                        XtraMessageBox.Show("Email không hợp lệ", "Thông báo.");
                    }
                    else if (txtSDT.Text == "")
                    {
                        XtraMessageBox.Show("Nhập số điện thoại.", "Thông báo");
                    }
                    else if (IsValidPhone(txtSDT.Text) == false)
                    {
                        XtraMessageBox.Show("Số điện thoại không hợp lệ.", "Thông báo");
                    }
                    else if (comboGioiTinh.Text == "")
                    {
                        XtraMessageBox.Show("Chọn giới tính.", "Thông báo");
                    }
                    else if (dteNgaySinh.Text == "")
                    {
                        XtraMessageBox.Show("Nhập ngày sinh", "Thông báo");
                    }
                    else if (ptanh.Image == null)
                    {
                        XtraMessageBox.Show("Chọn ảnh", "Thông báo");
                    }
                    //Lưu sản phẩm
                    else
                    {
                        NHANVIEN nv = new NHANVIEN();

                        nv.MANV     = txtMa.Text;
                        nv.TENNV    = txtTen.Text;
                        nv.MATKHAU  = txtMK.Text;
                        nv.HOATDONG = Convert.ToBoolean(checkHD.Checked.ToString());
                        nv.EMAIL    = txtEmail.Text;
                        nv.SDT      = txtSDT.Text;
                        nv.DIACHI   = txtDiaChi.Text;
                        nv.HINHANH  = imageToByteArray(ptanh.Image);
                        nv.GIOITINH = comboGioiTinh.SelectedItem.ToString();
                        nv.NGAYSINH = Convert.ToDateTime(dteNgaySinh.EditValue.ToString());
                        NV.NHANVIENs.InsertOnSubmit(nv);
                        NV.SubmitChanges();
                        XtraMessageBox.Show("Lưu thành công", "Thông báo");
                        loaddl();
                        gridControl1.Enabled = true;
                    }
                }
                else
                {
                    NHANVIEN nv = new NHANVIEN();
                    nv          = NV.NHANVIENs.Where(s => s.MANV == txtMa.Text).Single();
                    nv.TENNV    = txtTen.Text;
                    nv.GIOITINH = comboGioiTinh.Text;
                    nv.NGAYSINH = DateTime.Parse(dteNgaySinh.Text);
                    nv.HINHANH  = imageToByteArray(ptanh.Image);
                    nv.EMAIL    = txtEmail.Text;
                    nv.MATKHAU  = txtMK.Text;
                    nv.SDT      = txtSDT.Text;
                    nv.DIACHI   = txtDiaChi.Text;
                    nv.HOATDONG = Convert.ToBoolean(checkHD.Checked.ToString());
                    NV.SubmitChanges();
                    MessageBox.Show("Sửa thành công.");
                    loaddl();
                    enable();
                }
            }
            //Sửa
            else if (Convert.ToInt32(e.Button.Properties.Tag) == 5)
            {
                if (txtMa.Text == "")
                {
                    XtraMessageBox.Show("Chọn nhân viên cần sửa.", "Thông báo");
                }
                else
                {
                    ptanh.Enabled         = true;
                    txtMa.Enabled         = false;
                    txtDiaChi.Enabled     = true;
                    txtEmail.Enabled      = true;
                    txtMK.Enabled         = false;
                    txtSDT.Enabled        = true;
                    txtTen.Enabled        = true;
                    checkHD.Enabled       = true;
                    comboGioiTinh.Enabled = true;
                    dteNgaySinh.Enabled   = true;
                    groupControl2.CustomHeaderButtons[2].Properties.Enabled = true;
                    groupControl2.CustomHeaderButtons[0].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[1].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[4].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[5].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[6].Properties.Enabled = false;
                }
            }
            //Xoá
            else if (Convert.ToInt32(e.Button.Properties.Tag) == 6)
            {
                if (txtMa.Text == "")
                {
                    XtraMessageBox.Show("Vui lòng chọn nhân viên.", "Thông báo");
                }
                else if (txtMa.Text == _message)
                {
                    XtraMessageBox.Show("Tài khoản đang đăng nhập.", "Thông báo.");
                }
                else
                {
                    NHANVIEN nhanvien = new NHANVIEN();
                    nhanvien          = NV.NHANVIENs.Where(s => s.MANV == txtMa.Text).Single();
                    nhanvien.HOATDONG = false;
                    NV.SubmitChanges();
                    txtMa.Text     = "";
                    txtTen.Text    = "";
                    txtSDT.Text    = "";
                    txtMK.Text     = "";
                    txtEmail.Text  = "";
                    txtDiaChi.Text = "";
                    // gridhanghoa.Enabled = false;
                    dteNgaySinh.Text   = "";
                    comboGioiTinh.Text = "";
                    ptanh.Image        = null;
                    checkHD.Checked    = false;
                    XtraMessageBox.Show("Đã khoá thành công.", "Thông báo");
                    loaddl();
                }
            }
            else if (Convert.ToInt32(e.Button.Properties.Tag) == 1)
            {
                enabletrue();
                ramdomma();
                txtMK.Text           = CreateRandomPassword();
                gridControl1.Enabled = false;

                //XtraMessageBox.Show("Thêm nè", "Thông báo");
            }
        }
Esempio n. 4
0
        private void groupControl2_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            /*Thêm sản phẩm*/
            if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 1)
            {
                txtmasp.Text        = "";
                txttensp.Text       = "";
                txtsoluong.Text     = "";
                txtgiatien.Text     = "";
                txtgiaban.Text      = "";
                gridhanghoa.Enabled = false;
                unenable();
                cmbloaisp.Text     = "";
                cmbnhacungcap.Text = "";
                ptanh.Image        = null;
                groupControl2.CustomHeaderButtons[2].Properties.Enabled = false;
                groupControl2.CustomHeaderButtons[1].Properties.Enabled = false;
                groupControl2.CustomHeaderButtons[3].Properties.Enabled = false;
                groupControl2.CustomHeaderButtons[6].Properties.Enabled = true;
                txtmasp.Enabled = false;
            }
            /*Lưu sản phẩm*/
            else if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 7)
            {
                //int rowHandle = gridhanghoatrong.FocusedRowHandle;
                string vValue = txtmasp.Text;
                /*trường hợp sửa*/
                if (kiemtratrung(vValue.ToString()) == 1)
                {
                    if (ptanh.Image == null)
                    {
                        MessageBox.Show("Cần chọn ảnh để lưu.");
                    }
                    else
                    if (txtgiatien.Text == "" || txtgiaban.Text == "")
                    {
                        MessageBox.Show("Giá không hợp lệ");
                    }
                    else
                    if (double.Parse(txtgiatien.Text) > double.Parse(txtgiaban.Text))
                    {
                        MessageBox.Show("Giá bán hợp lệ");
                    }
                    else
                    {
                        if (cmbnhacungcap.Text == "")
                        {
                            MessageBox.Show("Chọn nhà cung cấp sản phẩm.");
                        }
                        else if (cmbloaisp.Text == "")
                        {
                            MessageBox.Show("Chọn loại sản phẩm.");
                        }
                        else if (txtsoluong.Text == "")
                        {
                            MessageBox.Show("Nhập số lượng cho sản phẩm.");
                        }
                        else
                        {
                            SANPHAM sp = new SANPHAM();
                            sp         = BH.SANPHAMs.Where(s => s.MASP == txtmasp.Text).Single();
                            sp.TENSP   = txttensp.Text;
                            sp.SOLUONG = int.Parse(txtsoluong.Text);
                            var v3Value = cmbnhacungcap.Properties.GetDataSourceValue("MANCC", cmbnhacungcap.ItemIndex);
                            sp.MANCC  = v3Value.ToString();
                            sp.DONGIA = decimal.Parse(txtgiatien.Text);
                            var v1Value = cmbloaisp.Properties.GetDataSourceValue("MALOAISP", cmbloaisp.ItemIndex);
                            sp.LOAISP    = v1Value.ToString();
                            sp.DONGIABAN = decimal.Parse(txtgiaban.Text);
                            sp.GIAMGIA   = int.Parse(txtgiamgia.Text);
                            sp.HINHANH   = imageToByteArray(ptanh.Image);
                            BH.SubmitChanges();
                            MessageBox.Show("Sửa thành công.");
                            enable();
                            groupControl2.CustomHeaderButtons[0].Properties.Enabled = true;
                            groupControl2.CustomHeaderButtons[2].Properties.Enabled = true;
                            groupControl2.CustomHeaderButtons[3].Properties.Enabled = true;
                            loaddulieusp();
                            gridhanghoa.Enabled = true;
                            //frmHangHoa_Load(sender,e);
                        }
                    }
                }
                /*trường hợp lưu*/
                else if (kiemtratrung(vValue.ToString()) == 0)
                {
                    if (ptanh.Image == null)
                    {
                        MessageBox.Show("Cần chọn ảnh để lưu.");
                    }
                    else
                    if (txtgiatien.Text == "" || txtgiaban.Text == "")
                    {
                        MessageBox.Show("Giá không hợp lệ");
                    }
                    else
                    if (double.Parse(txtgiatien.Text) > double.Parse(txtgiaban.Text))
                    {
                        MessageBox.Show("Giá bán hợp lệ");
                    }
                    else
                    {
                        //var v1Value = cmbloaisp.Properties.GetDataSourceValue("MALOAISP", cmbloaisp.ItemIndex);
                        //var v3Value = cmbnhacungcap.Properties.GetDataSourceValue("MANCC", cmbnhacungcap.ItemIndex);
                        SANPHAM           sp   = new SANPHAM();
                        CHITIET_DIENTHOAI ctdt = new CHITIET_DIENTHOAI();
                        sp.MASP = ctdt.MASP = txtmasp.Text;
                        if (cmbnhacungcap.Text == "")
                        {
                            MessageBox.Show("Chọn nhà cung cấp sản phẩm.");
                        }
                        else if (cmbloaisp.Text == "")
                        {
                            MessageBox.Show("Chọn loại sản phẩm.");
                        }
                        else if (txtsoluong.Text == "")
                        {
                            MessageBox.Show("Nhập số lượng cho sản phẩm.");
                        }
                        else
                        {
                            var v3Value = cmbnhacungcap.Properties.GetDataSourceValue("MANCC", cmbnhacungcap.ItemIndex);
                            sp.MANCC = v3Value.ToString();
                            var v1Value = cmbloaisp.Properties.GetDataSourceValue("MALOAISP", cmbloaisp.ItemIndex);
                            sp.LOAISP    = v1Value.ToString();
                            sp.SOLUONG   = int.Parse(txtsoluong.Text);
                            sp.DONGIA    = decimal.Parse(txtgiatien.Text);
                            sp.DONGIABAN = decimal.Parse(txtgiaban.Text);
                            sp.TENSP     = txttensp.Text;
                            if (txtgiamgia.Text == "")
                            {
                                sp.GIAMGIA = 0;
                            }
                            else
                            {
                                sp.GIAMGIA = int.Parse(txtgiamgia.Text);
                            }
                            sp.HINHANH = imageToByteArray(ptanh.Image);
                            BH.CHITIET_DIENTHOAIs.InsertOnSubmit(ctdt);
                            BH.SANPHAMs.InsertOnSubmit(sp);
                            BH.SubmitChanges();
                            loaddulieusp();
                            MessageBox.Show("Lưu thành công.");
                            gridhanghoa.Enabled = true;
                            groupControl2.CustomHeaderButtons[1].Properties.Enabled = true;
                            groupControl2.CustomHeaderButtons[2].Properties.Enabled = true;
                            groupControl2.CustomHeaderButtons[3].Properties.Enabled = true;
                            //groupControl2.CustomHeaderButtons[3].Properties.Enabled = false;
                            enable();
                        }
                    }
                }
            }
            else if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 8)
            {
                if (MessageBox.Show("Xác nhận thông tin Export", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    FolderBrowserDialog chuc = new FolderBrowserDialog();

                    if (chuc.ShowDialog() == DialogResult.OK)
                    {
                        string filePath = chuc.SelectedPath + "\\Export_BaoCao.xls";
                        gridhanghoa.ExportToXls(filePath);
                    }
                }
            }
            /*Xoá sản phẩm*/
            else if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 3)
            {
                if (txtmasp.Text == "")
                {
                    MessageBox.Show("Vui lòng chọn sản phẩm.");
                }
                else
                {
                    SANPHAM           sp   = new SANPHAM();
                    CHITIET_DIENTHOAI ctdt = new CHITIET_DIENTHOAI();
                    ctdt = BH.CHITIET_DIENTHOAIs.Where(s => s.MASP == txtmasp.Text).Single();
                    sp   = BH.SANPHAMs.Where(s => s.MASP == txtmasp.Text).Single();
                    BH.SANPHAMs.DeleteOnSubmit(sp);
                    BH.CHITIET_DIENTHOAIs.DeleteOnSubmit(ctdt);
                    BH.SubmitChanges();
                    loaddulieusp();
                    txtmasp.Text    = "";
                    txttensp.Text   = "";
                    txtsoluong.Text = "";
                    txtgiatien.Text = "";
                    txtgiaban.Text  = "";
                    // gridhanghoa.Enabled = false;
                    cmbloaisp.Text     = "";
                    cmbnhacungcap.Text = "";
                    ptanh.Image        = null;
                }
            }
            /*Sửa sản phẩm*/
            else if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 2)
            {
                if (txtmasp.Text == "")
                {
                    MessageBox.Show("Hãy chọn sản phẩm.");
                }
                else
                {
                    unenable();
                    cmbloaisp.EditValueChanged -= new EventHandler(cmbloaisp_EditValueChanged);
                    cmbloaisp.Enabled           = false;
                    gridhanghoa.Enabled         = false;
                    txtmasp.Enabled             = false;
                    groupControl2.CustomHeaderButtons[0].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[2].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[3].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[6].Properties.Enabled = true;
                }
            }
        }
Esempio n. 5
0
        private void groupControl1_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 1)
            {
                PHIEUNHAPHANG pn = new PHIEUNHAPHANG();

                pn.MAPN         = txtmaphieunhap.Text;
                pn.MADH         = txtmaphieudat.Text;
                pn.MANV         = _message;
                pn.NGAYGIAOHANG = DateTime.Parse(cmbngaylap.Text);
                pn.TONGTIEN     = decimal.Parse(txtthanhtien.Text);
                pn.TINHTRANG    = false;
                BH.PHIEUNHAPHANGs.InsertOnSubmit(pn);
                BH.SubmitChanges();

                for (int j = 0; j < dataGridView1.Rows.Count; j++)
                {
                    CHITIET_PHIEUNHAP ctpn = new CHITIET_PHIEUNHAP();
                    SANPHAM           sp   = new SANPHAM();
                    DONDATHANG        dh   = new DONDATHANG();
                    ctpn.MAPN      = txtmaphieunhap.Text;
                    ctpn.MA_CT_DH  = dataGridView1.Rows[j].Cells[5].Value.ToString();
                    ctpn.SOLUONG   = decimal.Parse(dataGridView1.Rows[j].Cells[2].Value.ToString());
                    ctpn.DONGIA    = decimal.Parse(dataGridView1.Rows[j].Cells[3].Value.ToString());
                    ctpn.THANHTIEN = decimal.Parse(dataGridView1.Rows[j].Cells[4].Value.ToString());
                    //cập nhật sản phẩm
                    int sl = (from slhanghoa in BH.SANPHAMs

                              where slhanghoa.MASP == dataGridView1.Rows[j].Cells[6].Value.ToString()
                              select
                              slhanghoa.SOLUONG).FirstOrDefault();
                    int soln      = int.Parse(dataGridView1.Rows[j].Cells[2].Value.ToString());
                    int slcapnhat = sl + soln;
                    sp         = BH.SANPHAMs.Where(s => s.MASP == dataGridView1.Rows[j].Cells[6].Value.ToString()).Single();
                    sp.SOLUONG = slcapnhat;

                    //kiểm tra số lượng nhập
                    // dem dong
                    int sum;
                    int count = (from nhaphang in BH.CHITIET_PHIEUNHAPs
                                 where nhaphang.MA_CT_DH == dataGridView1.Rows[j].Cells[5].Value.ToString()
                                 select
                                 nhaphang.SOLUONG
                                 ).Count();
                    if (count == 0)
                    {
                        sum = 0;
                    }
                    else
                    {
                        //tổng số lượng các lần nhập hàng
                        sum = (int)(from nhaphang in BH.CHITIET_PHIEUNHAPs
                                    where nhaphang.MA_CT_DH == dataGridView1.Rows[j].Cells[5].Value.ToString()
                                    select
                                    nhaphang.SOLUONG
                                    ).Sum();
                    }

                    // tổng nhập
                    int tongnhap = sum + int.Parse(dataGridView1.Rows[j].Cells[2].Value.ToString());
                    //số lượng chi tiết đơn đặt hàng
                    var sl1 = (from slhanghoa1 in BH.CT_DONDHs

                               where slhanghoa1.MA_CT_DH == dataGridView1.Rows[j].Cells[5].Value.ToString()
                               select
                               slhanghoa1.SOLUONG).FirstOrDefault();
                    if (tongnhap > int.Parse(sl1.ToString()))
                    {
                        XtraMessageBox.Show("Số lượng nhập quá lớn", "Thông báo");
                    }
                    else
                    {
                        if (tongnhap == int.Parse(sl1.ToString()))
                        {
                            // cap nhat tinh trang
                            dh           = BH.DONDATHANGs.Where(s => s.MADH == txtmaphieudat.Text).Single();
                            dh.TINHTRANG = true;
                        }
                        else
                        {
                            dh.TINHTRANG = false;
                        }

                        BH.CHITIET_PHIEUNHAPs.InsertOnSubmit(ctpn);
                        BH.SubmitChanges();
                        XtraMessageBox.Show("Lưu thành công");
                    }
                }
            }
            else if (Convert.ToInt32(e.Button.Properties.Tag.ToString()) == 2)
            {
                dataGridView1.DataSource = null;

                // Bind with the new data.
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.ColumnCount         = 7;

                dataGridView1.Columns[0].Name = "Mã phiếu nhập";
                dataGridView1.Columns[1].Name = "Sản phẩm";
                dataGridView1.Columns[2].Name = "Số lượng";
                dataGridView1.Columns[3].Name = "Đơn giá";
                dataGridView1.Columns[4].Name = "Thành tiền";
                dataGridView1.Columns[5].Name = "Mã CT";
                dataGridView1.Columns[6].Name = "Mã sản phẩm";
                bool   kt      = true;
                var    v3Value = cmbsanpham.Properties.GetDataSourceValue("MASP", cmbsanpham.ItemIndex);
                string value   = (from tennv in BH.CT_DONDHs
                                  join sp in BH.SANPHAMs on tennv.MASP equals sp.MASP
                                  join ddh in BH.DONDATHANGs on tennv.MADH equals ddh.MADH
                                  where tennv.MASP == v3Value.ToString() && tennv.MADH == txtmaphieudat.Text
                                  select
                                  tennv.MA_CT_DH).FirstOrDefault();
                for (int j = 0; j < dataGridView1.Rows.Count; j++)
                {
                    if (value == dataGridView1.Rows[j].Cells[5].Value.ToString())
                    {
                        int slcong = Int32.Parse(dataGridView1.Rows[j].Cells[2].Value.ToString());
                        slcong = slcong + int.Parse(txtsoluong.Text);
                        dataGridView1.Rows[j].Cells[2].Value = slcong;
                        double thanhtien = 0;
                        thanhtien = (slcong * double.Parse(dataGridView1.Rows[j].Cells[3].Value.ToString()));
                        dataGridView1.Rows[j].Cells[4].Value = thanhtien;
                        kt = false;
                        break;
                    }
                }
                if (kt)
                {
                    int row = 0;
                    dataGridView1.Rows.Add();
                    row = dataGridView1.Rows.Count - 1;

                    dataGridView1.Rows[row].Cells[0].Value = txtmaphieunhap.Text;

                    dataGridView1.Rows[row].Cells[1].Value = cmbsanpham.Text;

                    dataGridView1.Rows[row].Cells[2].Value = txtsoluong.Text;

                    dataGridView1.Rows[row].Cells[3].Value = txtdongia.Text;

                    double tt = int.Parse(dataGridView1.Rows[row].Cells[2].Value.ToString()) * double.Parse(dataGridView1.Rows[row].Cells[3].Value.ToString());

                    dataGridView1.Rows[row].Cells[4].Value = tt.ToString();
                    dataGridView1.Rows[row].Cells[5].Value = value;
                    dataGridView1.Rows[row].Cells[6].Value = v3Value;
                }
                double i = tinhtongtien();
                txtthanhtien.Text = string.Format("{0:n0}", Double.Parse(i.ToString()));
            }
        }
Esempio n. 6
0
        private void groupControl2_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            if (Convert.ToInt32(e.Button.Properties.Tag) == 3)
            {
                string vValue = txtMa.Text;
                if (kiemtratrung(vValue) == 0)
                {
                    if (txtEmail.Text == "")
                    {
                        XtraMessageBox.Show("Nhập email.", "Thông báo");
                    }
                    else if (isEmail(txtEmail.Text) == false)
                    {
                        XtraMessageBox.Show("Email không hợp lệ", "Thông báo.");
                    }
                    else if (txtSDT.Text == "")
                    {
                        XtraMessageBox.Show("Nhập số điện thoại.", "Thông báo");
                    }
                    else if (IsValidPhone(txtSDT.Text) == false)
                    {
                        XtraMessageBox.Show("Số điện thoại không hợp lệ.", "Thông báo");
                    }
                    else if (comboGioiTinh.Text == "")
                    {
                        XtraMessageBox.Show("Chọn giới tính.", "Thông báo");
                    }
                    else if (dteNgaySinh.Text == "")
                    {
                        XtraMessageBox.Show("Nhập ngày sinh", "Thông báo");
                    }
                    else if (ptanh.Image == null)
                    {
                        XtraMessageBox.Show("Chọn ảnh", "Thông báo");
                    }
                    //Lưu sản phẩm
                    else
                    {
                        NHANVIEN nv = new NHANVIEN();

                        nv.MANV     = txtMa.Text;
                        nv.TENNV    = txtTen.Text;
                        nv.MATKHAU  = txtMK.Text;
                        nv.HOATDONG = Convert.ToBoolean(checkHD.Checked.ToString());
                        nv.EMAIL    = txtEmail.Text;
                        nv.SDT      = txtSDT.Text;
                        nv.DIACHI   = txtDiaChi.Text;
                        nv.HINHANH  = imageToByteArray(ptanh.Image);
                        nv.GIOITINH = comboGioiTinh.SelectedItem.ToString();
                        nv.NGAYSINH = Convert.ToDateTime(dteNgaySinh.EditValue.ToString());
                        NV.NHANVIENs.InsertOnSubmit(nv);
                        NV.SubmitChanges();
                        XtraMessageBox.Show("Lưu thành công", "Thông báo");
                        loaddl();
                        gridControl1.Enabled = true;
                    }
                }
                else
                {
                    NHANVIEN nv = new NHANVIEN();
                    nv          = NV.NHANVIENs.Where(s => s.MANV == txtMa.Text).Single();
                    nv.TENNV    = txtTen.Text;
                    nv.GIOITINH = comboGioiTinh.Text;
                    nv.NGAYSINH = DateTime.Parse(dteNgaySinh.Text);
                    nv.HINHANH  = imageToByteArray(ptanh.Image);
                    nv.EMAIL    = txtEmail.Text;
                    nv.MATKHAU  = txtMK.Text;
                    nv.SDT      = txtSDT.Text;
                    nv.DIACHI   = txtDiaChi.Text;
                    nv.HOATDONG = Convert.ToBoolean(checkHD.Checked.ToString());
                    NV.SubmitChanges();
                    MessageBox.Show("Sửa thành công.");
                    loaddl();
                    enable();
                }
            }
            //Sửa
            else if (Convert.ToInt32(e.Button.Properties.Tag) == 5)
            {
                if (txtMa.Text == "")
                {
                    XtraMessageBox.Show("Chọn nhân viên cần sửa.", "Thông báo");
                }
                else
                {
                    ptanh.Enabled         = true;
                    txtMa.Enabled         = false;
                    txtDiaChi.Enabled     = true;
                    txtEmail.Enabled      = true;
                    txtMK.Enabled         = false;
                    txtSDT.Enabled        = true;
                    txtTen.Enabled        = true;
                    checkHD.Enabled       = true;
                    comboGioiTinh.Enabled = true;
                    dteNgaySinh.Enabled   = true;
                    groupControl2.CustomHeaderButtons[2].Properties.Enabled = true;
                    groupControl2.CustomHeaderButtons[0].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[1].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[4].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[5].Properties.Enabled = false;
                    groupControl2.CustomHeaderButtons[6].Properties.Enabled = false;
                }
            }
            //Xoá
            else if (Convert.ToInt32(e.Button.Properties.Tag) == 6)
            {
                if (txtMa.Text == "")
                {
                    XtraMessageBox.Show("Vui lòng chọn nhân viên.", "Thông báo");
                }
                else if (txtMa.Text == _message)
                {
                    XtraMessageBox.Show("Tài khoản đang đăng nhập.", "Thông báo.");
                }
                else
                {
                    NHANVIEN nhanvien = new NHANVIEN();
                    nhanvien          = NV.NHANVIENs.Where(s => s.MANV == txtMa.Text).Single();
                    nhanvien.HOATDONG = false;
                    NV.SubmitChanges();
                    txtMa.Text     = "";
                    txtTen.Text    = "";
                    txtSDT.Text    = "";
                    txtMK.Text     = "";
                    txtEmail.Text  = "";
                    txtDiaChi.Text = "";
                    // gridhanghoa.Enabled = false;
                    dteNgaySinh.Text   = "";
                    comboGioiTinh.Text = "";
                    ptanh.Image        = null;
                    checkHD.Checked    = false;
                    XtraMessageBox.Show("Đã khoá thành công.", "Thông báo");
                    loaddl();
                }
            }
            else if (Convert.ToInt32(e.Button.Properties.Tag) == 1)
            {
                enabletrue();
                ramdomma();
                txtMK.Text           = CreateRandomPassword();
                gridControl1.Enabled = false;

                //XtraMessageBox.Show("Thêm nè", "Thông báo");
            }
            else if (Convert.ToInt32(e.Button.Properties.Tag) == 7)
            {
                rptNhanVien rpt1 = new rptNhanVien();
                rpt1.Parameters["ma"].Value       = txtMa.Text;
                rpt1.Parameters["ten"].Value      = txtTen.Text;
                rpt1.Parameters["ngaysinh"].Value = dteNgaySinh.Text;
                rpt1.Parameters["diachi"].Value   = txtDiaChi.Text;
                rpt1.Parameters["giotinh"].Value  = comboGioiTinh.Text;
                rpt1.Parameters["matkhau"].Value  = txtMK.Text;
                rpt1.Parameters["email"].Value    = txtEmail.Text;
                //rpt1.DataSource = DH.In_DDH(txtsohoadon.Text);
                if (MessageBox.Show("Xác nhận thông tin Export", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    FolderBrowserDialog chuc = new FolderBrowserDialog();
                    if (chuc.ShowDialog() == DialogResult.OK)
                    {
                        string filePath = chuc.SelectedPath + "\\Export_ThongtinNV" + txtMa.Text + ".docx";
                        rpt1.ExportToDocx(filePath);
                        Process.Start(filePath);
                    }
                }

                // rpt.ShowPreviewDialog();
                //rpt1.ShowPreviewDialog();
            }
        }