Esempio n. 1
0
        public static DataTable LayHangHoaLookupEdit()
        {
            try
            {
                HangHoa   hh            = new HangHoa();
                DonViTinh dv            = new DonViTinh();
                Kho       k             = new Kho();
                DataTable dataTableHH   = hh.LoadHangHoa();
                DataTable dataTableHHLK = hh.LoadHHLookupEdit();
                DataTable dataTableNH   = hh.LoadNhomHang();


                var results = from table1 in dataTableHHLK.AsEnumerable()
                              join table2 in dataTableHH.AsEnumerable() on(string) table1["Product_ID"] equals(string) table2["Product_ID"]
                              join table3 in dataTableNH.AsEnumerable() on(string) table2["Product_Group_ID"] equals(string) table3["ProductGroup_ID"]
                              select new
                {
                    Product_ID       = table1["Product_ID"].ToString(),
                    Product_Name     = table1["Product_Name"].ToString(),
                    Unit             = table2["Unit"].ToString(),
                    Quantity         = float.Parse(table1["Quantity"].ToString()),
                    Stock_Name       = table1["Stock_Name"].ToString(),
                    Product_Group_ID = table3["ProductGroup_Name"].ToString(),
                    Active           = bool.Parse(table2["Active"].ToString())
                };

                results = results.Select(row => row).Distinct();
                DataTable rs = new DataTable();
                rs.Columns.Add("Product_ID");
                rs.Columns.Add("Product_Name");
                rs.Columns.Add("Quantity", typeof(int));
                rs.Columns.Add("Stock_Name");
                rs.Columns.Add("Unit");
                rs.Columns.Add("Product_Group_ID");
                rs.Columns.Add("Active", typeof(bool));

                foreach (var item in results)
                {
                    rs.Rows.Add(item.Product_ID, item.Product_Name, item.Quantity, item.Stock_Name, item.Unit, item.Product_Group_ID, item.Active);
                }
                return(rs);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public static DataTable LayHangHoa()
        {
            try
            {
                HangHoa   hh           = new HangHoa();
                DonViTinh dv           = new DonViTinh();
                Kho       k            = new Kho();
                DataTable dataTableHH  = hh.LoadHangHoa();
                DataTable dataTableDV  = dv.LoadDVTDonGian();
                DataTable dataTableKho = k.LoadKhoHang();

                var results = from table1 in dataTableHH.AsEnumerable()
                              join table2 in dataTableDV.AsEnumerable() on(string) table1["Unit"] equals(string) table2["UNIT_ID"]
                              join table3 in dataTableKho.AsEnumerable() on(string) table1["Provider_ID"] equals(string) table3["Stock_ID"]
                              select new
                {
                    Product_ID        = table1["Product_ID"].ToString(),
                    Product_Name      = table1["Product_Name"].ToString(),
                    ProductGroup_Name = table1["ProductGroup_Name"].ToString(),
                    Unit            = table2["UNIT_Name"].ToString(),
                    Org_Price       = float.Parse(table1["Org_Price"].ToString()),
                    Sale_Price      = float.Parse(table1["Sale_Price"].ToString()),
                    Retail_Price    = float.Parse(table1["Retail_Price"].ToString()),
                    LimitOrders     = float.Parse(table1["LimitOrders"].ToString()),
                    Product_Type_ID = table1["Product_Type_ID"].ToString(),
                    Stock_ID        = table3["Stock_Name"].ToString(),
                    Active          = bool.Parse(table1["Active"].ToString())
                };

                DataTable rs = new DataTable();
                rs.Columns.Add("Product_ID");
                rs.Columns.Add("Product_Name");
                rs.Columns.Add("ProductGroup_Name");
                rs.Columns.Add("Unit");
                rs.Columns.Add("Org_Price");
                rs.Columns.Add("Sale_Price");
                rs.Columns.Add("Retail_Price");
                rs.Columns.Add("LimitOrders");
                rs.Columns.Add("Product_Type_ID");
                rs.Columns.Add("Stock_Name", typeof(string));
                rs.Columns.Add("Active", typeof(bool));

                foreach (var item in results)
                {
                    rs.Rows.Add(item.Product_ID, item.Product_Name, item.ProductGroup_Name, item.Unit, item.Org_Price,
                                item.Sale_Price, item.Retail_Price, item.LimitOrders, item.Product_Type_ID, item.Stock_ID, item.Active);
                }

                foreach (DataRow row in rs.Rows)
                {
                    if (float.Parse(row["Product_Type_ID"].ToString()) == 0)
                    {
                        row.SetField("Product_Type_ID", "Hàng hóa");
                    }
                }

                return(rs);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }