public void AddDummySiteData() { DataTable siteDataTable = new DataTable("DummyTable"); siteDataTable.Columns.Add("Site Name"); DataRow newRow = siteDataTable.NewRow(); siteDataTable.Rows.Add(newRow); DayDetailsGridView.DataSource = siteDataTable; DayDetailsGridView.DataBind(); }
public void FillSiteDataGridView(DataSet siteDataSet, DateTime dateChoosen, string clickType) { if (clickType == "DayClick") { try { if (siteDataSet.Tables[0].Rows.Count == 0) { AddDummySiteData(); int columnCount = DayDetailsGridView.Rows[0].Cells.Count; DayDetailsGridView.Rows[0].Cells.Clear(); DayDetailsGridView.Rows[0].Cells.Add(new TableCell()); DayDetailsGridView.Rows[0].Cells[0].ColumnSpan = columnCount; DayDetailsGridView.Rows[0].Cells[0].Text = "No sites receive a delivery this day"; } else { m_SQL = "SELECT DISTINCT SiteID, SiteName, MealCount, DeliveryTypeName, ServingDate, MealTypeName, GroupCancellationID FROM vwDelivery WHERE CONVERT(varchar(50),deliverydate,101) = '" + dateChoosen.ToString("MM/dd/yyyy") + "' ORDER BY SiteName"; deliveriesDataSet = GCFDGlobals.m_GCFDPlannerDatabaseLibrary.dbSelectDataSet(m_SQL); DataSet deliverySite = new DataSet(); DataTable deliverySiteTable = deliverySite.Tables.Add(); deliverySiteTable.Columns.Add("SiteID", typeof(int)); deliverySiteTable.Columns.Add("Site Name", typeof(string)); deliverySiteTable.Columns.Add("Delivery Type", typeof(string)); deliverySiteTable.Columns.Add("Group Cancellation?", typeof(string)); deliverySiteTable.Columns.Add("Meal Type", typeof(string)); deliverySiteTable.Columns.Add("Meal Count", typeof(int)); deliverySiteTable.Columns.Add("Serving Day", typeof(string)); string servingDay; string idField; foreach (DataRow deliverySiteData in deliveriesDataSet.Tables[0].Rows) { idField = GCFDGlobals.dbGetValue(deliverySiteData, "SiteID"); m_MealCount = GCFDGlobals.dbGetValue(deliverySiteData, "MealCount"); servingDay = Convert.ToDateTime(GCFDGlobals.dbGetValue(deliverySiteData, "ServingDate")).DayOfWeek.ToString(); string deliveryType = GCFDGlobals.dbGetValue(deliverySiteData, "DeliveryTypeName"); string mealType = GCFDGlobals.dbGetValue(deliverySiteData, "MealTypeName"); string groupCancellation = GCFDGlobals.dbGetValue(deliverySiteData, "GroupCancellationID"); switch (deliveryType) { case "Cancelled": m_MealCount = "0"; break; case "Rescheduled": deliveryType = "Extra"; break; } if (deliveryType == "Extra" || deliveryType == "Cancelled") { if (!String.IsNullOrEmpty(groupCancellation)) { groupCancellation = "Yes"; } else { groupCancellation = "No"; } } else { groupCancellation = "N/A"; } deliverySiteTable.Rows.Add(idField, GCFDGlobals.dbGetValue(deliverySiteData, "SiteName"), deliveryType, groupCancellation, mealType, m_MealCount, servingDay); } DayDetailsGridView.DataMember = deliverySite.Tables[0].TableName; DayDetailsGridView.DataSource = deliverySite; DayDetailsGridView.DataBind(); } } catch (Exception ex) { MessageBox.Show("Error retrieving site information - " + ex.Message); } } else { try { if (siteDataSet.Tables[0].Rows.Count == 0) { AddDummySiteData(); int columnCount = DayDetailsGridView.Rows[0].Cells.Count; DayDetailsGridView.Rows[0].Cells.Clear(); DayDetailsGridView.Rows[0].Cells.Add(new TableCell()); DayDetailsGridView.Rows[0].Cells[0].ColumnSpan = columnCount; DayDetailsGridView.Rows[0].Cells[0].Text = "No sites receive a delivery this day"; } else { DataSet deliverySite = new DataSet(); DataTable deliverySiteTable = deliverySite.Tables.Add(); //commented out due to not using group cancellation functionality deliverySiteTable.Columns.Add("DeliveryID", typeof(int)); deliverySiteTable.Columns.Add("Site Name", typeof(string)); deliverySiteTable.Columns.Add("Delivery Type", typeof(string)); deliverySiteTable.Columns.Add("Group Cancellation?", typeof(string)); deliverySiteTable.Columns.Add("Meal Type", typeof(string)); deliverySiteTable.Columns.Add("Meal Count", typeof(string)); deliverySiteTable.Columns.Add("Serving Day", typeof(string)); foreach (DataRow deliverySiteData in siteDataSet.Tables[0].Rows) { string deliveryType = GCFDGlobals.dbGetValue(deliverySiteData, "DeliveryTypeName"); m_MealCount = GCFDGlobals.dbGetValue(deliverySiteData, "MealCount"); string servingDay = Convert.ToDateTime(GCFDGlobals.dbGetValue(deliverySiteData, "ServingDate")).DayOfWeek.ToString(); string groupCancellation = GCFDGlobals.dbGetValue(deliverySiteData, "GroupCancellationID"); switch (deliveryType) { case "Cancelled": m_MealCount = "0"; break; case "Rescheduled": deliveryType = "Extra"; break; } if (deliveryType == "Extra" || deliveryType == "Cancelled") { if (!String.IsNullOrEmpty(groupCancellation)) { groupCancellation = "Yes"; } else { groupCancellation = "No"; } } else { groupCancellation = "N/A"; } //commented out due to not using group cancellation functionality deliverySiteTable.Rows.Add(GCFDGlobals.dbGetValue(deliverySiteData, "DeliveryID"), GCFDGlobals.dbGetValue(deliverySiteData, "SiteName"), deliveryType, groupCancellation, GCFDGlobals.dbGetValue(deliverySiteData, "MealTypeName"), m_MealCount, Convert.ToDateTime(GCFDGlobals.dbGetValue(deliverySiteData, "ServingDate")).DayOfWeek.ToString()); //deliverySiteTable.Rows.Add(GCFDGlobals.dbGetValue(deliverySiteData, "SiteName"), deliveryType, GCFDGlobals.dbGetValue(deliverySiteData, "MealTypeName"), // m_MealCount, servingDay); } DayDetailsGridView.DataMember = deliverySite.Tables[0].TableName; DayDetailsGridView.DataSource = deliverySite; DayDetailsGridView.DataBind(); } } catch (Exception ex) { MessageBox.Show("Error retrieving site information - " + ex.Message); } } }