/// <summary> /// 检测项目标准下载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDownItemStand_Click(object sender, EventArgs e) { btnDownItemStand.Enabled = false; if (Global.ServerAdd.Length == 0) { MessageBox.Show("服务器地址不能为空", "提示"); btnDownItemStand.Enabled = true; return; } if (Global.ServerName.Length == 0) { MessageBox.Show("用户名不能为空", "提示"); btnDownItemStand.Enabled = true; return; } if (Global.ServerPassword.Length == 0) { MessageBox.Show("密码不能为空", "提示"); btnDownItemStand.Enabled = true; return; } string err = ""; int icount = 0; try { KunShanEntity.CheckItemRequest.webService checkItem = new KunShanEntity.CheckItemRequest.webService(); checkItem.head = new KunShanEntity.CheckItemRequest.Head(); checkItem.head.name = Global.ServerName; checkItem.head.password = Global.MD5(Global.ServerPassword); checkItem.request = new KunShanEntity.CheckItemRequest.Request(); checkItem.request.Id = "0"; checkItem.request.UpdateDate = "";//DateTime.MinValue.ToString("yyyy-MM-dd HH:mm:ss"); string response = XmlHelper.EntityToXml <KunShanEntity.CheckItemRequest.webService>(checkItem); string CheckItem = webserver.QueryCheckItem(response); List <KunShanEntity.CheckItem> models = JsonHelper.JsonToEntity <List <KunShanEntity.CheckItem> >(CheckItem); if (models != null && models.Count > 0) { csql.DeleteItem("", out err);//删除原有数据 KunShanEntity.CheckItem items = new KunShanEntity.CheckItem(); for (int i = 0; i < models.Count; i++) { items.Id = models[i].Id; items.ItemCode = models[i].ItemCode; items.ItemName = models[i].ItemName; items.SubItemCode = models[i].SubItemCode; items.SubItemName = models[i].SubItemName; items.UpdateDate = models[i].UpdateDate; csql.InKSItem(items, out err); icount = icount + 1; } } MessageBox.Show("检测项目标准下载成功,共下载" + icount.ToString() + "条记录", "提示"); //string rtndata = InterfaceHelper.DownloadBasicData(Global.DownLoadItemAndStandard, out err); //ResultMsg jsonResult = GetData(rtndata); //if (jsonResult == null && jsonResult.result != null) //{ // MessageBox.Show("暂时没有数据可更新!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); // btnDownItemStand.Enabled = true; // return; //} //ItemAndStandard itemAndStandard = null; //downLoadItemAndStandardList = new List<ItemAndStandard>(); //downLoadItemAndStandardList = JsonHelper.JsonToEntity<List<ItemAndStandard>>(jsonResult.result.ToString());//(List<ItemAndStandard>)JsonConvert.DeserializeObject(jsonResult.result.ToString(), typeof(List<ItemAndStandard>)); //if (downLoadItemAndStandardList == null || downLoadItemAndStandardList.Count == 0) //{ // MessageBox.Show( "暂时没有数据可更新!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); // btnDownItemStand.Enabled = true; // return; //} ////删除原来表的数据再插入 //csql.DeleteItemStandard("", "", out err); //for (int i = 0; i < downLoadItemAndStandardList.Count; i++) //{ // itemAndStandard = downLoadItemAndStandardList[i]; // csql.InItemStandard(itemAndStandard ,out err ); //} } catch (Exception ex) { btnDownItemStand.Enabled = true; MessageBox.Show(ex.Message, "Error"); } //try //{ // StringBuilder sb = new StringBuilder(); // dt = csql.GetDownChkItem("", "", out err); // //dt= csql.GetChkItem("", "", out err); // if (dt != null) // { // if (dt.Rows.Count > 0) // { // DataDisTable.Clear(); // //for (int i = 0; i < dt.Rows.Count; i++) // //{ // // addtable(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString(), dt.Rows[i][3].ToString(), dt.Rows[i][4].ToString(), dt.Rows[i][5].ToString()); // //} // CheckDatas.DataSource = dt;//DataDisTable; // CheckDatas.Columns[0].HeaderCell.Value = "样品名称"; // CheckDatas.Columns[1].HeaderCell.Value = "检测项目"; // CheckDatas.Columns[2].HeaderCell.Value = "检测依据"; // CheckDatas.Columns[3].HeaderCell.Value = "标准值"; // CheckDatas.Columns[4].HeaderCell.Value = "判定符号"; // CheckDatas.Columns[5].HeaderCell.Value = "单位"; // for (int j = 0; j < CheckDatas.RowCount; j++) // { // CheckDatas.Columns[0].Width = 200; // CheckDatas.Columns[1].Width = 200; // CheckDatas.Columns[2].Width = 200; // } // } // } //} //catch (Exception ex) //{ // btnDownItemStand.Enabled = true; // MessageBox.Show(ex.Message, "Error"); //} btnDownItemStand.Enabled = true; }