public static ArrayList GetList(int id, DateTime date1, DateTime date2) { string sql = "SELECT s.[Id], s.[Date], p.[Name] AS ProductName, u.FIO AS 'UserName', d.[Name] AS DimensionName, s.Quantity, s.[Time], pg.[Name] AS ProductGroupName, p.Price AS Cost, s.IsDeleted, s.DeleteDate, s.DeleteReason "; sql += " FROM Sales AS s INNER JOIN Products AS p ON s.ProductId = p.[Id] "; sql += " INNER JOIN Users AS u ON u.[Id] = s.UserId INNER JOIN ProductGroup AS pg ON pg.[Id] = p.GroupId"; sql += " INNER JOIN Dimensions AS d ON d.[Id] = p.DimensionId"; sql += " WHERE s.[Date] BETWEEN '" + date1.ToString("yyyyMMdd") + "' AND '" + date2.ToString("yyyyMMdd") + "'"; sql += " ORDER BY s.[Date]"; DataTable dt = ZFort.DB.Execute.ExecuteString_DataTable(sql); ArrayList al = new ArrayList(); foreach (DataRow dr in dt.Rows) { DBLayer.Sales.Sales_WideDetails det = new DBLayer.Sales.Sales_WideDetails(); if (!dr.IsNull("Id")) { det.Id = Convert.ToInt32(dr["Id"]); } if (!dr.IsNull("Date")) { det.Date = Convert.ToDateTime(dr["Date"]); } if (!dr.IsNull("Quantity")) { det.Quantity = Convert.ToInt32(dr["Quantity"]); } det.DimensionName = dr["DimensionName"].ToString(); det.ProductGroupName = dr["ProductGroupName"].ToString(); det.Time = dr["Time"].ToString(); det.UserName = dr["UserName"].ToString(); det.ProductName = dr["ProductName"].ToString(); det.Cost = Convert.ToDouble(dr["Cost"]); if (!dr.IsNull("IsDeleted")) { det.IsDeleted = Convert.ToBoolean(dr["IsDeleted"]); } if (!dr.IsNull("DeleteDate")) { det.DeleteDate = Convert.ToDateTime(dr["DeleteDate"]); } det.DeleteReason = dr["DeleteReason"].ToString(); al.Add(det); } return(al); }
private void LoadData() { ArrayList al = DBLayer.Sales.GetList(0, Date1, Date2); DataTable dt = new DataTable(); dt.Columns.Add("ProductName"); dt.Columns.Add("GroupName"); dt.Columns.Add("DimensionName"); dt.Columns.Add("Cost", typeof(double)); dt.Columns.Add("Quantity", typeof(double)); dt.Columns.Add("User"); dt.Columns.Add("Date", typeof(DateTime)); dt.Columns.Add("Time"); dt.Columns.Add("Summ", typeof(double)); dt.Columns.Add("IsDeleted"); dt.Columns.Add("DeleteDate", typeof(DateTime)); dt.Columns.Add("DeleteReason"); dt.Columns.Add("Id", typeof(int)); int total = 0; double totalSumm = 0; for (int i = 0; i < al.Count; i++) { DBLayer.Sales.Sales_WideDetails det = (DBLayer.Sales.Sales_WideDetails)al[i]; DataRow dr = dt.Rows.Add(); if (!det.IsDeleted) { total++; totalSumm += (det.Cost * det.Quantity); } dr["Id"] = det.Id; dr["ProductName"] = det.ProductName; dr["GroupName"] = det.ProductGroupName; dr["DimensionName"] = det.DimensionName; dr["Cost"] = det.Cost; dr["User"] = det.UserName; dr["Date"] = det.Date; dr["Time"] = det.Time; dr["Quantity"] = det.Quantity; dr["Summ"] = (det.Cost * det.Quantity); if (det.IsDeleted) { dr["IsDeleted"] = "Удален"; } if (det.DeleteDate != DateTime.MinValue) { dr["DeleteDate"] = det.DeleteDate; } dr["DeleteReason"] = det.DeleteReason; } grSales.DataSource = dt; slblTotal.Text = total.ToString(); slblTotalMoney.Text = totalSumm.ToString(); advBandedGridView1.BestFitColumns(); }