private void Del()
        {
            tblhoadontraBL ctr = new tblhoadontraBL();

            string sidkh = "";

            try { sidkh = ctr.GetByID(txtID.Text.Trim()).id_khachhang.Trim(); }
            catch { }
            string         stenkh = "";
            tblkhachhangBL ctrkh  = new tblkhachhangBL();

            try { stenkh = ctrkh.GetByID(sidkh).tenkh.Trim(); }
            catch { stenkh = "-/-"; }

            string kq = "";

            if (MessageBox.Show("Xác nhận xóa dữ liệu?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                UpdateSoLuongMatHang();
                kq = ctr.Delete(txtID.Text.Trim());
                if (kq.Trim().Equals("") == true)
                {
                    _ctrlog.Append(Data.use, "Xóa hóa đơn trả lại hàng của khách hàng: " + stenkh);
                    Add(); HienThiDSMatHang();
                }
                else
                {
                    MessageBox.Show("Xóa hóa đơn không thành công.\nChi tiết lỗi: " + kq, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
        }
        private void LoadCBKhachHang()
        {
            tblkhachhangBL ctr = new tblkhachhangBL();
            DataTable      dt  = new DataTable();

            dt = ctr.GetAll();
            cbKhachHang.DataSource    = dt;
            cbKhachHang.DisplayMember = "tenkh";
            cbKhachHang.ValueMember   = "id";
        }
Example #3
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            Application.DoEvents();
            progressBar1.PerformStep();
            Application.DoEvents();
            DateTime       dtdenngay = dpkDenNgay.Value;
            tblkhachhangBL ctrkh     = new tblkhachhangBL();
            DataTable      dtkh      = new DataTable();

            try
            {
                Application.DoEvents();
                progressBar1.PerformStep();
                Application.DoEvents();
                dtkh = ctrkh.GetByHoaDonBan();
                Application.DoEvents();
                progressBar1.PerformStep();
                Application.DoEvents();
                if (dtkh != null)
                {
                    TKCongNo ctr = new TKCongNo();
                    string   kq  = "";
                    kq = ctr.Generate(txtpath.Text, dtdenngay, dtkh, progressBar1);
                    Application.DoEvents();
                    progressBar1.Value = progressBar1.Maximum;
                    Application.DoEvents();
                    if (kq.Trim().Equals("") == true)
                    {
                        MessageBox.Show("Tổng hợp dữ liệu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tổng hợp dữ liệu không thành công.\nChi tiết lỗi: " + kq, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    progressBar1.Value = 0;
                    Application.DoEvents();
                }
                else
                {
                    MessageBox.Show("Lỗi không tổng hợp được dữ liệu.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    progressBar1.Value = 0;
                    Application.DoEvents();
                }
            }
            catch (Exception ex) {
                MessageBox.Show("Lỗi không tổng hợp được dữ liệu.\nChi tiết lỗi: " + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                progressBar1.Value = 0;
                Application.DoEvents();
            }
        }
        private void Del()
        {
            tblhoadontraBL ctr   = new tblhoadontraBL();
            string         kq    = "";
            string         sidhd = "";

            try { sidhd = flxHoaDon[flxHoaDon.RowSel, "id"].ToString().Trim(); }
            catch { }
            string sidkh = "";

            try { sidkh = flxHoaDon[flxHoaDon.RowSel, "id_khachhang"].ToString().Trim(); }
            catch { }
            string         stenkh = "";
            tblkhachhangBL ctrkh  = new tblkhachhangBL();

            try { stenkh = ctrkh.GetByID(sidkh).tenkh.Trim(); }
            catch { stenkh = "-/-"; }

            if (MessageBox.Show("Xác nhận xóa dữ liệu?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                UpdateSoLuongMatHang(sidhd);
                kq = ctr.Delete(sidhd);
                if (kq.Trim().Equals("") == true)
                {
                    _ctrlog.Append(Data.use, "Xóa hóa đơn trả lại hàng của khách hàng: " + stenkh);
                    flxHoaDon.Rows.Remove(flxHoaDon.RowSel);
                    if (flxHoaDon.Rows.Count - 1 > 0)
                    {
                        try { sidhd = flxHoaDon[1, "id"].ToString().Trim(); }
                        catch { }
                        HienThiTTHoaDon(sidhd);
                        HienThiDSMatHang(sidhd);
                    }
                    else
                    {
                        Add(); HienThiDSMatHang("-1");
                    }
                }
                else
                {
                    MessageBox.Show("Xóa hóa đơn trả lại hàng không thành công.\nChi tiết lỗi: " + kq, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
        }
Example #5
0
        private void HienThiDS()
        {
            tblkhachhangBL _ctr   = new tblkhachhangBL();
            DataTable      dt     = new DataTable();
            string         scapdl = "";

            if (cbCapDL.Text.Trim().Equals("---Tất cả---") == false)
            {
                scapdl = cbCapDL.Text;
            }
            dt = _ctr.Filter(txtKeyword.Text.Trim(), scapdl);
            if (dt != null)
            {
                c1FlexGrid1.DataSource = dt;
                //dt.Columns.Add("TT", typeof(Int32));
                FormatGrid();
            }
        }
Example #6
0
        private void HienThiTTKhachHang()
        {
            tblkhachhang   obj = new tblkhachhang();
            tblkhachhangBL ctr = new tblkhachhangBL();

            obj = ctr.GetByID(sidkh);
            if (obj == null)
            {
                MessageBox.Show("Lỗi: Không lấy được thông tin của khách hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try { txtTenKH.Text = obj.tenkh.Trim(); }
            catch { txtTenKH.Text = "N/A"; }
            try { txtCapDaiLy.Text = obj.id_capdl.Trim(); }
            catch { txtCapDaiLy.Text = "N/A"; }
            try { txtDienThoai.Text = obj.dt.Trim(); }
            catch { txtDienThoai.Text = "N/A"; }
            try { txtDiaChi.Text = obj.diachi.Trim(); }
            catch { txtDiaChi.Text = "N/A"; }
        }
Example #7
0
        private void Delete()
        {
            tblkhachhangBL _ctr = new tblkhachhangBL();
            string         loi  = "";
            string         sten = "";
            string         iid  = "";
            int            n    = c1FlexGrid1.RowSel;

            if (n >= 1)
            {
                try { sten = c1FlexGrid1[c1FlexGrid1.RowSel, "tenkh"].ToString().Trim(); }
                catch { }
                try { iid = c1FlexGrid1[c1FlexGrid1.RowSel, "id"].ToString().Trim(); }
                catch { }
                DialogResult bien;
                bien = MessageBox.Show("Xác nhận xóa dữ liệu", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (bien == DialogResult.Yes)
                {
                    loi = _ctr.Delete(iid);
                    if (loi.Equals("") == true)
                    {
                        try { _ctrlog.Append(Data.use, "Xóa khách hàng: " + sten.Trim()); }
                        catch { }
                        HienThiDS();
                    }
                    else
                    {
                        MessageBox.Show(loi, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Dữ liệu hiện tại đang trắng.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            c1FlexGrid1.Focus();
        }
        private void HienThiTTHoaDon()
        {
            tblhoadonban   objhd = new tblhoadonban();
            tblhoadonbanBL ctrhd = new tblhoadonbanBL();

            objhd = ctrhd.GetByID(sidhd);
            try{
                tblkhachhang   objkh = new tblkhachhang();
                tblkhachhangBL ctrkh = new tblkhachhangBL();
                objkh            = ctrkh.GetByID(objhd.id_khachhang.Trim());
                lbCapDL.Text     = objkh.id_capdl;
                lbDiaChi.Text    = objkh.diachi;
                lbDienThoai.Text = objkh.dt;
                lbNgayXuat.Text  = objhd.ngaytao.ToString("dd/MM/yyyy HH:mm:ss");
                lbTenKH.Text     = objkh.tenkh;
            }
            catch {
                lbCapDL.Text     = "-/-";
                lbDiaChi.Text    = "-/-";
                lbDienThoai.Text = "-/-";
                lbNgayXuat.Text  = "-/-";
                lbTenKH.Text     = "-/-";
            }
        }
        private void cbKhachHang_SelectedIndexChanged(object sender, EventArgs e)
        {
            tblhoadontraBL ctrhdb     = new tblhoadontraBL();
            tblmathangBL   ctrmathang = new tblmathangBL();
            string         sidkh      = "";

            try { sidkh = cbKhachHang.SelectedValue.ToString().Trim(); }
            catch { }
            tblkhachhang   obj = new tblkhachhang();
            tblkhachhangBL ctr = new tblkhachhangBL();

            obj = ctr.GetByID(sidkh);
            try
            {
                DateTime dtngaytao = new DateTime();
                dtngaytao = DateTime.ParseExact(
                    txtNgayXuat.Text.Trim(),
                    "dd/MM/yyyy HH:mm:ss",
                    CultureInfo.InvariantCulture);
                cbCapDL.Text      = obj.id_capdl;
                txtDiaChi.Text    = obj.diachi;
                txtDienThoai.Text = obj.dt.Trim();
                try
                {
                    double tongtien = 0;
                    for (int i = 1; i < flxMatHang.Rows.Count; i++)
                    {
                        try
                        {
                            string sidmathang = "";
                            try { sidmathang = flxMatHang[i, "id_mathang"].ToString(); }
                            catch { }
                            tblmathang objmathang = new tblmathang();
                            objmathang = ctrmathang.GetByID(sidmathang);
                            try
                            {
                                if (cbCapDL.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 1") == true)
                                {
                                    flxMatHang[i, "gianhaplai"] = objmathang.giadl1.ToString().Trim();
                                    try { flxMatHang[i, "thanhtien"] = Convert.ToInt32(flxMatHang[i, "soluong"]) * objmathang.giadl1; }
                                    catch { }
                                }
                                if (cbCapDL.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 2") == true)
                                {
                                    flxMatHang[i, "gianhaplai"] = objmathang.giadl2.ToString().Trim();
                                    try { flxMatHang[i, "thanhtien"] = Convert.ToInt32(flxMatHang[i, "soluong"]) * objmathang.giadl2; }
                                    catch { }
                                }
                                if (cbCapDL.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 3") == true)
                                {
                                    flxMatHang[i, "gianhaplai"] = objmathang.giadl3.ToString().Trim();
                                    try { flxMatHang[i, "thanhtien"] = Convert.ToInt32(flxMatHang[i, "soluong"]) * objmathang.giadl3; }
                                    catch { }
                                }
                                if (cbCapDL.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 4") == true)
                                {
                                    flxMatHang[i, "gianhaplai"] = objmathang.giadl4.ToString().Trim();
                                    try { flxMatHang[i, "thanhtien"] = Convert.ToInt32(flxMatHang[i, "soluong"]) * objmathang.giadl4; }
                                    catch { }
                                }
                                if (cbCapDL.Text.ToUpper().Trim().Equals("ĐẠI LÝ CẤP 5") == true)
                                {
                                    flxMatHang[i, "gianhaplai"] = objmathang.giadl5.ToString().Trim();
                                    try { flxMatHang[i, "thanhtien"] = Convert.ToInt32(flxMatHang[i, "soluong"]) * objmathang.giadl5; }
                                    catch { }
                                }
                                if (cbCapDL.Text.ToUpper().Trim().Equals("KHÁCH LẺ") == true)
                                {
                                    flxMatHang[i, "gianhaplai"] = objmathang.giadl5.ToString().Trim();
                                    try { flxMatHang[i, "thanhtien"] = Convert.ToInt32(flxMatHang[i, "soluong"]) * objmathang.giadl5; }
                                    catch { }
                                }
                            }
                            catch
                            {
                                flxMatHang[i, "gianhaplai"] = objmathang.giadl5.ToString().Trim();
                                try { flxMatHang[i, "thanhtien"] = Convert.ToInt32(flxMatHang[i, "soluong"]) * objmathang.giadl5; }
                                catch { }
                            }
                            tongtien = tongtien + Convert.ToDouble(flxMatHang[i, "thanhtien"].ToString().Trim());
                        }
                        catch { }
                    }
                    txtTongTien.Text = tongtien.ToString("N0", CultureInfo.InvariantCulture);
                }
                catch { }
            }
            catch
            {
                cbCapDL.Text      = "";
                txtDiaChi.Text    = "";
                txtDienThoai.Text = "";
                txtTongTien.Text  = "0";
            }
        }
Example #10
0
        private void Save()
        {
            string              temploi = "";
            string              loi     = "";
            tblkhachhangBL      _ctr    = new tblkhachhangBL();
            List <tblkhachhang> lst     = new List <tblkhachhang>();

            lst = GetData();
            if (lst != null)
            {
                for (int i = 0; i < lst.Count; i++)
                {
                    loi = "";
                    tblkhachhang _obj = new tblkhachhang();
                    try { _obj = _ctr.GetByID(lst[i].id); }
                    catch { }
                    if (_obj == null)
                    {
                        try { loi = c1FlexGrid1.GetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "tenkh").ToString().Trim(); }
                        catch { }
                        if (loi.Equals("") == true)
                        {
                            loi = _ctr.Insert(lst[i]);
                            if (loi.Equals("") == false)
                            {
                                c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror;
                            }
                            else
                            {
                                _ctrlog.Append(Data.use, "Thêm mới khách hàng: " + lst[i].tenkh.Trim());
                            }
                        }
                        else
                        {
                            c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror;
                        }
                        if (loi.Trim().Equals("") == false)
                        {
                            temploi = loi;
                        }
                    }
                    else
                    {
                        try { loi = c1FlexGrid1.GetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "tenkh").ToString().Trim(); }
                        catch { }
                        if (loi.Equals("") == true)
                        {
                            loi = _ctr.Update(lst[i]);
                            if (loi.Equals("") == false)
                            {
                                c1FlexGrid1.SetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "tenkh", loi);
                                c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror;
                            }
                            else
                            {
                                _ctrlog.Append(Data.use, "Cập nhật khách hàng: " + lst[i].tenkh.Trim());
                            }
                        }
                        else
                        {
                            c1FlexGrid1.SetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "tenkh", loi);
                            c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror;
                        }
                        if (loi.Trim().Equals("") == false)
                        {
                            temploi = loi;
                        }
                    }
                }
            }
            if (temploi.Trim().Equals("") == true)
            {
                HienThiDS();
                MessageBox.Show("Cập nhật dữ liệu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Cập nhật dữ liệu không thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void FormatGrid()
        {
            tblkhachhang   objkh = new tblkhachhang();
            tblkhachhangBL ctrkh = new tblkhachhangBL();

            objkh = ctrkh.GetByID(sidkh);
            for (int i = 0; i < c1FlexGrid1.Cols.Count; i++)
            {
                if (c1FlexGrid1.Cols[i].Caption.Equals("stt"))
                {
                    c1FlexGrid1[0, i] = "Stt"; c1FlexGrid1.Cols[i].Visible = true; c1FlexGrid1.Cols[i].AllowEditing = false;
                }
                else if (c1FlexGrid1.Cols[i].Caption.Equals("tenhang"))
                {
                    c1FlexGrid1[0, i] = "Hãng(*)"; c1FlexGrid1.Cols[i].Visible = true;
                }
                else if (c1FlexGrid1.Cols[i].Caption.Equals("tenloai"))
                {
                    c1FlexGrid1[0, i] = "Loại(*)"; c1FlexGrid1.Cols[i].Visible = false;
                }
                else if (c1FlexGrid1.Cols[i].Caption.Equals("ten"))
                {
                    c1FlexGrid1[0, i] = "Tên(*)"; c1FlexGrid1.Cols[i].Visible = true;
                }
                else if (c1FlexGrid1.Cols[i].Caption.Equals("donvi"))
                {
                    c1FlexGrid1[0, i]           = "ĐV";
                    c1FlexGrid1.Cols[i].Visible = true;
                }
                else if (c1FlexGrid1.Cols[i].Caption.Equals("giadl1") == true && objkh.id_capdl.ToLower().Trim().Equals("đại lý cấp 1") == true)
                {
                    c1FlexGrid1[0, i] = "Giá bán"; c1FlexGrid1.Cols[i].Visible = true;
                }
                else if (c1FlexGrid1.Cols[i].Caption.Equals("giadl2") == true && objkh.id_capdl.ToLower().Trim().Equals("đại lý cấp 2") == true)
                {
                    c1FlexGrid1[0, i] = "Giá bán"; c1FlexGrid1.Cols[i].Visible = true;
                }
                else if (c1FlexGrid1.Cols[i].Caption.Equals("giadl3") == true && objkh.id_capdl.ToLower().Trim().Equals("đại lý cấp 3") == true)
                {
                    c1FlexGrid1[0, i] = "Giá bán"; c1FlexGrid1.Cols[i].Visible = true;
                }
                else if (c1FlexGrid1.Cols[i].Caption.Equals("giadl4") == true && objkh.id_capdl.ToLower().Trim().Equals("đại lý cấp 4") == true)
                {
                    c1FlexGrid1[0, i] = "Giá bán"; c1FlexGrid1.Cols[i].Visible = true;
                }
                else if (c1FlexGrid1.Cols[i].Caption.Equals("giadl5") == true && objkh.id_capdl.ToLower().Trim().Equals("đại lý cấp 5") == true)
                {
                    c1FlexGrid1[0, i] = "Giá bán"; c1FlexGrid1.Cols[i].Visible = true;
                }
                else
                {
                    c1FlexGrid1.Cols[i].Visible = false;
                }
                c1FlexGrid1.Cols[i].TextAlignFixed = TextAlignEnum.CenterCenter;
            }
            Font _font = new Font("Time new Roman", 14);

            c1FlexGrid1.Font = _font;
            //for (int j = 1; j < c1FlexGrid1.Rows.Count; j++)
            //{
            //    c1FlexGrid1[j, 0] = j;
            //}
            c1FlexGrid1.Cols[0].TextAlign = TextAlignEnum.CenterCenter;
            c1FlexGrid1.AutoSizeCols();
            c1FlexGrid1.AutoSizeRows();
            txtKeyword.Focus();
        }