protected void btn_Add_Click(object sender, EventArgs e) { lbl_Type.Text = "添加"; CleanAllText(); btn_OK.Text = "确定"; Query(); string str = "select top 1 t_M_AnStandard.id,t_M_AnStandard.Standard from t_M_AIStandard inner join t_M_AnStandard on t_M_AnStandard.Standard=t_M_AIStandard.Standard where AIID='" + strSelectedId + "'"; DataSet tep = new MyDataOp(str).CreateDataSet(); dsmethod = tep.Clone(); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "click", "showAddEdit();", true); }
public void Query() { DateTime s = DateTime.Parse("2010-6-16 00:00:00"); DateTime end = DateTime.Parse(DateTime.Now.ToString()); if (txt_StartTime.Text.Trim() != "") { s = DateTime.Parse(txt_StartTime.Text.Trim() + " 0:00:00"); } if (txt_EndTime.Text.Trim() != "") { end = DateTime.Parse(txt_EndTime.Text.Trim() + " 23:59:59"); } // string strItem = "select id,AIName from t_M_AnalysisItemEx order by id"; string strItem = "Select distinct MonitorItem,AIName from View_MonitorItem where AccessDate BETWEEN '" + s + "' AND '" + end + "' "; DataSet ds = new MyDataOp(strItem).CreateDataSet(); DataSet ds_new = ds.Clone(); DataColumn dcdate = new DataColumn("日期"); ds_new.Tables[0].Columns.Add(dcdate); foreach (DataRow dr in ds.Tables[0].Rows) { DataColumn dc = new DataColumn(dr["AIName"].ToString() + "(" + dr["MonitorItem"].ToString() + ")", typeof(Int16)); DataColumn dcid = new DataColumn(dr["MonitorItem"].ToString(), typeof(Int16)); ds_new.Tables[0].Columns.Add(dc); ds_new.Tables[0].Columns.Add(dcid); } string strToday = @"SELECT sum(N) AS Expr1, MonitorItem, CreateDate " + "FROM (SELECT count(MonitorItem) AS N, MonitorItem, LEFT(CONVERT(varchar, AccessDate, 120), 10) CreateDate " + " FROM t_MonitorItemDetail INNER JOIN" + " t_M_SampleInfor ON " + " t_M_SampleInfor.id = t_MonitorItemDetail.SampleID" + " WHERE (AccessDate BETWEEN '" + s + "' AND '" + end + "') GROUP BY MonitorItem, AccessDate) a" + " GROUP BY MonitorItem, CreateDate" + " ORDER BY CreateDate, MonitorItem"; //将统计数据加入到DataSet中 DataSet dsData = new MyDataOp(strToday).CreateDataSet(); if (dsData.Tables[0].Rows.Count > 0) { for (DateTime dt = s; dt < end;) { DataRow dr = ds_new.Tables[0].NewRow(); dr["日期"] = dt.Date.ToString("yyyy-MM-dd"); for (int i = 4; i < ds_new.Tables[0].Columns.Count; i = i + 2) { DataRow[] drdata = dsData.Tables[0].Select("CreateDate='" + dt.Date.ToString("yyyy-MM-dd") + "' and MonitorItem='" + ds_new.Tables[0].Columns[i].ColumnName + "'"); if (drdata.Length > 0) { dr[i - 1] = drdata[0][0].ToString(); } else { dr[i - 1] = "0"; } } ds_new.Tables[0].Rows.Add(dr); dt = dt.AddDays(1); } DataRow total = ds_new.Tables[0].NewRow(); ds_new.Tables[0].Columns.Remove("MonitorItem"); ds_new.Tables[0].Columns.Remove("AIName"); ds_new.Tables[0].AcceptChanges(); total[0] = "合计"; for (int j = 1; j < ds_new.Tables[0].Columns.Count; j = j + 2) { if (j % 2 == 1) { object temp = ds_new.Tables[0].Compute("sum([" + ds_new.Tables[0].Columns[j].ColumnName + "])", ""); total[j] = Int16.Parse(temp.ToString()); } } ds_new.Tables[0].Rows.Add(total); } if (ds_new.Tables[0].Rows.Count == 0) { //没有记录仍保留表头 ds_new.Tables[0].Rows.Add(ds_new.Tables[0].NewRow()); grdvw_List.DataSource = ds_new; grdvw_List.DataBind(); int intColumnCount = grdvw_List.Rows[0].Cells.Count; grdvw_List.Rows[0].Cells.Clear(); grdvw_List.Rows[0].Cells.Add(new TableCell()); grdvw_List.Rows[0].Cells[0].ColumnSpan = intColumnCount; } else { grdvw_List.DataSource = ds_new; grdvw_List.DataBind(); } }