public Entities.BCHDBanBuon[] Select(Entities.BCHDBanBuon bchdbl)
        {
            //Insert Category into ArrayList
            ArrayList arr = new ArrayList();
            Entities.ChiTietHDBanHang chitiet = new Entities.ChiTietHDBanHang();
            chitiet.MaHDBanHang = bchdbl.MaHDBanHang;
            Entities.ChiTietHDBanHang[] chitiethdbanhang = new BizLogic.ChiTietHDBanHang().Select(chitiet);

            foreach (Entities.ChiTietHDBanHang ite in chitiethdbanhang)
            {
                Entities.BCHDBanBuon bcdttg1 = new Entities.BCHDBanBuon();
                bcdttg1.MaHDBanHang = ite.MaHDBanHang;
                bcdttg1.TenHangHoa = ite.TenHangHoa;
                bcdttg1.SoLuong = ite.SoLuong;
                bcdttg1.GiaBanBuon = int.Parse(ite.DonGia);
                bcdttg1.ChietKhau = ite.PhanTramChietKhau.ToString();
                bcdttg1.Thue = ite.Thue;
                bcdttg1.TongTienThanhToan = bcdttg1.SoLuong * bcdttg1.GiaBanBuon;
                arr.Add(bcdttg1);
            }
            int n = arr.Count;
            if (n == 0) return null;

            Entities.BCHDBanBuon[] arrC = new Entities.BCHDBanBuon[n];
            for (int i = 0; i < n; i++)
            {
                arrC[i] = (Entities.BCHDBanBuon)arr[i];
            }

            return arrC;
        }
        public Entities.BCHDBanLe[] Select(Entities.BCHDBanLe bchdbl)
        {
            //Insert Category into ArrayList
            ArrayList arr = new ArrayList();

            Entities.ChiTietHDBanHang chitiet = new Entities.ChiTietHDBanHang();
            chitiet.MaHDBanHang = bchdbl.MaHDBanHang;
            Entities.ChiTietHDBanHang[] chitiethdbanhang = new BizLogic.ChiTietHDBanHang().Select(chitiet);
            foreach (Entities.ChiTietHDBanHang ite in chitiethdbanhang)
            {
                Entities.BCHDBanLe bcdttg1 = new Entities.BCHDBanLe();
                bcdttg1.MaHDBanHang       = ite.MaHDBanHang;
                bcdttg1.TenHangHoa        = ite.TenHangHoa;
                bcdttg1.SoLuong           = ite.SoLuong;
                bcdttg1.GiaBanLe          = double.Parse(ite.DonGia);
                bcdttg1.Thue              = double.Parse(ite.Thue);
                bcdttg1.ChietKhau         = double.Parse(ite.PhanTramChietKhau.ToString());
                bcdttg1.TongTienThanhToan = bcdttg1.SoLuong * bcdttg1.GiaBanLe;
                arr.Add(bcdttg1);
            }
            int n = arr.Count;

            if (n == 0)
            {
                return(null);
            }

            Entities.BCHDBanLe[] arrC = new Entities.BCHDBanLe[n];
            for (int i = 0; i < n; i++)
            {
                arrC[i] = (Entities.BCHDBanLe)arr[i];
            }

            return(arrC);
        }
