Exemple #1
0
        private void dtgvSanPham_DataSourceChanged(object sender, EventArgs e)
        {
            dtgvSanPham.Refresh();
            this.dtgvSanPham.Columns["HinhAnh"].Visible   = false;
            this.dtgvSanPham.Columns["TrangThai"].Visible = false;
            this.dtgvSanPham.Columns["GiaBan"].Visible    = false;

            this.dtgvSanPham.Columns["GiaSi"].DefaultCellStyle.Format  = "#,0";
            this.dtgvSanPham.Columns["GiaLe"].DefaultCellStyle.Format  = "#,0";
            this.dtgvSanPham.Columns["GiaGoc"].DefaultCellStyle.Format = "#,0";

            this.dtgvSanPham.Columns["NgayNhap"].DefaultCellStyle.Format    = "dd/MM/yyyy HH:mm:ss";
            this.dtgvSanPham.Columns["NgayCapNhat"].DefaultCellStyle.Format = "dd/MM/yyyy HH:mm:ss";

            this.dtgvSanPham.Columns["NgayCapNhat"].ReadOnly  = true;
            this.dtgvSanPham.Columns["NgayNhap"].ReadOnly     = true;
            this.dtgvSanPham.Columns["MaSanPham"].ReadOnly    = true;
            this.dtgvSanPham.Columns["NguoiNhap"].ReadOnly    = true;
            this.dtgvSanPham.Columns["NguoiCapNhat"].ReadOnly = true;


            //DataGridViewCheckBoxColumn CBColumn = new DataGridViewCheckBoxColumn();
            //CBColumn.HeaderText = "Chọn";
            //CBColumn.FalseValue = "0";
            //CBColumn.TrueValue = "1";
            //dtgvSanPham.Columns.Insert(0, CBColumn);

            DataGridViewImageColumn imageCol = new DataGridViewImageColumn();

            imageCol.Name       = "img";
            imageCol.HeaderText = "Hinh Anh";
            imageCol.Width      = _colWidth;
            dtgvSanPham.Columns.Insert(2, imageCol);


            foreach (DataGridViewRow row in this.dtgvSanPham.Rows)
            {
                row.Height = _rowHeight;

                string checkImgPath = Directory.GetCurrentDirectory();
                string imgPath      = Directory.GetCurrentDirectory();
                //if (row.Cells["HinhAnh"].Value.ToString() != "")
                //{

                //}
                //else
                //{
                //    imgPath = imgPath + @"\Hinh\NoImage.jpg";
                //}
                checkImgPath = checkImgPath + @"\Hinh\" + row.Cells["HinhAnh"].Value.ToString();
                if (File.Exists(checkImgPath) == true)
                {
                    imgPath = checkImgPath;
                }
                else
                {
                    imgPath = imgPath + @"\Hinh\NoImage.jpg";
                }


                Image image = Helper.ResizeImage(@imgPath, _imageSize, _imageSize, false);
                row.Cells["img"].Value = image;

                if (row.Cells["TrangThai"].Value.ToString() == "0" || Int32.Parse(row.Cells["SoLuong"].Value.ToString()) <= 0)
                {
                    row.DefaultCellStyle.BackColor = Color.Yellow;
                    //row.DefaultCellStyle.Font = new Font("Tahoma", 8, FontStyle.Bold);
                }
            }
        }
        private void formatData()
        {
            try
            {
                //dtgvDanhSachSanPham.Refresh();
                this.dtgvDanhSachSanPham_ChiTiet.Columns["HinhAnh"].Visible      = false;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["TrangThai"].Visible    = false;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["NgayNhap"].Visible     = false;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["NgayCapNhat"].Visible  = false;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["NguoiNhap"].Visible    = false;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["NguoiCapNhat"].Visible = false;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["GiaGoc"].Visible       = false;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["TrongLuong"].Visible   = false;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["SoLuong"].Visible      = false;

                this.dtgvDanhSachSanPham_ChiTiet.Columns["GiaSi"].DefaultCellStyle.Format  = "#,0";
                this.dtgvDanhSachSanPham_ChiTiet.Columns["GiaLe"].DefaultCellStyle.Format  = "#,0";
                this.dtgvDanhSachSanPham_ChiTiet.Columns["GiaGoc"].DefaultCellStyle.Format = "#,0";
                this.dtgvDanhSachSanPham_ChiTiet.Columns["GiaBan"].DefaultCellStyle.Format = "#,0";

                //this.dtgvDanhSachSanPham.Columns["NgayNhap"].DefaultCellStyle.Format = "dd/MM/yyyy HH:mm:ss";
                //this.dtgvDanhSachSanPham.Columns["NgayCapNhat"].DefaultCellStyle.Format = "dd/MM/yyyy HH:mm:ss";

                this.dtgvDanhSachSanPham_ChiTiet.Columns["NgayCapNhat"].ReadOnly = true;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["NgayNhap"].ReadOnly    = true;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["MaSanPham"].ReadOnly   = true;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["GiaLe"].ReadOnly       = true;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["GiaSi"].ReadOnly       = true;
                this.dtgvDanhSachSanPham_ChiTiet.Columns["GiaBan"].ReadOnly      = true;

                this.dtgvDanhSachSanPham_ChiTiet.Columns["GiaBan"].HeaderText = "TongTien";

                int tongTien = 0;
                int soLuong  = 0;

                foreach (DataGridViewRow row in this.dtgvDanhSachSanPham_ChiTiet.Rows)
                {
                    row.Height = _rowHeight;

                    string checkImgPath = Directory.GetCurrentDirectory();
                    string imgPath      = Directory.GetCurrentDirectory();

                    checkImgPath = checkImgPath + @"\Hinh\" + row.Cells["HinhAnh"].Value.ToString();
                    if (File.Exists(checkImgPath) == true)
                    {
                        imgPath = checkImgPath;
                    }
                    else
                    {
                        imgPath = imgPath + @"\Hinh\NoImage.jpg";
                    }


                    Image image = Helper.ResizeImage(@imgPath, _imageSize, _imageSize, false);
                    row.Cells["img"].Value = image;

                    if (row.Cells["TrangThai"].Value.ToString() == "0" || Int32.Parse(row.Cells["SoLuong"].Value.ToString()) <= 0)
                    {
                        row.DefaultCellStyle.BackColor = Color.Yellow;
                        row.Cells["MauSac"].ReadOnly   = true;
                    }

                    int sl = Int32.Parse(row.Cells["SoLuong"].Value.ToString());

                    if (((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items.Count == 0)
                    {
                        for (int i = 1; i <= sl; i++)
                        {
                            ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items.Add(i);
                        }
                        if (((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items.Count == 0)
                        {
                            ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items.Add(0);
                            ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).ReadOnly = true;
                        }
                        row.Cells["CmbSoLuong"].Value = ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items[0];
                    }

                    if (_gMaSP == row.Cells["MaSanPham"].Value.ToString())
                    {
                        row.Cells["CmbSoLuong"].Value = ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items[_gSL - 1];
                    }

                    if (rdGiaLe.Checked == true)
                    {
                        fromFormat = true;
                        row.Cells["GiaBan"].Value = Int32.Parse(row.Cells["CmbSoLuong"].Value.ToString()) * Int32.Parse(row.Cells["GiaLe"].Value.ToString());
                    }
                    else
                    {
                        fromFormat = true;
                        row.Cells["GiaBan"].Value = Int32.Parse(row.Cells["CmbSoLuong"].Value.ToString()) * Int32.Parse(row.Cells["GiaSi"].Value.ToString());
                    }



                    soLuong  += Int32.Parse(row.Cells["CmbSoLuong"].Value.ToString());
                    tongTien += Int32.Parse(row.Cells["GiaBan"].Value.ToString());
                }

                if (txtPhiVanChuyen_Them.Text != "")
                {
                    tongTien += Int32.Parse(txtPhiVanChuyen_Them.Text.ToString());
                }

                lbSoLuong.Text  = soLuong.ToString();
                lbTongTien.Text = tongTien.ToString("n0");
                fromFormat      = false;
                _gMaSP          = "";
                _gSL            = 0;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #3
0
        private void formatData()
        {
            try
            {
                //dtgvDanhSachSanPham.Refresh();
                this.dtgvDanhSachSanPham.Columns["HinhAnh"].Visible          = false;
                this.dtgvDanhSachSanPham.Columns["MaChiTietDonHang"].Visible = false;
                this.dtgvDanhSachSanPham.Columns["SoLuongTrongKho"].Visible  = false;

                this.dtgvDanhSachSanPham.Columns["GiaSi"].DefaultCellStyle.Format  = "#,0";
                this.dtgvDanhSachSanPham.Columns["GiaLe"].DefaultCellStyle.Format  = "#,0";
                this.dtgvDanhSachSanPham.Columns["GiaBan"].DefaultCellStyle.Format = "#,0";

                this.dtgvDanhSachSanPham.Columns["MaSanPham"].ReadOnly       = true;
                this.dtgvDanhSachSanPham.Columns["GiaLe"].ReadOnly           = true;
                this.dtgvDanhSachSanPham.Columns["GiaSi"].ReadOnly           = true;
                this.dtgvDanhSachSanPham.Columns["GiaBan"].ReadOnly          = true;
                this.dtgvDanhSachSanPham.Columns["SoLuongTrongKho"].ReadOnly = true;

                int tongTien = 0;
                int soLuong  = 0;

                foreach (DataGridViewRow row in this.dtgvDanhSachSanPham.Rows)
                {
                    row.Height = _rowHeight;

                    string checkImgPath = Directory.GetCurrentDirectory();
                    string imgPath      = Directory.GetCurrentDirectory();

                    checkImgPath = checkImgPath + @"\Hinh\" + row.Cells["HinhAnh"].Value.ToString();
                    if (File.Exists(checkImgPath) == true)
                    {
                        imgPath = checkImgPath;
                    }
                    else
                    {
                        imgPath = imgPath + @"\Hinh\NoImage.jpg";
                    }


                    Image image = Helper.ResizeImage(@imgPath, _imageSize, _imageSize, false);
                    row.Cells["img"].Value = image;


                    if (rdGiaLe.Checked == true)
                    {
                        fromFormat = true;
                        row.Cells["GiaBan"].Value = Int32.Parse(row.Cells["SoLuongDatMua"].Value.ToString()) * Int32.Parse(row.Cells["GiaLe"].Value.ToString());
                    }
                    else
                    {
                        fromFormat = true;
                        row.Cells["GiaBan"].Value = Int32.Parse(row.Cells["SoLuongDatMua"].Value.ToString()) * Int32.Parse(row.Cells["GiaSi"].Value.ToString());
                    }



                    soLuong  += Int32.Parse(row.Cells["SoLuongDatMua"].Value.ToString());
                    tongTien += Int32.Parse(row.Cells["GiaBan"].Value.ToString());
                }

                if (txtPhiVanChuyen.Text != "")
                {
                    tongTien += Int32.Parse(txtPhiVanChuyen.Text.ToString());
                }

                lbSoLuong.Text  = soLuong.ToString();
                lbTongTien.Text = tongTien.ToString("n0");
                fromFormat      = false;
                _gMaSP          = "";
                _gSL            = 0;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #4
0
        public void formatData()
        {
            try
            {
                //dtgvDanhSachSanPham.Refresh();
                this.dtgvDanhSachSanPham.Columns["HinhAnh"].Visible          = false;
                this.dtgvDanhSachSanPham.Columns["MaChiTietDonHang"].Visible = false;
                this.dtgvDanhSachSanPham.Columns["TrangThai"].Visible        = false;
                this.dtgvDanhSachSanPham.Columns["SoLuongDatMua"].Visible    = false;

                this.dtgvDanhSachSanPham.Columns["GiaSi"].DefaultCellStyle.Format  = "#,0";
                this.dtgvDanhSachSanPham.Columns["GiaLe"].DefaultCellStyle.Format  = "#,0";
                this.dtgvDanhSachSanPham.Columns["GiaBan"].DefaultCellStyle.Format = "#,0";

                this.dtgvDanhSachSanPham.Columns["MaSanPham"].ReadOnly = true;
                this.dtgvDanhSachSanPham.Columns["GiaLe"].ReadOnly     = true;
                this.dtgvDanhSachSanPham.Columns["GiaSi"].ReadOnly     = true;
                this.dtgvDanhSachSanPham.Columns["GiaBan"].ReadOnly    = true;
                this.dtgvDanhSachSanPham.Columns["TrangThai"].ReadOnly = true;

                int tongTien = 0;
                int soLuong  = 0;

                //DonHangDTO dhDto = new DonHangDTO();
                //DonHangBUS dhBus = new DonHangBUS();
                //dhDto = dhBus.LayBangMaDonHang(_maDH);

                foreach (DataGridViewRow row in this.dtgvDanhSachSanPham.Rows)
                {
                    row.Height = _rowHeight;

                    if (row.Cells["img"].Value == null)
                    {
                        string checkImgPath = Directory.GetCurrentDirectory();
                        string imgPath      = Directory.GetCurrentDirectory();

                        checkImgPath = checkImgPath + @"\Hinh\" + row.Cells["HinhAnh"].Value.ToString();
                        if (File.Exists(checkImgPath) == true)
                        {
                            imgPath = checkImgPath;
                        }
                        else
                        {
                            imgPath = imgPath + @"\Hinh\NoImage.jpg";
                        }


                        Image image = Helper.ResizeImage(@imgPath, _imageSize, _imageSize, false);
                        row.Cells["img"].Value = image;
                    }

                    //if (Int32.Parse(row.Cells["SoLuongTrongKho"].Value.ToString()) <= 0 && _firstLoad == false)
                    //{
                    //    row.DefaultCellStyle.BackColor = Color.Yellow;
                    //    //row.Cells["MauSac"].ReadOnly = true;
                    //}

                    //int sl;
                    //SanPhamDTO spDto = SanPhamBUS.LaySanPham(row.Cells["MaSanPham"].Value.ToString());

                    if (_fromTxtMaSpTextChange == true)
                    {
                        SanPhamDTO spDto = SanPhamBUS.LaySanPham(row.Cells["MaSanPham"].Value.ToString());
                        if (spDto.TrangThai == 0)
                        {
                            row.DefaultCellStyle.BackColor = Color.Yellow;
                        }
                        _fromTxtMaSpTextChange = false;
                    }
                    else
                    {
                        if (row.Cells["TrangThai"].Value.ToString() == "0")
                        {
                            row.DefaultCellStyle.BackColor = Color.Yellow;
                        }
                    }


                    //ChiTietDonHangBUS ctdhBus = new ChiTietDonHangBUS();
                    //ChiTietDonHangDTO ctdhDto = ctdhBus.KiemTraTonTai(_maDH, row.Cells["MaSanPham"].Value.ToString());

                    //if ((dhDto.TrangThai == 2 || dhDto.TrangThai == 5) && ctdhDto.MaChiTietDonHang != 0)
                    //{
                    //    //sl = Int32.Parse(row.Cells["SoLuongDatMua"].Value.ToString()) + spDto.SoLuong;
                    //    sl = ctdhDto.SoLuong + spDto.SoLuong;
                    //}
                    //else
                    //{
                    //    sl = spDto.SoLuong;
                    //}

                    //sl = ctdhDto.SoLuong + spDto.SoLuong;

                    if (((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items.Count == 0)
                    {
                        for (int i = 0; i <= 30; i++)
                        {
                            ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items.Add(i);
                        }
                        if (((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items.Count == 0)
                        {
                            ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items.Add(0);
                            ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).ReadOnly = true;
                        }

                        if (_firstLoad == true)
                        {
                            ChiTietDonHangBUS ctdhBus = new ChiTietDonHangBUS();
                            ChiTietDonHangDTO ctdhDto = ctdhBus.KiemTraTonTai(_maDH, row.Cells["MaSanPham"].Value.ToString());
                            row.Cells["CmbSoLuong"].Value = ctdhDto.SoLuong;
                        }
                        else
                        {
                            row.Cells["CmbSoLuong"].Value = ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items[1];
                        }
                    }

                    //if (_firstLoad == true)
                    //{
                    //    row.Cells["CmbSoLuong"].Value = Int32.Parse(row.Cells["SoLuongDatMua"].Value.ToString());
                    //}
                    //else
                    //{
                    //    if (_gMaSP == row.Cells["MaSanPham"].Value.ToString())
                    //    {
                    //        row.Cells["CmbSoLuong"].Value = ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items[_gSL - 1];
                    //    }
                    //}

                    if (_gMaSP == row.Cells["MaSanPham"].Value.ToString())
                    {
                        row.Cells["CmbSoLuong"].Value = ((DataGridViewComboBoxCell)row.Cells["CmbSoLuong"]).Items[_gSL];
                    }

                    if (rdGiaLe.Checked == true)
                    {
                        fromFormat = true;
                        row.Cells["GiaBan"].Value = Int32.Parse(row.Cells["CmbSoLuong"].Value.ToString()) * Int32.Parse(row.Cells["GiaLe"].Value.ToString());
                    }
                    else
                    {
                        fromFormat = true;
                        row.Cells["GiaBan"].Value = Int32.Parse(row.Cells["CmbSoLuong"].Value.ToString()) * Int32.Parse(row.Cells["GiaSi"].Value.ToString());
                    }



                    soLuong  += Int32.Parse(row.Cells["CmbSoLuong"].Value.ToString());
                    tongTien += Int32.Parse(row.Cells["GiaBan"].Value.ToString());
                }

                if (txtPhiVanChuyen_Them.Text != "")
                {
                    tongTien += Int32.Parse(txtPhiVanChuyen_Them.Text.ToString());
                }

                lbSoLuong.Text  = soLuong.ToString();
                lbTongTien.Text = tongTien.ToString("n0");
                fromFormat      = false;
                _gMaSP          = "";
                _gSL            = 0;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }