public void Load_table() { Dictionary <string, MyColumn> MyColumns = new Dictionary <string, MyColumn>(); DataTable table = dbOperation.GetDbHelper().GetDataSet(string.Format("call p_sampling_rate_details({0})", (Application.Current.Resources["User"] as UserInfo).ID)).Tables[0]; currenttable = table; list.Clear(); for (int i = 0; i < table.Rows.Count; i++) { DeptItem info = new DeptItem(); //info.DeptId = table.Rows[i][0].ToString(); info.DeptName = table.Rows[i][1].ToString(); //info.ItemId = table.Rows[i][2].ToString(); info.ItemName = table.Rows[i][3].ToString(); info.Task = table.Rows[i][4].ToString(); list.Add(info); } //得到行和列标题 及数量 string[] DeptNames = list.Select(t => t.DeptName).Distinct().ToArray(); string[] ItemNames = list.Select(t => t.ItemName).Distinct().ToArray(); //创建DataTable DataTable tabledisplay = new DataTable(); //表中第一行第一列交叉处一般显示为第1列标题 //tabledisplay.Columns.Add(new DataColumn("序号")); //MyColumns.Add("序号", new MyColumn("序号", "序号") { BShow = true, Width = 10 }); switch (user_flag_tier) { case "0": tabledisplay.Columns.Add(new DataColumn("省名称")); MyColumns.Add("省名称", new MyColumn("省名称", "省名称") { BShow = true, Width = 20 }); break; case "1": tabledisplay.Columns.Add(new DataColumn("市(州)单位名称")); MyColumns.Add("市(州)单位名称", new MyColumn("市(州)单位名称", "市(州)单位名称") { BShow = true, Width = 20 }); break; case "2": tabledisplay.Columns.Add(new DataColumn("区县名称")); MyColumns.Add("区县名称", new MyColumn("区县名称", "区县名称") { BShow = true, Width = 20 }); break; case "3": tabledisplay.Columns.Add(new DataColumn("检测单位名称")); MyColumns.Add("检测单位名称", new MyColumn("检测单位名称", "检测单位名称") { BShow = true, Width = 20 }); break; case "4": tabledisplay.Columns.Add(new DataColumn("检测单位名称")); MyColumns.Add("检测单位名称", new MyColumn("检测单位名称", "检测单位名称") { BShow = true, Width = 20 }); break; default: break; } //表中后面每列的标题其实是列分组的关键字 for (int i = 0; i < ItemNames.Length; i++) { DataColumn column = new DataColumn(ItemNames[i]); tabledisplay.Columns.Add(column); MyColumns.Add(ItemNames[i], new MyColumn(ItemNames[i], ItemNames[i]) { BShow = true, Width = 15 }); } //为表中各行生成数据 for (int i = 0; i < DeptNames.Length; i++) { var row = tabledisplay.NewRow(); //每行第0列为行分组关键字 //row[0] = i + 1; row[0] = DeptNames[i]; //每行的其余列为行列交叉对应的汇总数据 for (int j = 0; j < ItemNames.Length; j++) { string num = list.Where(t => t.DeptName == DeptNames[i] && t.ItemName == ItemNames[j]).Select(t => t.Task).FirstOrDefault(); if (num == null || num == "") { num = '0'.ToString(); } row[ItemNames[j]] = num; } tabledisplay.Rows.Add(row); } _tableview.BShowModify = true; _tableview.MyColumns = MyColumns; _tableview.Table = tabledisplay; }
public void Load_table() { Dictionary<string, MyColumn> MyColumns = new Dictionary<string, MyColumn>(); System.Data.DataTable table = dbOperation.GetDbHelper().GetDataSet(string.Format("call p_task_details('{0}','{1}')", (System.Windows.Application.Current.Resources["User"] as UserInfo).ID, dept_type)).Tables[0]; currenttable = table; list.Clear(); for (int i = 0; i < table.Rows.Count; i++) { DeptItem info = new DeptItem(); info.DeptId = table.Rows[i][0].ToString(); info.DeptName = table.Rows[i][1].ToString(); info.ItemId = table.Rows[i][2].ToString(); info.ItemName = table.Rows[i][3].ToString(); info.Task = table.Rows[i][4].ToString(); list.Add(info); } //得到行和列标题 及数量 string[] DeptNames = list.Select(t => t.DeptName).Distinct().ToArray(); string[] ItemNames = list.Select(t => t.ItemName).Distinct().ToArray(); //创建DataTable System.Data.DataTable tabledisplay = new System.Data.DataTable(); //表中第一行第一列交叉处一般显示为第1列标题 //tabledisplay.Columns.Add(new DataColumn("序号")); //MyColumns.Add("序号", new MyColumn("序号", "序号") { BShow = true, Width = 10 }); //switch (user_flag_tier) //{ // case "0": tabledisplay.Columns.Add(new DataColumn("省名称")); // MyColumns.Add("省名称", new MyColumn("省名称", "省名称") { BShow = true, Width = 20 }); // break; // case "1": tabledisplay.Columns.Add(new DataColumn("市(州)单位名称")); // MyColumns.Add("市(州)单位名称", new MyColumn("市(州)单位名称", "市(州)单位名称") { BShow = true, Width = 20 }); // break; // case "2": tabledisplay.Columns.Add(new DataColumn("区县名称")); // MyColumns.Add("区县名称", new MyColumn("区县名称", "区县名称") { BShow = true, Width = 20 }); // break; // case "3": tabledisplay.Columns.Add(new DataColumn("检测单位名称")); // MyColumns.Add("检测单位名称", new MyColumn("检测单位名称", "检测单位名称") { BShow = true, Width = 20 }); // break; // case "4": tabledisplay.Columns.Add(new DataColumn("检测单位名称")); // MyColumns.Add("检测单位名称", new MyColumn("检测单位名称", "检测单位名称") { BShow = true, Width = 20 }); // break; // default: break; //} tabledisplay.Columns.Add(new DataColumn("部门名称")); MyColumns.Add("部门名称", new MyColumn("部门名称", "部门名称") { BShow = true, Width = 20 }); //表中后面每列的标题其实是列分组的关键字 for (int i = 0; i < ItemNames.Length; i++) { DataColumn column = new DataColumn(ItemNames[i]); tabledisplay.Columns.Add(column); MyColumns.Add(ItemNames[i], new MyColumn(ItemNames[i], ItemNames[i]) { BShow = true, Width = 15 }); } //为表中各行生成数据 for (int i = 0; i < DeptNames.Length; i++) { var row = tabledisplay.NewRow(); //每行第0列为行分组关键字 //row[0] = i + 1; row[0] = DeptNames[i]; //每行的其余列为行列交叉对应的汇总数据 for (int j = 0; j < ItemNames.Length; j++) { string num = list.Where(t => t.DeptName == DeptNames[i] && t.ItemName == ItemNames[j]).Select(t => t.Task).FirstOrDefault(); if (num == null || num == "") { num = '0'.ToString(); } row[ItemNames[j]] = num; } tabledisplay.Rows.Add(row); } if (table.Rows.Count != 0) { //表格最后添加合计行 tabledisplay.Rows.Add(tabledisplay.NewRow()[1] = "合计"); for (int j = 1; j < tabledisplay.Columns.Count; j++) { int sum = 0; for (int i = 0; i < tabledisplay.Rows.Count - 1; i++) { sum += Convert.ToInt32(tabledisplay.Rows[i][j].ToString()); } //sum_column += sum; tabledisplay.Rows[tabledisplay.Rows.Count - 1][j] = sum; } System.Data.DataTable tasktable = dbOperation.GetDbHelper().GetDataSet("select t_det_item.ItemNAME,task " + "from t_task_assign_new left JOIN t_det_item ON t_task_assign_new.iid = t_det_item.ItemID " + "where t_task_assign_new.did = " + deptid).Tables[0]; List<ItemTask> listtask = new List<ItemTask>(); listtask.Clear(); for (int i = 0; i < tasktable.Rows.Count; i++) { ItemTask task = new ItemTask(); task.ItemName = tasktable.Rows[i][0].ToString(); task.Task = tasktable.Rows[i][1].ToString(); listtask.Add(task); } if (user_flag_tier != "1") { //表格最后添加上级分配任务量 tabledisplay.Rows.Add(tabledisplay.NewRow()[1] = "上级下达任务量"); for (int j = 1; j < tabledisplay.Columns.Count; j++) { string task = listtask.Where(s => s.ItemName == tabledisplay.Columns[j].ColumnName.ToString()).Select(s => s.Task).FirstOrDefault(); if (task == null || task == "") { task = '0'.ToString(); } tabledisplay.Rows[tabledisplay.Rows.Count - 1][j] = task; } //表格最后添加未分配量 tabledisplay.Rows.Add(tabledisplay.NewRow()[1] = "未分配量"); for (int j = 1; j < tabledisplay.Columns.Count; j++) { int rwl = Convert.ToInt32(tabledisplay.Rows[tabledisplay.Rows.Count - 2][j].ToString()); int yfp = Convert.ToInt32(tabledisplay.Rows[tabledisplay.Rows.Count - 3][j].ToString()); int wfp = rwl - yfp; tabledisplay.Rows[tabledisplay.Rows.Count - 1][j] = wfp; } } } exporttable = tabledisplay; _tableview.BShowModify = true; _tableview.MyColumns = MyColumns; _tableview.Table = tabledisplay; }
public void Load_table() { Dictionary<string, MyColumn> MyColumns = new Dictionary<string, MyColumn>(); DataTable table = dbOperation.GetDbHelper().GetDataSet(string.Format("call p_sampling_rate_details({0})", (Application.Current.Resources["User"] as UserInfo).ID)).Tables[0]; currenttable = table; list.Clear(); for (int i = 0; i < table.Rows.Count; i++) { DeptItem info = new DeptItem(); //info.DeptId = table.Rows[i][0].ToString(); info.DeptName = table.Rows[i][1].ToString(); //info.ItemId = table.Rows[i][2].ToString(); info.ItemName = table.Rows[i][3].ToString(); info.Task = table.Rows[i][4].ToString(); list.Add(info); } //得到行和列标题 及数量 string[] DeptNames = list.Select(t => t.DeptName).Distinct().ToArray(); string[] ItemNames = list.Select(t => t.ItemName).Distinct().ToArray(); //创建DataTable DataTable tabledisplay = new DataTable(); //表中第一行第一列交叉处一般显示为第1列标题 //tabledisplay.Columns.Add(new DataColumn("序号")); //MyColumns.Add("序号", new MyColumn("序号", "序号") { BShow = true, Width = 10 }); switch (user_flag_tier) { case "0": tabledisplay.Columns.Add(new DataColumn("省名称")); MyColumns.Add("省名称", new MyColumn("省名称", "省名称") { BShow = true, Width = 20 }); break; case "1": tabledisplay.Columns.Add(new DataColumn("市(州)单位名称")); MyColumns.Add("市(州)单位名称", new MyColumn("市(州)单位名称", "市(州)单位名称") { BShow = true, Width = 20 }); break; case "2": tabledisplay.Columns.Add(new DataColumn("区县名称")); MyColumns.Add("区县名称", new MyColumn("区县名称", "区县名称") { BShow = true, Width = 20 }); break; case "3": tabledisplay.Columns.Add(new DataColumn("检测单位名称")); MyColumns.Add("检测单位名称", new MyColumn("检测单位名称", "检测单位名称") { BShow = true, Width = 20 }); break; case "4": tabledisplay.Columns.Add(new DataColumn("检测单位名称")); MyColumns.Add("检测单位名称", new MyColumn("检测单位名称", "检测单位名称") { BShow = true, Width = 20 }); break; default: break; } //表中后面每列的标题其实是列分组的关键字 for (int i = 0; i < ItemNames.Length; i++) { DataColumn column = new DataColumn(ItemNames[i]); tabledisplay.Columns.Add(column); MyColumns.Add(ItemNames[i], new MyColumn(ItemNames[i], ItemNames[i]) { BShow = true, Width = 15 }); } //为表中各行生成数据 for (int i = 0; i < DeptNames.Length; i++) { var row = tabledisplay.NewRow(); //每行第0列为行分组关键字 //row[0] = i + 1; row[0] = DeptNames[i]; //每行的其余列为行列交叉对应的汇总数据 for (int j = 0; j < ItemNames.Length; j++) { string num = list.Where(t => t.DeptName == DeptNames[i] && t.ItemName == ItemNames[j]).Select(t => t.Task).FirstOrDefault(); if (num == null || num == "") { num = '0'.ToString(); } row[ItemNames[j]] = num; } tabledisplay.Rows.Add(row); } _tableview.BShowModify = true; _tableview.MyColumns = MyColumns; _tableview.Table = tabledisplay; }
public void Load_table() { Dictionary <string, MyColumn> MyColumns = new Dictionary <string, MyColumn>(); System.Data.DataTable table = dbOperation.GetDbHelper().GetDataSet(string.Format("call p_task_details({0})", (System.Windows.Application.Current.Resources["User"] as UserInfo).ID)).Tables[0]; currenttable = table; list.Clear(); for (int i = 0; i < table.Rows.Count; i++) { DeptItem info = new DeptItem(); info.DeptId = table.Rows[i][0].ToString(); info.DeptName = table.Rows[i][1].ToString(); info.ItemId = table.Rows[i][2].ToString(); info.ItemName = table.Rows[i][3].ToString(); info.Task = table.Rows[i][4].ToString(); list.Add(info); } //得到行和列标题 及数量 string[] DeptNames = list.Select(t => t.DeptName).Distinct().ToArray(); string[] ItemNames = list.Select(t => t.ItemName).Distinct().ToArray(); //创建DataTable System.Data.DataTable tabledisplay = new System.Data.DataTable(); //表中第一行第一列交叉处一般显示为第1列标题 //tabledisplay.Columns.Add(new DataColumn("序号")); //MyColumns.Add("序号", new MyColumn("序号", "序号") { BShow = true, Width = 10 }); switch (user_flag_tier) { case "0": tabledisplay.Columns.Add(new DataColumn("省名称")); MyColumns.Add("省名称", new MyColumn("省名称", "省名称") { BShow = true, Width = 20 }); break; case "1": tabledisplay.Columns.Add(new DataColumn("市(州)单位名称")); MyColumns.Add("市(州)单位名称", new MyColumn("市(州)单位名称", "市(州)单位名称") { BShow = true, Width = 20 }); break; case "2": tabledisplay.Columns.Add(new DataColumn("区县名称")); MyColumns.Add("区县名称", new MyColumn("区县名称", "区县名称") { BShow = true, Width = 20 }); break; case "3": tabledisplay.Columns.Add(new DataColumn("检测单位名称")); MyColumns.Add("检测单位名称", new MyColumn("检测单位名称", "检测单位名称") { BShow = true, Width = 20 }); break; case "4": tabledisplay.Columns.Add(new DataColumn("检测单位名称")); MyColumns.Add("检测单位名称", new MyColumn("检测单位名称", "检测单位名称") { BShow = true, Width = 20 }); break; default: break; } //表中后面每列的标题其实是列分组的关键字 for (int i = 0; i < ItemNames.Length; i++) { DataColumn column = new DataColumn(ItemNames[i]); tabledisplay.Columns.Add(column); MyColumns.Add(ItemNames[i].ToLower(), new MyColumn(ItemNames[i].ToLower(), ItemNames[i]) { BShow = true, Width = 15 }); } //为表中各行生成数据 for (int i = 0; i < DeptNames.Length; i++) { var row = tabledisplay.NewRow(); //每行第0列为行分组关键字 //row[0] = i + 1; row[0] = DeptNames[i]; //每行的其余列为行列交叉对应的汇总数据 for (int j = 0; j < ItemNames.Length; j++) { string num = list.Where(t => t.DeptName == DeptNames[i] && t.ItemName == ItemNames[j]).Select(t => t.Task).FirstOrDefault(); if (num == null || num == "") { num = '0'.ToString(); } row[ItemNames[j]] = num; } tabledisplay.Rows.Add(row); } if (table.Rows.Count != 0) { //表格最后添加合计行 tabledisplay.Rows.Add(tabledisplay.NewRow()[1] = "合计"); for (int j = 1; j < tabledisplay.Columns.Count; j++) { int sum = 0; for (int i = 0; i < tabledisplay.Rows.Count - 1; i++) { sum += Convert.ToInt32(tabledisplay.Rows[i][j].ToString()); } //sum_column += sum; tabledisplay.Rows[tabledisplay.Rows.Count - 1][j] = sum; } System.Data.DataTable tasktable = dbOperation.GetDbHelper().GetDataSet("select t_det_item.ItemNAME,task " + "from t_task_assign_new left JOIN t_det_item ON t_task_assign_new.iid = t_det_item.ItemID " + "where t_task_assign_new.did = " + deptid).Tables[0]; List <ItemTask> listtask = new List <ItemTask>(); listtask.Clear(); for (int i = 0; i < tasktable.Rows.Count; i++) { ItemTask task = new ItemTask(); task.ItemName = tasktable.Rows[i][0].ToString(); task.Task = tasktable.Rows[i][1].ToString(); listtask.Add(task); } if (user_flag_tier != "1") { //表格最后添加上级分配任务量 tabledisplay.Rows.Add(tabledisplay.NewRow()[1] = "上级下达任务量"); for (int j = 1; j < tabledisplay.Columns.Count; j++) { string task = listtask.Where(s => s.ItemName == tabledisplay.Columns[j].ColumnName.ToString()).Select(s => s.Task).FirstOrDefault(); if (task == null || task == "") { task = '0'.ToString(); } tabledisplay.Rows[tabledisplay.Rows.Count - 1][j] = task; } //表格最后添加未分配量 tabledisplay.Rows.Add(tabledisplay.NewRow()[1] = "未分配量"); for (int j = 1; j < tabledisplay.Columns.Count; j++) { int rwl = Convert.ToInt32(tabledisplay.Rows[tabledisplay.Rows.Count - 2][j].ToString()); int yfp = Convert.ToInt32(tabledisplay.Rows[tabledisplay.Rows.Count - 3][j].ToString()); int wfp = rwl - yfp; tabledisplay.Rows[tabledisplay.Rows.Count - 1][j] = wfp; } } } exporttable = tabledisplay; _tableview.BShowModify = true; _tableview.MyColumns = MyColumns; _tableview.Table = tabledisplay; }
public void Load_table() { Dictionary <string, MyColumn> MyColumns = new Dictionary <string, MyColumn>(); string function = ""; switch (dept_type) { case "0": function = "p_task_details_produce"; break; case "1": function = "p_task_details_fishery"; break; case "2": function = "p_task_details_animal"; break; default: break; } System.Data.DataTable table = sysTaskContract.ExecuteProTaskDetails(function, PubClass.userInfo.ID); currenttable = table; list.Clear(); for (int i = 0; i < table.Rows.Count; i++) { DeptItem info = new DeptItem(); info.DeptId = table.Rows[i][0].ToString(); info.DeptName = table.Rows[i][1].ToString(); info.ItemId = table.Rows[i][2].ToString(); info.ItemName = table.Rows[i][3].ToString(); info.Task = table.Rows[i][4].ToString(); list.Add(info); } //得到行和列标题 及数量 string[] DeptNames = list.Select(t => t.DeptName).Distinct().ToArray(); string[] ItemNames = list.Select(t => t.ItemName).Distinct().ToArray(); //创建DataTable System.Data.DataTable tabledisplay = new System.Data.DataTable(); //表中第一行第一列交叉处一般显示为第1列标题 //tabledisplay.Columns.Add(new DataColumn("序号")); //MyColumns.Add("序号", new MyColumn("序号", "序号") { BShow = true, Width = 10 }); tabledisplay.Columns.Add(new DataColumn("部门名称")); MyColumns.Add("部门名称", new MyColumn("部门名称", "部门名称") { BShow = true, Width = 20 }); //表中后面每列的标题其实是列分组的关键字 for (int i = 0; i < ItemNames.Length; i++) { DataColumn column = new DataColumn(ItemNames[i]); tabledisplay.Columns.Add(column); MyColumns.Add(ItemNames[i], new MyColumn(ItemNames[i], ItemNames[i]) { BShow = true, Width = 15 }); } //为表中各行生成数据 for (int i = 0; i < DeptNames.Length; i++) { var row = tabledisplay.NewRow(); //每行第0列为行分组关键字 //row[0] = i + 1; row[0] = DeptNames[i]; //每行的其余列为行列交叉对应的汇总数据 for (int j = 0; j < ItemNames.Length; j++) { string num = list.Where(t => t.DeptName == DeptNames[i] && t.ItemName == ItemNames[j]).Select(t => t.Task).FirstOrDefault(); if (num == null || num == "") { num = '0'.ToString(); } row[ItemNames[j]] = num; } tabledisplay.Rows.Add(row); } if (table.Rows.Count != 0) { //表格最后添加合计行 tabledisplay.Rows.Add(tabledisplay.NewRow()[1] = "合计"); for (int j = 1; j < tabledisplay.Columns.Count; j++) { int sum = 0; for (int i = 0; i < tabledisplay.Rows.Count - 1; i++) { sum += Convert.ToInt32(tabledisplay.Rows[i][j].ToString()); } //sum_column += sum; tabledisplay.Rows[tabledisplay.Rows.Count - 1][j] = sum; } System.Data.DataTable tasktable = new System.Data.DataTable(); tasktable = sysTaskContract.GetTaskTable(dept_type, deptid); List <ItemTask> listtask = new List <ItemTask>(); listtask.Clear(); for (int i = 0; i < tasktable.Rows.Count; i++) { ItemTask task = new ItemTask(); task.ItemName = tasktable.Rows[i][0].ToString(); task.Task = tasktable.Rows[i][1].ToString(); listtask.Add(task); } if (user_flag_tier != "1") { //表格最后添加上级分配任务量 tabledisplay.Rows.Add(tabledisplay.NewRow()[1] = "上级下达任务量"); for (int j = 1; j < tabledisplay.Columns.Count; j++) { string task = listtask.Where(s => s.ItemName == tabledisplay.Columns[j].ColumnName.ToString()).Select(s => s.Task).FirstOrDefault(); if (task == null || task == "") { task = '0'.ToString(); } tabledisplay.Rows[tabledisplay.Rows.Count - 1][j] = task; } //表格最后添加未分配量 tabledisplay.Rows.Add(tabledisplay.NewRow()[1] = "未分配量"); for (int j = 1; j < tabledisplay.Columns.Count; j++) { int rwl = Convert.ToInt32(tabledisplay.Rows[tabledisplay.Rows.Count - 2][j].ToString()); int yfp = Convert.ToInt32(tabledisplay.Rows[tabledisplay.Rows.Count - 3][j].ToString()); int wfp = rwl - yfp; tabledisplay.Rows[tabledisplay.Rows.Count - 1][j] = wfp; } } } exporttable = tabledisplay; _tableview.BShowModify = true; _tableview.MyColumns = MyColumns; _tableview.Table = tabledisplay; }