private void Button_Click_2(object sender, RoutedEventArgs e) { string txt_Val = txtare_s_dj.Text.Trim(); bool fromChifeng = false; txt_Val = Regex.Replace(txt_Val, @"[\r\n]", ""); List <string> lstJcxm = txt_Val.Replace("\r\n", "").Split(',').ToList(); string type = txt_type.Text.Trim(); if (string.IsNullOrEmpty(type)) { MessageBox.Show("试验编号不可以为空"); return; } List <string> lstInsertSqls = new List <string>(); Base.SqlBase sqlbaseChiFeng = new Base.SqlBase(); DataSet ds = new DataSet(); string sqlstr = ""; string insertSql = ""; int retCount = 0; int valuesIndex = 0; int SJBMCIndex = 0; //select* from weblab_chifeng.dbo.ZDZD_WJJ where SJBMC = '' ZDMC like '%JPHWZL_%' }
public static string GetAfferentDataJson2(string type, string sql, string m_json = null, string y_json = null) { StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); sb.Append("{\"data\":[{"); Base.SqlBase sqlbase = new Base.SqlBase("local"); DataSet ds = sqlbase.ExecuteDataset(sql); DataTable dt = ds.Tables[0]; string json = Base.JsonHelper.SerializeObject(dt); sb2.Append("\"" + type + "\":"); sb2.Append(json); if (m_json != null) { sb2.Append(m_json); } if (y_json != null) { sb2.Append(y_json); } sb.Append(sb2.ToString().TrimEnd(',')); sb.Append("}],\"code\":1, \"message\":\"成功\"}"); return(sb.ToString()); }
public static string GetAfferentDataJson(string type, string sql) { StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); sb.Append("{\"calcData\":[{"); //string sql = string.Format(@"select top 1 * from " + tableName); Base.SqlBase sqlbase = new Base.SqlBase("local"); DataSet ds = sqlbase.ExecuteDataset(sql); DataTable dt = ds.Tables[0]; string[] jcxm_list = dt.Rows[0]["jcxm"].ToString().Split('、'); foreach (string item in jcxm_list) { sb2.Append("\"" + item + "\":{"); DataTable dt_json = ToDataTable(dt.Select(" jcxm like '%" + item.Trim() + "%'")); string json = Base.JsonHelper.SerializeObject(dt_json); sb2.Append("\"" + type + "\":" + json + ""); sb2.Append(",\"S_BY_RW_XQ\":["); for (int i = 0; i < dt.Select(" jcxm like '%" + item.Trim() + "%'").Length; i++) { sb2.Append("{\"RECID\":\"19085206791636631332933\","); sb2.Append("\"SJWCJSSJ\":\"" + DateTime.Now.ToString() + "\","); sb2.Append("\"JCJG\":\"\","); sb2.Append("\"JCJGMS\":\"\""); sb2.Append("},"); } sb2.Remove(sb2.Length - 1, 1).Append("]},"); sb2.Append("\"BGJG\": {\"M_BY_BG\": [{\"JCJG\": \"不合格\",\"JCJGMS\": \"\"}]},"); } sb.Append(sb2.ToString().TrimEnd(',')); sb.Append("}],\"code\":1, \"message\":\"成功\"}"); return(sb.ToString()); }
public static string GetDataJson(string type, string sqlstr, string tableName, Dictionary <string, string> testDatas = null) { StringBuilder sb = new StringBuilder(); sb.Append("{\"calcData\":{\"" + type + "\":"); string sql = string.Format(@sqlstr); Base.SqlBase sqlbase = new Base.SqlBase(Base.ESqlConnType.ConnectionStringLocal); DataSet ds = sqlbase.ExecuteDataset(sql); if (testDatas != null) { ds.Tables[0].Rows[0][0] = testDatas["QDYQ1"]; ds.Tables[0].Rows[0][1] = testDatas["QDYQ2"]; ds.Tables[0].Rows[0][2] = testDatas["QDYQ3"]; ds.Tables[0].Rows[0][3] = testDatas["QDYQ4"]; ds.Tables[0].Rows[0][4] = testDatas["QDYQ5"]; ds.Tables[0].Rows[0][5] = testDatas["QDYQ6"]; ds.Tables[0].Rows[0][6] = testDatas["SFBSS1"]; ds.Tables[0].Rows[0][7] = testDatas["SFBSS2"]; ds.Tables[0].Rows[0][8] = testDatas["SFBSS3"]; ds.Tables[0].Rows[0][9] = testDatas["SFBSS4"]; ds.Tables[0].Rows[0][10] = testDatas["SFBSS5"]; ds.Tables[0].Rows[0][11] = testDatas["SFBSS6"]; } ds.Tables[0].TableName = tableName; string json = Base.JsonHelper.SerializeObject(ds); sb.Append(json); sb.Append("},\"code\":1,\"message\":\"成功\"}"); Base.JsonHelper.GetDictionary(sb.ToString(), type); return(sb.ToString()); }
public static string GetMdataJson(string type, string sql, string table_name) { StringBuilder sb = new StringBuilder(); Base.SqlBase sqlbase = new Base.SqlBase(type); DataSet ds = sqlbase.ExecuteDataset(sql); DataTable dt = ds.Tables[0]; string json = Base.JsonHelper.SerializeObject(dt); sb.Append(",\"" + table_name + "\":"); sb.Append(json); return(sb.ToString()); }
public static string GetExtraDataJson(string work, string tablename) { StringBuilder sb = new StringBuilder(); sb.Append("{\"calcData\":{\"" + work + "\":"); string sql = string.Format(@"select * from " + tablename); Base.SqlBase sqlbase = new Base.SqlBase("local"); DataSet ds = sqlbase.ExecuteDataset(sql); ds.Tables[0].TableName = tablename; string json = Base.JsonHelper.SerializeObject(ds); sb.Append(json); sb.Append("},\"code\":1,\"message\":\"成功\"}"); GetDictionary(sb.ToString(), work); return(sb.ToString()); }
public static string GetDataJson(string type, string sqlstr, string tableName) { StringBuilder sb = new StringBuilder(); sb.Append("{\"calcData\":{\"" + type + "\":"); string sql = string.Format(@sqlstr); Base.SqlBase sqlbase = new Base.SqlBase(); DataSet ds = sqlbase.ExecuteDataset(sql); ds.Tables[0].TableName = tableName; string json = Base.JsonHelper.SerializeObject(ds); sb.Append(json); sb.Append("},\"code\":1,\"message\":\"成功\"}"); Base.JsonHelper.GetDictionary(sb.ToString(), type); return(sb.ToString()); }
private void btn_SDJ_Click(object sender, RoutedEventArgs e) { string txt_Val = txtare_s_dj.Text.Trim(); bool fromChifeng = false; txt_Val = Regex.Replace(txt_Val, @"[\r\n]", ""); List <string> lstJcxm = txt_Val.Replace("\r\n", "").Split(',').ToList(); string type = txt_type.Text.Trim(); if (string.IsNullOrEmpty(type)) { MessageBox.Show("试验编号不可以为空"); return; } List <string> lstInsertSqls = new List <string>(); Base.SqlBase sqlbaseChiFeng = new Base.SqlBase(); DataSet ds = new DataSet(); string sqlstr = ""; string insertSql = ""; int retCount = 0; int valuesIndex = 0; int SJBMCIndex = 0; foreach (var zdmc in lstJcxm) { //判断字段是否已经添加 sqlstr = string.Format(" select * FROM ZDZD_{0} where SJBMC='S_DJ_{0}' and sy ='{1}'", type, zdmc.Trim()); retCount = CommondSQL(sqlstr); if (retCount > 0) { continue; } fromChifeng = false; sqlstr = string.Format(" exec GetZDZDData 'ZDZD_{0}', ' 1=1 and sy = ''{1}'' and SJBMC=''S_{0}'' ' ", type, zdmc.Trim()); //sqlstr = string.Format(" exec GetZDZDData 'ZDZD_{0}', ' 1=1 and sy = ''{1}'' and SJBMC=''S_{0}'' ' ", "HD", "检测项目"); ds = sqlbase.ExecuteDataset(sqlstr); DataTable dt = ds.Tables[0]; if (dt.Rows.Count == 0) { fromChifeng = true; sqlstr = string.Format(" exec GetZDZDData 'ZDZD_{0}', ' 1=1 and sy = ''{1}'' and SJBMC=''S{0}'' ' ", type, zdmc.Trim()); ds = sqlbaseChiFeng.ExecuteDataset(sqlstr); dt = ds.Tables[0]; } foreach (var item in dt.Rows) { var itemArray = ((System.Data.DataRow)item).ItemArray; insertSql = ""; for (int i = 0; i < itemArray.Count(); i++) { if (i == 1 || i == 2) { continue; } if (string.IsNullOrEmpty(itemArray[i].ToString())) { insertSql += "null"; } insertSql += itemArray[i]; } insertSql = insertSql.ToUpper(); if (fromChifeng) { valuesIndex = insertSql.IndexOf("VALUES("); SJBMCIndex = insertSql.IndexOf("'S", valuesIndex); } else { valuesIndex = insertSql.IndexOf("VALUES("); SJBMCIndex = insertSql.IndexOf("N'S_", valuesIndex); } insertSql = insertSql.Remove(valuesIndex + 7, SJBMCIndex - valuesIndex - 7); insertSql = insertSql.Replace("RECID,", "").Replace("SJGJ_ID,", "").Replace("FALSE", "0").Replace("TRUE", "1").Replace(string.Format("N'S_{0}'", type), string.Format("N'S_DJ_{0}'", type)).Replace(string.Format("('S{0}',", type), string.Format("('S_DJ_{0}',", type)); lstInsertSqls.Add(insertSql); } } if (lstInsertSqls.Count > 0) { lstInsertSqls.Add(string.Format("update ZDZD_{0} set LX = '{1}' where SJBMC = 'S_DJ_{0}' and LX is null", type, ((System.Windows.Controls.ContentControl)lisBoxLX.SelectedItem).Content.ToString())); lstInsertSqls.Add(string.Format("update ZDZD_{0} set ZDLX = 'NVARCHAR' where ZDLX='C'", type)); lstInsertSqls.Add(string.Format("update ZDZD_{0} set ZDLX = 'int' where ZDLX='I'", type)); lstInsertSqls.Add(string.Format("update ZDZD_{0} set ZDLX = 'NUMERIC' where ZDLX='N'", type)); lstInsertSqls.Add(string.Format("update ZDZD_{0} set ZDLX = 'text' where ZDLX='M'", type)); lstInsertSqls.Add(string.Format("update ZDZD_{0} set datetime = 'text' where ZDLX='D'", type)); lstInsertSqls.Add(string.Format("update ZDZD_{0} set XSCD = 0 where SJBMC='S_DJ_{0}'", type)); //update ZDZD_WJJ set XSCD = 0 where SJBMC = 's_DJ_WJJ' //--update ZDZD_HD set ZDLX = 'nvarchar' where ZDLX = 'C' //--update ZDZD_HD set ZDLX = 'int' where ZDLX = 'I' //--update ZDZD_HD set ZDLX = 'bit' where ZDLX = 'L' //--update ZDZD_HD set ZDLX = 'numeric' where ZDLX = 'N' //--update ZDZD_HD set ZDLX = 'text' where ZDLX = 'M' //--update ZDZD_HD set ZDLX = 'datetime' where ZDLX = 'D' //--update ZDZD_HD set KJLX = 'CHECKBOX' where KJLX = 'C' //-- 不定类型 update ZDZD_HD set KJLX = 'COMBOBOX' where KJLX = 'B' //--update ZDZD_HD set KJLX = 'RADIO' where KJLX = 'R' //--update ZDZD_HD set KJLX = 'SELECT' where KJLX = 'S' } foreach (var item in lstInsertSqls) { int we = CommondSQL(item); } }