Exemple #3
0
        public Entities.ChiTietHDBanHang[] Select(Entities.ChiTietHDBanHang hdbh1)
        {
            Sql    = new Constants.Sql();
            cthdbh = new Constants.ChiTietHDBanHang();
            string        sql  = Sql.SelectChiTietHDBanHang;
            Connection    conn = new Connection();
            SqlConnection cn   = conn.openConnection();
            SqlCommand    cmd  = new SqlCommand(sql, cn);

            cmd.Parameters.Add(cthdbh.MaHDBanHang, SqlDbType.VarChar).Value = hdbh1.MaHDBanHang;
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            //Insert Category into ArrayList
            ArrayList arr = new ArrayList();

            while (dr.Read())
            {
                Entities.ChiTietHDBanHang cthdbh1 = new Entities.ChiTietHDBanHang();
                cthdbh1.MaHDBanHang       = dr[cthdbh.MaHDBanHang].ToString();
                cthdbh1.MaHangHoa         = dr[cthdbh.MaHangHoa].ToString();
                cthdbh1.TenHangHoa        = dr[cthdbh.TenHangHoa].ToString();
                cthdbh1.SoLuong           = int.Parse(dr[cthdbh.SoLuong].ToString());
                cthdbh1.DonGia            = (dr[cthdbh.DonGia].ToString());
                cthdbh1.Thue              = (dr[cthdbh.Thue].ToString());
                cthdbh1.PhanTramChietKhau = float.Parse(dr[cthdbh.PhanTramChietKhau].ToString());
                cthdbh1.GhiChu            = dr[cthdbh.GhiChu].ToString();
                cthdbh1.Deleted           = (Boolean)dr[cthdbh.Deleted];
                arr.Add(cthdbh1);
            }
            int n = arr.Count;

            if (n == 0)
            {
                return(null);
            }

            Entities.ChiTietHDBanHang[] arrC = new Entities.ChiTietHDBanHang[n];
            for (int i = 0; i < n; i++)
            {
                arrC[i] = (Entities.ChiTietHDBanHang)arr[i];
            }

            //Giai phong bo nho
            arr = null;
            cmd.Connection.Dispose();
            cn.Close();
            conn.closeConnection();
            cn   = null;
            conn = null;
            return(arrC);
        }
Exemple #4
0
        public bool InsertUpdate(Entities.ChiTietHDBanHang hdbh1)
        {
            try
            {
                bool kt = false;
                cthdbh = new Constants.ChiTietHDBanHang();
                Sql    = new Constants.Sql();
                string        sql  = Sql.InsertUpdateChiTietHDBanHangMang;
                Connection    conn = new Connection();
                SqlConnection cn   = conn.openConnection();
                SqlCommand    cmd  = new SqlCommand(sql, cn);
                cmd.Parameters.Add(cthdbh.HanhDong, SqlDbType.NVarChar, 20).Value    = hdbh1.HanhDong;
                cmd.Parameters.Add(cthdbh.MaHDBanHang, SqlDbType.VarChar).Value      = hdbh1.MaHDBanHang;
                cmd.Parameters.Add(cthdbh.MaHangHoa, SqlDbType.VarChar, 50).Value    = hdbh1.MaHangHoa;
                cmd.Parameters.Add(cthdbh.TenHangHoa, SqlDbType.NVarChar, 200).Value = hdbh1.TenHangHoa;
                cmd.Parameters.Add(cthdbh.SoLuong, SqlDbType.Int).Value             = hdbh1.SoLuong;
                cmd.Parameters.Add(cthdbh.DonGia, SqlDbType.Float).Value            = hdbh1.DonGia;
                cmd.Parameters.Add(cthdbh.Thue, SqlDbType.Float).Value              = hdbh1.Thue;
                cmd.Parameters.Add(cthdbh.PhanTramChietKhau, SqlDbType.Float).Value = hdbh1.PhanTramChietKhau;
                cmd.Parameters.Add(cthdbh.GhiChu, SqlDbType.NVarChar, 100).Value    = hdbh1.GhiChu;
                cmd.Parameters.Add(cthdbh.Deleted, SqlDbType.Bit).Value             = hdbh1.Deleted;

                int i = cmd.ExecuteNonQuery();
                if (i == 1)
                {
                    kt = true;
                }
                else
                {
                    kt = false;
                }
                cmd.Connection.Dispose();
                cn.Close();
                conn.closeConnection();
                cn   = null;
                conn = null;
                return(kt);
            }
            catch (Exception ex)
            {
                string s = ex.Message;
                return(false);
            }
        }
