Esempio n. 1
0
        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);
            }
        }