Ejemplo n.º 1
0
 private void LoadDataGridView()
 {
     cnct = BUS_CNCT.hienthiCNCT(); //Lấy dữ liệu từ bảng
     dgvcongno.DataSource         = cnct;
     dgvcongno.AllowUserToAddRows = false;
     dgvcongno.EditMode           = DataGridViewEditMode.EditProgrammatically;
 }
Ejemplo n.º 2
0
        private void btntimkiem_Click(object sender, EventArgs e)
        {
            if (cbmanv.Text.Trim() == string.Empty && cbmatkcn.Text.Trim() == "Mã sẽ tự động thêm!")
            {
                MessageBox.Show("Bạn phải nhập điều kiện tìm kiếm!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            btnhienthi.Enabled = true;

            DTO_CN CN = new DTO_CN();

            if (cbmatkcn.Text.Trim() == "Mã sẽ tự động thêm!")
            {
                CN.Macn = "";
            }
            else
            {
                CN.Macn = cbmatkcn.Text.Trim();
            }
            CN.Manv = cbmanv.Text.Trim();
            DataTable dt = BUS_CN.timkiemCN(CN.Manv, CN.Macn);

            if (dt.Rows.Count == 0)
            {
                lblsoluongtk.Text    = "Không có báo cáo nào thoả mãn điều kiện tìm kiếm!";
                dgvcongno.DataSource = BUS_CNCT.hienthiCNCTcuthe("NULL");
            }
            else
            {
                lblsoluongtk.Text = "Có " + dt.Rows.Count + " báo cáo nào thoả mãn điều kiện tìm kiếm!";

                //Thêm soucre khi kết quả tìm kiếm trả về nhiều bảng thống kê hàng tồn.

                List <DTO_CNCT> row = new List <DTO_CNCT>();
                for (int i = 0; i < dt.Rows.Count; ++i)
                {
                    DataRow   dr = dt.Rows[i];
                    DataTable DT = BUS_CNCT.hienthiCNCTcuthe(dr[0].ToString());
                    if (DT.Rows.Count > 0)
                    {
                        for (int j = 0; j < DT.Rows.Count; ++j)
                        {
                            dr = DT.Rows[i];
                            DTO_CNCT cnct = new DTO_CNCT(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), dr[5].ToString());
                            row.Add(cnct);
                        }
                    }
                }

                dgvcongno.DataSource = row;
            }
            DANGNHAP.thaotac += "Tìm kiếm, ";
        }
Ejemplo n.º 3
0
        private void cbmatkht_TextChanged(object sender, EventArgs e)
        {
            DataTable dt = BUS_CNCT.hienthiCNCTcuthe(cbmatkcn.Text.Trim());

            if (cbmatkcn.Text.Trim() != string.Empty)
            {
                if (dt.Rows.Count > 0)
                {
                    dgvcongno.DataSource = dt;
                    dt = BUS_CN.hienthiCNcuthe(cbmatkcn.Text.Trim());
                    DataRow dr = dt.Rows[0];
                    cbmanv.Text    = dr[1].ToString();
                    dtpngaytk.Text = dr[2].ToString();
                }
                else
                {
                    dgvcongno.DataSource = dt;
                    cbmanv.Text          = string.Empty;
                    dtpngaytk.Value      = DateTime.Now;
                    txtmancu.Text        = string.Empty;
                    txtconno.Text        = string.Empty;
                    txtmancu.Text        = string.Empty;
                    txttenncu.Text       = string.Empty;
                    txtsdt.Text          = string.Empty;
                    txtdiachi.Text       = string.Empty;
                }
            }
            else
            {
                dgvcongno.DataSource = dt;
                cbmanv.Text          = string.Empty;
                dtpngaytk.Value      = DateTime.Now;
                txtmancu.Text        = string.Empty;
                txtconno.Text        = string.Empty;
                txtmancu.Text        = string.Empty;
                txttenncu.Text       = string.Empty;
                txtsdt.Text          = string.Empty;
                txtdiachi.Text       = string.Empty;
            }
        }
Ejemplo n.º 4
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (ncu.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaNCU.Text == "Mã nhà cung ứng sẽ tự động thêm!")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("Xoá nhà cung ứng sẽ xoá tất cả dữ liệu của nhà cung ứng và tất cả các thông tin về nhà cung ứng trên bảng sản phẩm, bảng hoá đơn nhập, bảng hoá đơn bán và bảng thống kê công nợ. Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                //Lấy mã nhà cung ứng trên bảng thống kê công nợ và xoá thông tin của NCƯ trên bảng thống kê công nợ.
                List <string> id = new List <string>();
                DataTable     dt;
                DataRow       dr;
                dt = BUS_CNCT.hienthiCNCT();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        if (dr[1].ToString() == txtMaNCU.Text)
                        {
                            id.Add(dr["IdCN"].ToString());
                        }
                    }
                }

                //Xóa trên bảng công nợ chi tiết
                foreach (string item in id)
                {
                    BUS_CN.RunDelSQLOnCNCT(item);
                }

                id.Clear();

                //xóa nhà cung ứng trên bảng hóa đơn nhập
                //Lấy mã hóa đơn nhập trên bảng hóa đơn nhập
                dt = BUS_HDN.hienthiHDN();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        if (dr[2].ToString() == txtMaNCU.Text)
                        {
                            id.Add(dr["IdHDN"].ToString());
                        }
                    }
                }

                //Xóa trên bảng hóa đơn nhập chi tiết
                foreach (string item in id)
                {
                    BUS_HDN.RunDelSQLOnHDNCT(item);
                    BUS_HDN.RunDelSQL(item);
                }

                id.Clear();

                //Lấy mã sản phẩm trên bảng sản phẩm để xóa sản phẩm
                dt = BUS_SP.hienthisp();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        if (dr[1].ToString() == txtMaNCU.Text)
                        {
                            id.Add(dr["IdSP"].ToString());
                        }
                    }
                }

                //Xóa trên bảng sản phẩm
                foreach (string item in id)
                {
                    BUS_SP.RunDelSQLOnHTCT(item);
                    BUS_SP.RunDelSQLOnHDBCT(item);
                    BUS_SP.RunDelSQLOnHDNCT(item);
                    BUS_SP.RunDelSQL(item);
                }

                BUS_NCU.RunDelSQL(txtMaNCU.Text);

                LoadDataGridView();
                ResetValues();

                //Cập nhật lại mã nhà cung ứng trên combobx mã nhà cung ứng trên form sản phẩm.
                CapnhatCB_NCU();
                DANGNHAP.thaotac += "Xoá, ";
            }
        }
