/// <summary> /// 弹出窗口加载时,读取数据表 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TimeTableWindow_Loaded(object sender, RoutedEventArgs e) { int temp_ttw_cboxStation_SelectedIndex = ttw_cboxStation.SelectedIndex; MainWindow mw = Application.Current.Windows[0] as MainWindow; try { if (mw.cboxCity.SelectedIndex != -1) { if (sqlHelper.CheckDataBase(BCstatsHelper.dbFileName) && sqlHelper.CheckDataTable(BCstatsHelper.connectionString, BCstatsHelper.tableName)) { DataTable dt = new DataTable(); SQLiteDataReader reader = sqlHelper.GetDataBy(BCstatsHelper.tableName, BCstatsHelper.STR_STATION, mw.cboxStation.Text); if (ttw_cboxStation.SelectedIndex != -1) { reader = sqlHelper.GetDataBy(BCstatsHelper.tableName, BCstatsHelper.STR_STATION, ttw_cboxStation.Text); } dt.Load(reader); // 将表对象作为DataGrid的数据源 TimeTableWindow_dataGrid1.ItemsSource = dt.DefaultView; // 数据排序:根据台站名称 (TimeTableWindow_dataGrid1.ItemsSource as DataView).Sort = BCstatsHelper.STR_CATEGORY; // 禁止用户排序 TimeTableWindow_dataGrid1.CanUserSortColumns = false; // 阻止最后一行的空行 TimeTableWindow_dataGrid1.CanUserAddRows = false; // 读取city字段 getComboBoxBinding(ttw_cboxCity, sqlHelper, BCstatsHelper.connectionString, BCstatsHelper.STR_CITY, null, null, "TimeTableWindow_Loaded"); // 和主窗口的地点下拉菜单同步 ttw_cboxCity.SelectedIndex = mw.cboxCity.SelectedIndex; // 根据地点,读取station字段 getComboBoxBinding(ttw_cboxStation, sqlHelper, BCstatsHelper.connectionString, BCstatsHelper.STR_STATION, BCstatsHelper.STR_CITY, ttw_cboxCity.Text, "TimeTableWindow_Loaded"); if (mw.cboxCity.SelectedIndex != -1 && mw.cboxStation.SelectedIndex != -1) { ttw_cboxStation.SelectedIndex = mw.cboxStation.SelectedIndex; } if (temp_ttw_cboxStation_SelectedIndex != -1) { ttw_cboxStation.SelectedIndex = temp_ttw_cboxStation_SelectedIndex; } ttWindow.Title = ttw_cboxCity.Text + " " + ttw_cboxStation.Text + " " + "播出时间表设置"; } } else { MessageBox.Show("请先选择地点"); //this.Close(); } } catch (Exception ex) { MessageBox.Show("数据库读取错误:" + ex.ToString()); } }
/// <summary> /// 获取台站当月的各种播出时长数据 /// </summary> public void GetStationBCStats(CheckBox chkBoxLastTuesday) { // 获取主窗口的控件状态信息 MainWindow mw = Application.Current.Windows[0] as MainWindow; DataTable dt = new DataTable(); try { if (mw.cboxCity.SelectedIndex != -1 && mw.cboxStation.SelectedIndex != -1 && sqliteHelper.CheckDataBase(BCstatsHelper.dbFileName) && sqliteHelper.CheckDataTable(BCstatsHelper.connectionString, BCstatsHelper.tableName)) { #region 读写控件状态 int year = Convert.ToInt32(mw.scbYear.Value); int month = Convert.ToInt32(mw.scbMonth.Value); this.Title = mw.cboxStation.Text + " " + mw.scbYear.Value.ToString() + "年" + mw.scbMonth.Value.ToString() + "月" + "播出统计"; int nostop2 = Convert.ToInt16(mw.scbNoStop2.Value); int nostop3 = Convert.ToInt16(mw.scbNoStop3.Value); string city = mw.cboxCity.Text; string station = mw.cboxStation.Text; #endregion #region 读取数据库,生成 DataTable 到 DataGrid // 台站的所有节目数量,各种类型的节目数量 int total = sqliteHelper.GetDataCounBy(BCstatsHelper.connectionString, BCstatsHelper.tableName, BCstatsHelper.STR_STATION, station); string tableName = BCstatsHelper.tableName; // 列表:节目类型 List <string> categoryList = sqliteHelper.GetColunmValues(BCstatsHelper.connectionString, tableName, BCstatsHelper.STR_CATEGORY, BCstatsHelper.STR_STATION, station); // 列表:节目名称 List <string> nameList = sqliteHelper.GetColunmValues(BCstatsHelper.connectionString, tableName, BCstatsHelper.STR_NAME, BCstatsHelper.STR_STATION, station); // 列表:节目频率 List <string> frequencyList = sqliteHelper.GetColunmValues(BCstatsHelper.connectionString, tableName, BCstatsHelper.STR_FREQUENCY, BCstatsHelper.STR_STATION, station); // DataTable 定义列 dt.Columns.Add(BCstatsHelper.STR_STATION); dt.Columns.Add(BCstatsHelper.STR_CATEGORY); dt.Columns.Add(BCstatsHelper.STR_NAME); dt.Columns.Add(BCstatsHelper.STR_FREQUENCY); dt.Columns.Add(BCstatsHelper.STR_HOURS); //MessageBox.Show("1"); // DataTable 填充数据 for (int i = 0; i < total; i++) { DataRow dr = dt.NewRow(); dr[BCstatsHelper.STR_CATEGORY] = categoryList[i]; dr[BCstatsHelper.STR_NAME] = nameList[i]; dr[BCstatsHelper.STR_FREQUENCY] = frequencyList[i]; // 各节目的播出时长 if (chkBoxLastTuesday != null) { dr[BCstatsHelper.STR_HOURS] = GetFrequencyHours(sqliteHelper, year, month, this.chkBoxLastTuesday, nostop2, nostop3, city, station, frequencyList[i]); } else { dr[BCstatsHelper.STR_HOURS] = GetFrequencyHours(sqliteHelper, year, month, null, nostop2, nostop3, city, station, frequencyList[i]); } dt.Rows.Add(dr); } //MessageBox.Show("2"); // 绑定数据 StationStats_DataGrid.ItemsSource = dt.DefaultView; // 数据排序:根据节目类型 (StationStats_DataGrid.ItemsSource as DataView).Sort = BCstatsHelper.STR_CATEGORY; StationStats_DataGrid.CanUserDeleteRows = false; StationStats_DataGrid.CanUserAddRows = false; StationStats_DataGrid.CanUserSortColumns = true; #endregion #region 各个类型的播出时长之和 double swHours = GetHoursByCategory(dt, BCstatsHelper.STR_SW); double mwHours = GetHoursByCategory(dt, BCstatsHelper.STR_MW); double expHours = GetHoursByCategory(dt, BCstatsHelper.STR_EXP); double fmHours = GetHoursByCategory(dt, BCstatsHelper.STR_FM); double tvHours = GetHoursByCategory(dt, BCstatsHelper.STR_TV); double sumHours = swHours + mwHours + fmHours + tvHours; int swQuantity = GetQuantityByCategory(dt, BCstatsHelper.STR_SW); int mwQuantity = GetQuantityByCategory(dt, BCstatsHelper.STR_MW); int expQuantity = GetQuantityByCategory(dt, BCstatsHelper.STR_EXP); int fmQuantity = GetQuantityByCategory(dt, BCstatsHelper.STR_FM); int tvQuantity = GetQuantityByCategory(dt, BCstatsHelper.STR_TV); lblSW.Content = BCstatsHelper.STR_SW_CN + "(" + swQuantity + ")"; lblMW.Content = BCstatsHelper.STR_MW_CN + "(" + mwQuantity + ")"; lblEXP.Content = BCstatsHelper.STR_EXP_CN + "(" + expQuantity + ")"; lblFM.Content = BCstatsHelper.STR_FM_CN + "(" + fmQuantity + ")"; lblDTV.Content = BCstatsHelper.STR_TV_CN + "(" + tvQuantity + ")"; lblAllHours.Content = BCstatsHelper.STR_TOTAL_CN + "(" + total + ")"; tbxSW.Text = swHours.ToString(); tbxMW.Text = mwHours.ToString(); tbxEXP.Text = expHours.ToString(); tbxFM.Text = fmHours.ToString(); tbxDTV.Text = tvHours.ToString(); tbxAllHours.Text = sumHours.ToString(); #endregion } } catch (Exception ex) { ; //MessageBox.Show(ex.ToString()); } }