public ShowData() { iniTablt(); InitializeComponent(); this.Dock = DockStyle.Fill; CheckDatas.DataSource = null; //根据用户输入的条件组合查询语句,将原来的String 换成StringBuilder对象,提高代码性能 StringBuilder sb = new StringBuilder(); sb.Append("CheckTime>=#"); sb.Append("2017-4-19");//yyyy-MM-dd sb.Append("#"); sb.Append(" AND CheckTime<=#"); sb.Append("2017-4-29"); sb.Append(" 23:59:59#"); //if (!string.IsNullOrEmpty(cmbResult.Text.Trim())) //{ // sb.AppendFormat("AND Result='%{0}%'", cmbResult.Text.Trim()); //} //if (!string.IsNullOrEmpty(cmbTestItem.Text.Trim())) //{ // sb.AppendFormat("AND Checkitem='%{0}%'", cmbTestItem.Text.Trim()); //} //if (!string.IsNullOrEmpty(cmbTestUnit.Text.Trim())) //{ // sb.AppendFormat("AND CheckUnit='%{0}%'", cmbTestUnit.Text.Trim()); //} //if (!string.IsNullOrEmpty(cmbSample.Text.Trim())) //{ // sb.AppendFormat("AND SampleName='%{0}%'", cmbSample.Text.Trim()); //} sb.Append(" ORDER BY ID"); DataTable dtb = sql.GetDataTable(sb.ToString(), ""); if (dtb != null) { for (int i = 0; i < dtb.Rows.Count; i++) { // GridNum,Checkitem,SampleName,CheckData,Unit,CheckTime,CheckUnit,Result,Machine"); TableNewRow(dtb.Rows[i][0].ToString(), dtb.Rows[i][1].ToString(), dtb.Rows[i][2].ToString(), dtb.Rows[i][3].ToString(), dtb.Rows[i][4].ToString(), dtb.Rows[i][5].ToString(), dtb.Rows[i][6].ToString(), dtb.Rows[i][7].ToString(), dtb.Rows[i][8].ToString()); } CheckDatas.DataSource = DataReadTable; } }
//查询 private void btnfind_Click(object sender, EventArgs e) { btnfind.Enabled = false; DataReadTable.Clear(); CheckDatas.DataSource = null; //根据用户输入的条件组合查询语句,将原来的String 换成StringBuilder对象,提高代码性能 StringBuilder sb = new StringBuilder(); sb.Append("CheckTime>=#"); sb.Append(dTStart.Value.ToString("yyyy/MM/dd"));//yyyy-MM-dd sb.Append("#"); sb.Append(" AND CheckTime<=#"); sb.Append(dTPEnd.Value.ToString("yyyy/MM/dd")); sb.Append(" 23:59:59#"); if (!string.IsNullOrEmpty(cmbResult.Text.Trim()) && cmbResult.Text.Trim() != "请选择...") { sb.AppendFormat("AND Result='{0}'", cmbResult.Text.Trim()); } if (!string.IsNullOrEmpty(cmbTestItem.Text.Trim()) && cmbTestItem.Text.Trim() != "请选择...") { sb.AppendFormat("AND Checkitem='{0}'", cmbTestItem.Text.Trim()); } if (!string.IsNullOrEmpty(cmbSample.Text.Trim()) && cmbSample.Text.Trim() != "请选择...") { sb.AppendFormat("AND SampleName='{0}'", cmbSample.Text.Trim()); } sb.Append(" ORDER BY ID"); DataTable dtb = sql.GetDataTable(sb.ToString(), ""); if (dtb != null) { for (int i = 0; i < dtb.Rows.Count; i++) { TableNewRow(dtb.Rows[i]["ChkNum"].ToString(), dtb.Rows[i]["Checkitem"].ToString(), dtb.Rows[i]["SampleName"].ToString(), dtb.Rows[i]["CheckData"].ToString(), dtb.Rows[i]["Unit"].ToString(), dtb.Rows[i]["CheckTime"].ToString(), dtb.Rows[i]["CheckUnit"].ToString(), dtb.Rows[i]["Result"].ToString(), dtb.Rows[i]["Machine"].ToString()); } CheckDatas.DataSource = DataReadTable; CheckDatas.Columns[6].Width = 160; } //CmbgetItemName();//获取检测项目 //CmbgetSampleName();//获取样品名称 generateChart();//生成柱行图 btnfind.Enabled = true; }
/// <summary> /// 数据上传 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdata_Click(object sender, EventArgs e) { if (CheckDatas.Rows.Count < 1) { MessageBox.Show("没有检测数据上传", "提示"); return; } if (Global.ServerAdd.Length == 0) { MessageBox.Show("服务器地址不能为空", "提示"); return; } if (Global.DetectUnit.Length == 0) { MessageBox.Show("检测单位不能为空", "提示"); return; } DialogResult tishi = MessageBox.Show("共有" + CheckDatas.Rows.Count + "条数据是否上传", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (tishi == DialogResult.No) { return; } btnUpdata.Enabled = false; Global.ServerAdd = ConfigurationManager.AppSettings["ServerAddr"]; //服务器地址 Global.DetectUnit = ConfigurationManager.AppSettings["UpDetectUnit"]; //检测单位 Global.DetectUnitNo = ConfigurationManager.AppSettings["UpDetectUnitNo"]; //检测单位编号 Global.UploadType = ConfigurationManager.AppSettings["UploadType"]; //上传类型 Global.IntrumentNum = ConfigurationManager.AppSettings["IntrumentNum"]; //设备ID string err = ""; int iok = 0; int ino = 0; string ErrInfo = ""; try { for (int i = 0; i < CheckDatas.Rows.Count; i++) { //边查询边上传 StringBuilder sbd = new StringBuilder(); sbd.Append("Checkitem='"); sbd.Append(CheckDatas.Rows[i].Cells[2].Value.ToString()); sbd.Append("' and SampleName='"); sbd.Append(CheckDatas.Rows[i].Cells[1].Value.ToString()); sbd.Append("' and CheckData='"); sbd.Append(CheckDatas.Rows[i].Cells[3].Value.ToString()); sbd.Append("' and CheckTime=#"); sbd.Append(DateTime.Parse(CheckDatas.Rows[i].Cells[14].Value.ToString())); sbd.Append("#"); //查询界面上没有的数据信息 DataTable rt = sqlSet.GetDataTable(sbd.ToString(), ""); if (rt != null && rt.Rows.Count > 0) { udata.detectunit = CheckDatas.SelectedRows[i].Cells[9].Value.ToString(); //被检单位 udata.checkunit = CheckDatas.SelectedRows[i].Cells[11].Value.ToString(); //被检单位 udata.checkitem = CheckDatas.SelectedRows[i].Cells[1].Value.ToString(); //检测项目 udata.ttime = CheckDatas.SelectedRows[i].Cells[13].Value.ToString(); //检测时间 udata.chkdata = CheckDatas.SelectedRows[i].Cells[2].Value.ToString(); //检测数值 udata.unit = System.Web.HttpUtility.UrlEncode(rt.Rows[0][4].ToString()); //System.Web.HttpUtility.UrlEncode("%");//数值单位 对非法字符进行url转换 if (CheckDatas.SelectedRows[i].Cells[7].Value.ToString() == "阴性" || CheckDatas.SelectedRows[i].Cells[7].Value.ToString() == "合格") { udata.Conclusion = "合格";// 检测结论 } else { udata.Conclusion = "不合格"; } udata.samplenumber = rt.Rows[0][18].ToString(); //样品编号 udata.samplename = CheckDatas.SelectedRows[i].Cells[0].Value.ToString(); //样品名称 udata.sampleOrigin = CheckDatas.SelectedRows[i].Cells[10].Value.ToString(); //样品产地 udata.testbase = rt.Rows[0][12].ToString(); //检测依据 udata.ChkMachineNum = rt.Rows[0][20].ToString(); //设备编号 udata.standvalue = rt.Rows[0][13].ToString(); //标准值 udata.chker = CheckDatas.SelectedRows[i].Cells[12].Value.ToString(); udata.uptype = int.Parse(Global.UploadType); udata.shebeiID = Global.IntrumentNum; string rd = KeRunUpData.UpData(udata); JavaScriptSerializer jsup = new JavaScriptSerializer(); KeRunUpData.ReturnInfo retu = jsup.Deserialize <KeRunUpData.ReturnInfo>(rd); //将json数据转化为对象类型并赋值给list if (retu.status == "1" && retu.info == "success") { CheckDatas.SelectedRows[i].DefaultCellStyle.BackColor = Color.Green;//上传成功变绿色 iok = iok + 1; clsUpdateData ud = new clsUpdateData(); ud.result = CheckDatas.SelectedRows[i].Cells[2].Value.ToString(); ud.ChkTime = CheckDatas.SelectedRows[i].Cells[13].Value.ToString(); sqlSet.SetUpLoadData(ud, out err); } else { ino = ino + 1; ErrInfo = ErrInfo + "(" + ino + ")" + retu.info; } } } MessageBox.Show("共成功上传" + iok + "条数据;失败" + ino + "条数据,失败原因:" + ErrInfo, "数据上传"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } btnUpdata.Enabled = true; }