Ejemplo n.º 5
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (cbmanv.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cbmanv.Focus();
                return;
            }
            string manv = cbmanv.Text;
            //Kiểm tra có bảng thống kê nào rỗng hay không nếu là rỗng thì xóa đi và cập nhật lại combobox tương ứng
            DataTable table = BUS_CN.hienthiCN();

            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; ++i)
                {
                    DataRow r = table.Rows[0];
                    if (BUS_CNCT.hienthiCNCTcuthe(r[0].ToString()).Rows.Count == 0)
                    {
                        BUS_CN.RunDelSQL(r[0].ToString());
                    }
                }
                BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN");
                cbmatkcn.SelectedIndex = -1;
            }

            //Kiểm tra xem có thống kê nào trong tháng được tạo chưa để cập nhật mới

            DataTable dt = BUS_CN.KiemtraTKCNTonTai(DateTime.Now.Month.ToString(), DateTime.Now.Year.ToString());

            if (dt.Rows.Count == 1)
            {
                DataRow row = dt.Rows[0];

                //Cập nhật thống kê hàng tồn chi tiết
                dt = BUS_NCU.hienthiNCU();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        DataRow r = dt.Rows[i];
                        //Cập nhật lại nợ nhà cung ứng, nếu nợ = 0 thì xóa nhà cung ứng ra khỏi danh sách nợ
                        BUS_CNCT.CapnhatTKCNCT(row[0].ToString(), r[0].ToString());
                    }

                    //Nếu nhà cung ứng bị xóa khỏi danh sách nhưng sau đó có thêm nợ thì thêm nhà cung ứng vào danh sách nợ
                    DataTable DT = BUS_CNCT.hienthiCNCTcuthe(row[0].ToString());

                    //Lập danh sách các nhà cung ứng không có trong danh sách nợ
                    List <string> idncu = new List <string>();
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        bool    flag = false;
                        DataRow r    = dt.Rows[i];
                        for (int j = 0; j < DT.Rows.Count; ++j)
                        {
                            DataRow dr = DT.Rows[j];
                            if (r[0].ToString() == dr[1].ToString())
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag == false)
                        {
                            idncu.Add(r[0].ToString());
                        }
                    }
                    foreach (string item in idncu)
                    {
                        DataRow r = BUS_NCU.hienthiNCUcuthe(item).Rows[0];
                        //Thêm thống kê công nợ chi tiết
                        DTO_CNCT CNCT = new DTO_CNCT(row[0].ToString(), r[0].ToString(), r[1].ToString(), r[3].ToString(), r[2].ToString(), r[5].ToString());
                        BUS_CNCT.themCNCT(CNCT);
                    }
                }
                //Cập nhật ngày thống kê
                BUS_CN.CapnhatNgayTK(row[0].ToString(), DateTime.Now.ToString());

                BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN");
                cbmatkcn.SelectedIndex = -1;

                ResetValues();
                LoadDataGridView();

                DANGNHAP.thaotac += "Thêm, ";

                MessageBox.Show("Đã thống kê xong!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                //tạo mã ngẫu nhiên
                int    value;
                bool   kt   = false;
                Random rand = new Random();
                value = rand.Next(100000000, 999999999);
                string  macn = "CN" + value;
                DataRow dr;
                if (BUS_CN.hienthiCN().Rows.Count > 0)
                {
                    while (kt == false)
                    {
                        for (int i = 0; i < BUS_CN.hienthiCN().Rows.Count; ++i)
                        {
                            dr = BUS_CN.hienthiCN().Rows[i];
                            if (macn == dr["IdCN"].ToString())
                            {
                                kt    = false;
                                value = rand.Next(100000000, 999999999);
                                macn  = "CN" + value;
                                break;
                            }
                            else
                            {
                                kt = true;
                            }
                        }
                    }
                }

                //Kiểm tra đã tồn tại mã thống kê hàng tồn
                if (!BUS_CN.ktCNtrung(macn))
                {
                    MessageBox.Show("Mã công nợ đã tồn tại! Hãy nhấn Thêm lần nữa để lấy mã khác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    btnThem.Focus();
                    return;
                }

                //Chèn thêm
                //Thêm thống kê công nợ
                DTO_CN CN = new DTO_CN(macn, manv, DateTime.Now.ToString());
                BUS_CN.themCN(CN);

                //Thêm thống kê công nợ chi tiết
                dt = BUS_NCU.hienthiNCU();
                DTO_CNCT CNCT;
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        DataRow r = dt.Rows[i];
                        CNCT = new DTO_CNCT(macn, r[0].ToString(), r[1].ToString(), r[3].ToString(), r[2].ToString(), r[5].ToString());
                        BUS_CNCT.themCNCT(CNCT);
                    }
                }

                //giữ thông tin chung của thống kê vừa thêm trên các control
                dt = BUS_CN.hienthiCNcuthe(macn);
                if (dt.Rows.Count == 1)
                {
                    DataRow r = dt.Rows[0];
                    cbmatkcn.Text  = r[0].ToString();
                    cbmanv.Text    = r[1].ToString();
                    dtpngaytk.Text = r[2].ToString();
                }

                BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN");
                cbmatkcn.SelectedIndex = -1;

                ResetValues();
                LoadDataGridView();

                DANGNHAP.thaotac += "Thêm, ";

                MessageBox.Show("Đã thống kê xong!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }