public static ArrayList layDanhSachNguyenLieuTheoMonAn(MonAnDTO monAn)
        {
            DbCommand command = DataAccessCode.CreateCommand();

            command.CommandText = "dbo.LayDanhSachNguyenLieuTheoMonAn";
            DbParameter param = command.CreateParameter();

            param.ParameterName = "@MaMonAn";
            param.Value         = monAn.MaMonAn;
            param.DbType        = DbType.Int32;
            command.Parameters.Add(param);

            DataTable dt   = DataAccessCode.ExecuteSelectCommand(command);
            ArrayList list = new ArrayList();

            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    MonAn_NguyenLieuDTO dto = new MonAn_NguyenLieuDTO();
                    dto.NguyenLieu.MaNguyenLieu  = Convert.ToInt32(dt.Rows[i]["MaNguyenLieu"]);
                    dto.NguyenLieu.TenNguyenLieu = dt.Rows[i]["TenNguyenLieu"].ToString();
                    dto.NguyenLieu.DonViTinh     = dt.Rows[i]["DonViTinh"].ToString();
                    dto.SoLuong = Convert.ToInt32(dt.Rows[i]["SoLuong"]);
                    list.Add(dto);
                }
            }
            return(list);
        }
示例#2
0
        public static void cb_monAn_SelectedIndexChangedShowComboNguyenLieu(ComboBox cb_monAn, ComboBox cb_nguyenLieu)
        {
            cb_nguyenLieu.Items.Clear();

            MonAn_NguyenLieuDTO dto = new MonAn_NguyenLieuDTO();

            dto.NguyenLieu.TenNguyenLieu = "Tất cả";
            dto.NguyenLieu.MaNguyenLieu  = 0;

            cb_nguyenLieu.Items.Add(dto);
            if (cb_monAn.Items.Count == 0)
            {
                return;
            }
            if (cb_monAn.SelectedIndex != 0)
            {
                showDanhSachNguyenLieuTheoMonAnLenComboNguyenLieu(((PhanLoaiMonAnDTO)cb_monAn.SelectedItem).MonAn, cb_nguyenLieu);
            }
            else if (cb_monAn.SelectedIndex == 0)
            {
                for (int i = 1; i < cb_monAn.Items.Count; i++)
                {
                    showDanhSachNguyenLieuTheoMonAnLenComboNguyenLieu(((PhanLoaiMonAnDTO)cb_monAn.Items[i]).MonAn, cb_nguyenLieu);
                }
            }
            if (cb_nguyenLieu.Items.Count == 0)
            {
                cb_nguyenLieu.Text    = "Không có";
                cb_nguyenLieu.Enabled = false;
                return;
            }
            cb_nguyenLieu.Enabled       = true;
            cb_nguyenLieu.SelectedIndex = 0;
        }
 private bool isIngrid_nguyenLieuCanDatHangOrNot(MonAn_NguyenLieuDTO dto)
 {
     for (int i = 0; i < grid_nguyenLieuCanDatHang.RowCount; i++)
     {
         if (((MonAn_NguyenLieuDTO)grid_nguyenLieuCanDatHang.Rows[i].Cells["grid_nguyenLieuCanDatHang_cNguyenLieu"].Value).NguyenLieu.MaNguyenLieu == dto.NguyenLieu.MaNguyenLieu)
         {
             return(true);
         }
     }
     return(false);
 }
示例#4
0
        public static void showDanhSachNguyenLieuTheoMonAnLenComboNguyenLieu(MonAnDTO monAn, ComboBox cb)
        {
            ArrayList dsNguyenLieuTheoMon = new ArrayList();

            dsNguyenLieuTheoMon = MonAnBUS.layDanhSachNguyenLieuTheoMonAn(monAn);


            for (int i = 0; i < dsNguyenLieuTheoMon.Count; i++)
            {
                MonAn_NguyenLieuDTO dto = (MonAn_NguyenLieuDTO)dsNguyenLieuTheoMon[i];
                cb.Items.Add(dto);
            }
        }
        private void highlightNguyenLieuDaChonDuocNhaCungCapDapUng(NhaCungCapDTO dto)
        {
            ArrayList temp = dto.DsNguyenLieu;
            int       soDongGrid_nguyenLieuCanDatHang = grid_nguyenLieuCanDatHang.RowCount;

            for (int i = 0; i < soDongGrid_nguyenLieuCanDatHang; i++)
            {
                if (Convert.ToBoolean(grid_nguyenLieuCanDatHang.Rows[i].Cells[0].Value) == true)
                {
                    for (int j = 0; j < temp.Count; j++)
                    {
                        NguyenLieuDTO       nlNCC        = (NguyenLieuDTO)temp[j];
                        MonAn_NguyenLieuDTO nlCanDatHang = (MonAn_NguyenLieuDTO)grid_nguyenLieuCanDatHang.Rows[i].Cells["grid_nguyenLieuCanDatHang_cNguyenLieu"].Value;

                        if (nlNCC.MaNguyenLieu == nlCanDatHang.NguyenLieu.MaNguyenLieu)
                        {
                            grid_nguyenLieuCanDatHang.Rows[i].DefaultCellStyle.BackColor = Color.LightBlue;
                        }
                    }
                }
            }
        }
        private void bt_themVaoDanhSachNguyenLieuCanDatHang_Click(object sender, EventArgs e)
        {
            MonAn_NguyenLieuDTO curItem = (MonAn_NguyenLieuDTO)cb_nguyenLieu.SelectedItem;

            if (curItem.NguyenLieu.MaNguyenLieu == 0)
            {
                for (int i = 1; i < cb_nguyenLieu.Items.Count; i++)
                {
                    curItem = (MonAn_NguyenLieuDTO)cb_nguyenLieu.Items[i];
                    if (!isIngrid_nguyenLieuCanDatHangOrNot(curItem))
                    {
                        them1DongVaoGrid_nguyenLieuCanDatHang(curItem);
                    }
                }
            }
            else
            {
                if (!isIngrid_nguyenLieuCanDatHangOrNot(curItem))
                {
                    them1DongVaoGrid_nguyenLieuCanDatHang(curItem);
                }
            }
        }
        private void grid_tabPage_NCC_nhaCungCapPhuHop_CellDoubleClick(int indexSelectedRow)
        {
            //grid_tabPage_NCC_nhaCungCapPhuHop.Rows[indexSelectedRow].Cells[0].Value = !Convert.ToBoolean(grid_tabPage_NCC_nhaCungCapPhuHop.Rows[indexSelectedRow].Cells[0].Value);

            NhaCungCapDTO curNCC = (NhaCungCapDTO)grid_tabPage_NCC_nhaCungCapPhuHop.Rows[indexSelectedRow].Cells["grid_NCCPhuHop_cTenNhaCungCap"].Value;

            string sqlWHEREor = "";

            for (int i = 0; i < grid_nguyenLieuCanDatHang.RowCount; i++)
            {
                if (Convert.ToBoolean(grid_nguyenLieuCanDatHang.Rows[i].Cells[0].Value) == true)
                {
                    MonAn_NguyenLieuDTO dto = (MonAn_NguyenLieuDTO)grid_nguyenLieuCanDatHang.Rows[i].Cells["grid_nguyenLieuCanDatHang_cNguyenLieu"].Value;
                    sqlWHEREor += "NCCNL.MaNguyenLieu=" + dto.NguyenLieu.MaNguyenLieu.ToString();
                    int j = i + 1;
                    sqlWHEREor += " OR ";
                }
            }
            sqlWHEREor = sqlWHEREor.Substring(0, sqlWHEREor.Length - 3);
            ArrayList dsNguyenLieuPhuHopTheoNCC = NhaCungCapBUS.layDanhSachNguyenLieuNhaCungCapCoTheDapUngTheoDonDatHang(curNCC.MaNhaCungCap, sqlWHEREor);

            curNCC.DsNguyenLieu = dsNguyenLieuPhuHopTheoNCC;//grid_nguyenLieuCanDatHang
            highlightNguyenLieuDaChonDuocNhaCungCapDapUng(curNCC);
        }
        private void bt_timNCCPhuHop_Click(object sender, EventArgs e)
        {
            string sqlFROM = "";

            for (int i = 0; i < grid_nguyenLieuCanDatHang.RowCount; i++)
            {
                if (Convert.ToBoolean(grid_nguyenLieuCanDatHang.Rows[i].Cells[0].Value) == true)
                {
                    MonAn_NguyenLieuDTO dto = (MonAn_NguyenLieuDTO)grid_nguyenLieuCanDatHang.Rows[i].Cells["grid_nguyenLieuCanDatHang_cNguyenLieu"].Value;
                    sqlFROM += "(SELECT NHNCC.MaNhaCungCap, NCCNL.DonGia "
                               + " FROM NHAHANG_NHACUNGCAP NHNCC JOIN NHACUNGCAP_NGUYENLIEU NCCNL ON NHNCC.MaNhaCungCap=NCCNL.MaNhaCungCap"
                               + " WHERE NHNCC.TinhTrang=1 AND NCCNL.MaNguyenLieu=" + dto.NguyenLieu.MaNguyenLieu.ToString() + " AND NHNCC.MaNhaHang=" + GlobalVariables.maNhaHang.ToString() + ")";
                    int j = i + 1;

                    sqlFROM += " UNION ALL ";
                }
            }
            sqlFROM = sqlFROM.Substring(0, sqlFROM.Length - 10);
            ArrayList dsNCC = KhoHangBUS.traCuuNhaCungCapThoaYeuCauNguyenLieuCanDatHang(sqlFROM);

            if (dsNCC.Count == 0)
            {
                return;
            }
            grid_tabPage_NCC_nhaCungCapPhuHop.Rows.Clear();
            for (int i = 0; i < dsNCC.Count; i++)
            {
                NhaCungCapDTO dto = (NhaCungCapDTO)dsNCC[i];
                grid_tabPage_NCC_nhaCungCapPhuHop.Rows.Add();
                grid_tabPage_NCC_nhaCungCapPhuHop.Rows[i].Cells["grid_NCCPhuHop_cMaNhaCungCap"].Value  = dto.MaNhaCungCap;
                grid_tabPage_NCC_nhaCungCapPhuHop.Rows[i].Cells["grid_NCCPhuHop_cTenNhaCungCap"].Value = dto;
                grid_tabPage_NCC_nhaCungCapPhuHop.Rows[i].Cells["grid_NCCPhuHop_cSoLuongNguyenLieuThoaYeuCau"].Value = dto.SoLuongNguyenLieuToiDaPhuHopYeuCauDatHang;
            }
            grid_tabPage_NCC_nhaCungCapPhuHop.Sort(grid_tabPage_NCC_nhaCungCapPhuHop.Columns["grid_NCCPhuHop_cSoLuongNguyenLieuThoaYeuCau"], ListSortDirection.Descending);
            grid_tabPage_NCC_nhaCungCapPhuHop.Columns["grid_NCCPhuHop_cSoLuongNguyenLieuThoaYeuCau"].ReadOnly = false;
        }
 private void them1DongVaoGrid_nguyenLieuCanDatHang(MonAn_NguyenLieuDTO item)
 {
     grid_nguyenLieuCanDatHang.Rows.Add();
     grid_nguyenLieuCanDatHang.Rows[grid_nguyenLieuCanDatHang.RowCount - 1].Cells["grid_nguyenLieuCanDatHang_cNguyenLieu"].Value = item;
     grid_nguyenLieuCanDatHang.Rows[grid_nguyenLieuCanDatHang.RowCount - 1].Cells["grid_nguyenLieuCanDatHang_cDonVi"].Value      = item.NguyenLieu.DonViTinh;
 }