Exemple #5
0
        public bool Delete(Entities.ChiTietHDBanHang hdbh1)
        {
            try
            {
                cthdbh = new Constants.ChiTietHDBanHang();
                Sql    = new Constants.Sql();
                string        sql  = Sql.DeleteChiTietBanHang;
                Connection    conn = new Connection();
                SqlConnection cn   = conn.openConnection();
                SqlCommand    cmd  = new SqlCommand(sql, cn);
                cmd.Parameters.Add(cthdbh.HanhDong, SqlDbType.NVarChar, 20).Value = hdbh1.HanhDong;
                cmd.Parameters.Add(cthdbh.MaHDBanHang, SqlDbType.Int).Value       = hdbh1.MaHDBanHang;
                cmd.Parameters.Add(cthdbh.MaHangHoa, SqlDbType.VarChar, 50).Value = hdbh1.MaHangHoa;

                int  i  = cmd.ExecuteNonQuery();
                bool kt = false;
                if (i == 1)
                {
                    kt = true;
                }
                else
                {
                    kt = false;
                }
                cmd.Connection.Dispose();
                cn.Close();
                conn.closeConnection();
                cn   = null;
                conn = null;
                return(kt);
            }
            catch (Exception ex)
            {
                string s = ex.Message;
                return(false);
            }
        }
 private void LayDuLieuChiTietHoaDonBanHang()
 {
     //lấy dữ liệu chi tiết hóa đơn bán hàng
     ChiTietHDBanHang inputCtHdbbh = new ChiTietHDBanHang { HanhDong = "Select" };
     ChiTietHDBanHang[] outputCtHdbbh;
     bool kqCtHdbh = Utils.GetDataFromServer("ChiTietHDBanHang", inputCtHdbbh, out outputCtHdbbh);
     if (kqCtHdbh) _chiTietHdBanHangs.AddRange(outputCtHdbbh);
 }
        public void GiaVonBanHang(ChiTietHDBanHang[] ct)
        {
            try
            {
                List<GiaVonBanHang> gvbhArr = new List<GiaVonBanHang>();
                GoiHang[] goiHang = _goihang;
                GiaVon[] gv = GiaVon();
                bool isHangHoa = false;

                foreach (ChiTietHDBanHang bh in ct)
                {
                    GiaVonBanHang gvbh = new GiaVonBanHang();
                    ChiTietHDBanHang bh1 = bh;
                    foreach (GiaVon item in gv.Where(item => item.MaHangHoa.Equals(bh1.MaHangHoa)))
                    {
                        gvbh.HanhDong = "Insert";
                        gvbh.MaHangHoa = bh.MaHangHoa;
                        gvbh.MaHoaDon = bh.MaHDBanHang;
                        gvbh.GiaVon = item.Gia;
                        gvbhArr.Add(gvbh);
                        isHangHoa = true;
                        break;
                    }
                    // neu ko phai la hang hoa thi la gia von trong goi hang
                    if (isHangHoa) continue;
                    gvbh = GetGvGoiHang(bh.MaHDBanHang, bh.MaHangHoa, goiHang);

                    if (gvbh != null)
                        gvbhArr.Add(gvbh);
                }

                cl = new Server_Client.Client();
                Client1 = cl.Connect(Luu.IP, Luu.Ports);
                foreach (GiaVonBanHang item in gvbhArr.ToArray())
                {
                    Clientstrem = cl.SerializeObj(Client1, "GiaVonBanHang", item);
                }
                // đổ mảng đối tượng vào datagripview
                bool kt = false;
                kt = (bool)cl.DeserializeHepper(Clientstrem, kt);
            }
            catch (Exception)
            {

            }
        }
 /// <summary>
 /// kiểm tra dtgv trước khi update
 /// </summary>
 /// <param name="dgv"></param>
 public Entities.ChiTietHDBanHang[] CheckDataGridInsert(DataGridView dgv)
 {
     bool kkt = false;
     try
     {
         if (dgv.RowCount != 0)
         {
             Entities.ChiTietHDBanHang[] cthdbh = new Entities.ChiTietHDBanHang[dgv.RowCount];
             for (int j = 0; j < cthdbh.Length; j++)
             {
                 cthdbh[j] = new Entities.ChiTietHDBanHang("InsertUpdate", txtSochungtu.Text, dgv[1, j].Value.ToString(), int.Parse(dgv[4, j].Value.ToString()), int.Parse(dgv[5, j].Value.ToString()), "", false);
                 cthdbh[j].Thue = dgv["ThueGTGT", j].Value.ToString();
                 cthdbh[j].DonGia = dgv["DonGia", j].Value.ToString();
                 cthdbh[j].TenHangHoa = dgv["TenHang", j].Value.ToString();
             }
             return cthdbh;
         }
         return new Entities.ChiTietHDBanHang[0];
     }
     catch
     {
         return new Entities.ChiTietHDBanHang[0];
     }
 }
        /// <summary>
        /// select dữ liệu
        /// </summary>
        public void SelectData()
        {
            try
            {
                cl = new Server_Client.Client();

                // gán TCPclient
                this.Client1 = cl.Connect(Luu.IP, Luu.Ports);
                // khởi tạo biến truyền vào với hàm khởi tạo
                Entities.ChiTietHDBanHang pt = new Entities.ChiTietHDBanHang("Select", txtSochungtu.Text);
                // khởi tạo mảng đối tượng để hứng giá trị
                Entities.ChiTietHDBanHang[] pt1 = new Entities.ChiTietHDBanHang[1];
                Clientstrem = cl.SerializeObj(this.Client1, "ChiTietHDBanHang", pt);
                // đổ mảng đối tượng vào datagripview
                pt1 = (Entities.ChiTietHDBanHang[])cl.DeserializeHepper1(Clientstrem, pt1);
                if (pt1 == null)
                {

                    dtgvsanpham.DataSource = new Entities.HangHoaHienThi[0];
                    return;
                }

                Entities.ChiTietHDBanHang[] pt2 = new Entities.ChiTietHDBanHang[pt1.Length];
                int sotang = 0;
                for (int j = 0; j < pt1.Length; j++)
                {
                    if (pt1[j].Deleted == false)
                    {
                        if (pt1[j].MaHDBanHang == txtSochungtu.Text)
                        {
                            pt2[sotang] = pt1[j];
                            sotang++;
                        }
                    }
                }
                Entities.HangHoaHienThi[] hhht = new Entities.HangHoaHienThi[sotang];

                if (sotang != 0)
                {

                    for (int j = 0; j < sotang; j++)
                    {
                        string giasp = pt2[j].DonGia;

                        string soluongsp = pt2[j].SoLuong.ToString();
                        string thanhtien = (Convert.ToDouble(giasp) * Convert.ToDouble(soluongsp)).ToString();
                        thuegtgt = pt2[j].Thue;
                        hhht[j] = new Entities.HangHoaHienThi(pt2[j].MaHDBanHang, pt2[j].MaHangHoa.ToUpper(), pt2[j].TenHangHoa, giasp, soluongsp, pt2[j].PhanTramChietKhau.ToString(), thuegtgt, thanhtien);
                    }
                }
                else
                {
                    dtgvsanpham.DataSource = new Entities.HangHoaHienThi[0];
                    txtTienhang.Text = "0";
                    txtGTGT.Text = "0";
                    return;
                }
                dtgvsanpham.DataSource = hhht;
                //TinhToan();
                //if (txtPhantramchietkhau.Text == "")
                //    phantramchietkhau = "0";
                //else
                //    phantramchietkhau = txtPhantramchietkhau.Text;
                //txtChietkhau.Text = new Common.Utilities().FormatMoney(((Convert.ToDouble(phantramchietkhau) / 100) * Convert.ToDouble(txtTienhang.Text)));
                //txtTongtien.Text = new Common.Utilities().FormatMoney(Convert.ToDouble(tongtienthanhtoan) - Convert.ToDouble(txtChietkhau.Text) - Convert.ToDouble(txtGiamgia.Text));
                //txtkhachtra.Text = new Common.Utilities().FormatMoney(Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtgiatrithe.Text)); string khachtra = "0";
                //if (txtkhachtra.Text == "")
                //    khachtra = "0";
                //else
                //    khachtra = txtkhachtra.Text;
                //if (Convert.ToDouble(txtTongtien.Text) >= Convert.ToDouble(txtgiatrithe.Text))
                //    txtdutra.Text = new Common.Utilities().FormatMoney(Convert.ToDouble(khachtra) - Convert.ToDouble(txtTongtien.Text) + Convert.ToDouble(txtgiatrithe.Text));
                //else
                //    txtdutra.Text = txtkhachtra.Text; dtgvsanpham.Rows[0].Selected = true;

            }
            catch (Exception ex)
            {

            }
            finally
            {
                try
                {
                    fix();
                }
                catch
                {
                }

            }
        }
        /// <summary>
        /// select chi tiết hóa đơn bán hàng
        /// </summary>
        public void SelectData()
        {
            try
            {
                dtgvsanpham.RowHeadersVisible = false;
                cl = new Server_Client.Client();
                // gán TCPclient
                this.client1 = cl.Connect(Luu.IP, Luu.Ports);
                // khởi tạo biến truyền vào với hàm khởi tạo
                Entities.ChiTietHDBanHang pt = new Entities.ChiTietHDBanHang("Select", txtSochungtu.Text);
                // khởi tạo mảng đối tượng để hứng giá trị
                pt1 = new Entities.ChiTietHDBanHang[1];
                clientstrem = cl.SerializeObj(this.client1, "ChiTietHDBanHang", pt);
                // đổ mảng đối tượng vào datagripview
                pt1 = (Entities.ChiTietHDBanHang[])cl.DeserializeHepper1(clientstrem, pt1);
                if (pt1 == null)
                {
                    dtgvsanpham.DataSource = new Entities.HangHoaHienThi[0];
                    return;
                }
                Entities.ChiTietHDBanHang[] pt2 = new Entities.ChiTietHDBanHang[pt1.Length];
                int sotang = 0;
                for (int j = 0; j < pt1.Length; j++)
                {
                    if (pt1[j].Deleted == false)
                    {
                        if (pt1[j].MaHDBanHang == txtSochungtu.Text)
                        {
                            pt2[sotang] = pt1[j];
                            sotang++;
                        }
                    }
                }
                Entities.HangHoaHienThi[] hhht = new Entities.HangHoaHienThi[sotang];
                if (sotang != 0)
                {

                    for (int j = 0; j < sotang; j++)
                    {
                        string giasp = pt2[j].DonGia;
                        string soluongsp = pt2[j].SoLuong.ToString();
                        string thanhtien = (Convert.ToDouble(giasp) * Convert.ToDouble(soluongsp)).ToString();
                        thuegtgt = pt2[j].Thue;
                        hhht[j] = new Entities.HangHoaHienThi(pt2[j].MaHDBanHang, pt2[j].MaHangHoa.ToUpper(), pt2[j].TenHangHoa, giasp, soluongsp, pt2[j].PhanTramChietKhau.ToString(), thuegtgt, thanhtien);
                    }
                }
                else
                {
                    dtgvsanpham.DataSource = new Entities.HangHoaHienThi[0];
                    txtkhachtra.Text = txtTienhang.Text = txtGTGT.Text = txtTongtien.Text = txtTongchietkhau.Text = txtConphaitra.Text = txtThanhtoanngay.Text = "0";
                    return;
                }
                dtgvsanpham.DataSource = hhht;
            }
            catch
            {
            }
            finally
            {
                try
                {
                    fix();
                }
                catch
                { }

            }
        }
 public Entities.ChiTietHDBanHang[] LayChiTiet_HDBanHang_TheoMaPhieu(string maHD)
 {
     int count = 0;
     for (int i = 0; i < ctHDBanHang.Length; i++)
     {
         if (ctHDBanHang[i].MaHDBanHang == maHD)
         {
             count++;
         }
     }
     Entities.ChiTietHDBanHang[] ctHDBanHang_TheoMaHD = new Entities.ChiTietHDBanHang[count];
     count = 0;
     for (int i = 0; i < ctHDBanHang.Length; i++)
     {
         if (ctHDBanHang[i].MaHDBanHang == maHD)
         {
             ctHDBanHang_TheoMaHD[count] = ctHDBanHang[i];
             count++;
         }
     }
     if (ctHDBanHang_TheoMaHD == null)
     {
         ctHDBanHang_TheoMaHD = new Entities.ChiTietHDBanHang[0];
         return ctHDBanHang_TheoMaHD;
     }
     else
     {
         return ctHDBanHang_TheoMaHD;
     }
 }
 public void LayChiTiet_HDBanHang()
 {
     cl = new Server_Client.Client();
     this.client1 = cl.Connect(Luu.IP, Luu.Ports);
     Entities.ChiTietHDBanHang ctxh = new Entities.ChiTietHDBanHang("SelectSon");
     clientstrem = cl.SerializeObj(this.client1, "ChiTietHDBanHang", ctxh);
     Entities.ChiTietHDBanHang[] ctHDBanHang1 = new Entities.ChiTietHDBanHang[0];
     ctHDBanHang1 = (Entities.ChiTietHDBanHang[])cl.DeserializeHepper1(clientstrem, ctHDBanHang1);
     if (ctHDBanHang1 == null)
     {
         ctHDBanHang = new Entities.ChiTietHDBanHang[0];
         return;
     }
     ctHDBanHang = ctHDBanHang1;
 }
        public Entities.ChiTietHDBanHang[] Select()
        {
            Sql = new Constants.Sql();
            cthdbh = new Constants.ChiTietHDBanHang();
            string sql = "Select * from ChiTietHDBanHang where Deleted = 0";
            Connection conn = new Connection();
            SqlConnection cn = conn.openConnection();
            SqlCommand cmd = new SqlCommand(sql, cn);
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            //Insert Category into ArrayList
            ArrayList arr = new ArrayList();
            while (dr.Read())
            {
                Entities.ChiTietHDBanHang cthdbh1 = new Entities.ChiTietHDBanHang();
                cthdbh1.MaHDBanHang = dr[cthdbh.MaHDBanHang].ToString();
                cthdbh1.MaHangHoa = dr[cthdbh.MaHangHoa].ToString();
                cthdbh1.TenHangHoa = dr[cthdbh.TenHangHoa].ToString();
                cthdbh1.SoLuong = int.Parse(dr[cthdbh.SoLuong].ToString());
                cthdbh1.DonGia = (dr[cthdbh.DonGia].ToString());
                cthdbh1.Thue = (dr[cthdbh.Thue].ToString());
                cthdbh1.PhanTramChietKhau = float.Parse(dr[cthdbh.PhanTramChietKhau].ToString());
                cthdbh1.GhiChu = dr[cthdbh.GhiChu].ToString();
                cthdbh1.Deleted = (Boolean)dr[cthdbh.Deleted];
                arr.Add(cthdbh1);
            }
            int n = arr.Count;
            if (n == 0) return null;

            Entities.ChiTietHDBanHang[] arrC = new Entities.ChiTietHDBanHang[n];
            for (int i = 0; i < n; i++)
            {
                arrC[i] = (Entities.ChiTietHDBanHang)arr[i];
            }

            //Giai phong bo nho
            arr = null;
            cmd.Connection.Dispose();
            cn.Close();
            conn.closeConnection();
            cn = null;
            conn = null;
            return arrC;
        }