1 class Program 2 { 3 static void Main(string[] args) 4 { 5 using (SyncSRV.ServiceSoapClient client = new SyncSRV.ServiceSoapClient()) 6 { 7 8 try 9 { 10 var commandText = ""; 11 StringBuilder strSql = new StringBuilder(); 12 strSql.Length = 0; 13 14 // 清空原始数据,在表 msp_stor_fdbck 中 15 16 strSql.Append("DELETE msp_stor_fdbck "); 17 18 // GetDIY(DIY暗访) 19 var jsonText = client.GetDIY().ToString(); 20 List<dsStore> a = JsonDeserialize<List<dsStore>>(jsonText); 21 List<dsMR> b = JsonDeserialize<List<dsMR>>(jsonText); 22 23 foreach (dsStore item in a) 24 { 25 strSql.Append("INSERT INTO msp_stor_fdbck "); 26 strSql.Append("([stor_id] ,[nm] ,[addr] ,[fdbck_cntn], "); 27 strSql.Append("[last_upd_dtm] ,[iss_sts] ,[fdbck_cntn_remark]) "); 28 strSql.AppendFormat("VALUES ('{0}','{1}','{2}','{3}',", item.stor_id, CheckStr(item.stor_nm), CheckStr(item.stor_addr), CheckStr(item.fwFeedBackConter)); 29 strSql.AppendFormat("'{0}','{1}','{2}' ) ", JsonDateString(item.fwFeedBackDate), item.isSeccess, CheckStr(item.FwFeedBackRemark)); 30 } 31 32 // GetDIYMing(DIY明访) 33 jsonText = client.GetDIYMing().ToString(); 34 a = JsonDeserialize<List<dsStore>>(jsonText); 35 36 foreach (dsStore item in a) 37 { 38 strSql.Append("INSERT INTO msp_stor_fdbck "); 39 strSql.Append("([stor_id] ,[nm] ,[addr] ,[fdbck_cntn], "); 40 strSql.Append("[last_upd_dtm] ,[iss_sts] ,[fdbck_cntn_remark]) "); 41 strSql.AppendFormat("VALUES ('{0}','{1}','{2}','{3}',", item.stor_id, CheckStr(item.stor_nm), CheckStr(item.stor_addr), CheckStr(item.fwFeedBackConter)); 42 strSql.AppendFormat("'{0}','{1}','{2}' ) ", JsonDateString(item.fwFeedBackDate), item.isSeccess, CheckStr(item.FwFeedBackRemark)); 43 } 44 45 // GetLOEM(LOEM暗访) 46 jsonText = client.GetLOEM().ToString(); 47 a = JsonDeserialize<List<dsStore>>(jsonText); 48 49 foreach (dsStore item in a) 50 { 51 strSql.Append("INSERT INTO msp_stor_fdbck "); 52 strSql.Append("([stor_id] ,[nm] ,[addr] ,[fdbck_cntn], "); 53 strSql.Append("[last_upd_dtm] ,[iss_sts] ,[fdbck_cntn_remark]) "); 54 strSql.AppendFormat("VALUES ('{0}','{1}','{2}','{3}',", item.stor_id, CheckStr(item.stor_nm), CheckStr(item.stor_addr), CheckStr(item.fwFeedBackConter)); 55 strSql.AppendFormat("'{0}','{1}','{2}' ) ", JsonDateString(item.fwFeedBackDate), item.isSeccess, CheckStr(item.FwFeedBackRemark)); 56 } 57 58 // GetLOEMMing(LOEM明访) 59 jsonText = client.GetLOEMMing().ToString(); 60 a = JsonDeserialize<List<dsStore>>(jsonText); 61 62 foreach (dsStore item in a) 63 { 64 strSql.Append("INSERT INTO msp_stor_fdbck "); 65 strSql.Append("([stor_id] ,[nm] ,[addr] ,[fdbck_cntn], "); 66 strSql.Append("[last_upd_dtm] ,[iss_sts] ,[fdbck_cntn_remark]) "); 67 strSql.AppendFormat("VALUES ('{0}','{1}','{2}','{3}',", item.stor_id, CheckStr(item.stor_nm), CheckStr(item.stor_addr), CheckStr(item.fwFeedBackConter)); 68 strSql.AppendFormat("'{0}','{1}','{2}' ) ", JsonDateString(item.fwFeedBackDate), item.isSeccess, CheckStr(item.FwFeedBackRemark)); 69 } 70 71 // GetMNC(MNC暗访) 72 jsonText = client.GetMNC().ToString(); 73 a = JsonDeserialize<List<dsStore>>(jsonText); 74 75 foreach (dsStore item in a) 76 { 77 strSql.Append("INSERT INTO msp_stor_fdbck "); 78 strSql.Append("([stor_id] ,[nm] ,[addr] ,[fdbck_cntn], "); 79 strSql.Append("[last_upd_dtm] ,[iss_sts] ,[fdbck_cntn_remark]) "); 80 strSql.AppendFormat("VALUES ('{0}','{1}','{2}','{3}',", item.stor_id, CheckStr(item.stor_nm), CheckStr(item.stor_addr), CheckStr(item.fwFeedBackConter)); 81 strSql.AppendFormat("'{0}','{1}','{2}' ) ", JsonDateString(item.fwFeedBackDate), item.isSeccess, CheckStr(item.FwFeedBackRemark)); 82 } 83 84 // GetMNCMing(MNC明访) 85 jsonText = client.GetMNCMing().ToString(); 86 a = JsonDeserialize<List<dsStore>>(jsonText); 87 88 foreach (dsStore item in a) 89 { 90 strSql.Append("INSERT INTO msp_stor_fdbck "); 91 strSql.Append("([stor_id] ,[nm] ,[addr] ,[fdbck_cntn], "); 92 strSql.Append("[last_upd_dtm] ,[iss_sts] ,[fdbck_cntn_remark]) "); 93 strSql.AppendFormat("VALUES ('{0}','{1}','{2}','{3}',", item.stor_id, CheckStr(item.stor_nm), CheckStr(item.stor_addr), CheckStr(item.fwFeedBackConter)); 94 strSql.AppendFormat("'{0}','{1}','{2}' ) ", JsonDateString(item.fwFeedBackDate), item.isSeccess, CheckStr(item.FwFeedBackRemark)); 95 } 96 97 // GetMRMing(MR) 98 jsonText = client.GetMRMing().ToString(); 99 100 b = JsonDeserialize<List<dsMR>>(jsonText); 101 102 foreach (dsMR item in b) 103 { 104 strSql.Append("INSERT INTO msp_stor_fdbck "); 105 strSql.Append("([gid_num] ,[nm] ,[addr] ,[fdbck_cntn], "); 106 strSql.Append("[last_upd_dtm] ,[iss_sts] ,[fdbck_cntn_remark]) "); 107 strSql.AppendFormat("VALUES ('{0}','{1}','{2}','{3}',", item.gid_num, CheckStr(item.co_nm), CheckStr(item.co_addr), item.type); 108 strSql.AppendFormat("'{0}','{1}','{2}' ) ", JsonDateString(item.fwFeedBackDate), item.isSeccess, CheckStr(item.FwFeedBackRemark)); 109 } 110 111 commandText = strSql.ToString(); 112 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ToString()); 113 114 con.Open(); 115 SqlTransaction tran = con.BeginTransaction(); 116 try 117 { 118 SqlHelper.ExecuteNonQuery(tran, System.Data.CommandType.Text, commandText, null); 119 tran.Commit(); 120 } 121 catch 122 { 123 tran.Rollback(); 124 } 125 finally 126 { 127 con.Close(); 128 } 129 130 } 131 catch 132 { 133 string ex = ""; 134 } 135 136 client.Close(); 137 } 138 } 139
//静态方法 140 public static T JsonDeserialize<T>(string jsonText) 141 { 142 JavaScriptSerializer jss = new JavaScriptSerializer(); 143 return jss.Deserialize<T>(jsonText); 144 } 145 //静态方法 146 public static string JsonDateString(string jsonDate) 147 { 148 return jsonDate.Substring(0, 19); 149 } 150 151 152 public static DateTime JsonToDateTime(string jsonDate) 153 { 154 string value = jsonDate.Substring(6, jsonDate.Length - 8); 155 DateTimeKind kind = DateTimeKind.Utc; 156 int index = value.IndexOf('+', 1); 157 if (index == -1) index = value.IndexOf('-', 1); 158 if (index != -1) { kind = DateTimeKind.Local; value = value.Substring(0, index); } 159 long javaScriptTicks = long.Parse(value, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture); 160 long InitialJavaScriptDateTicks = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks; 161 DateTime utcDateTime = new DateTime((javaScriptTicks * 10000) + InitialJavaScriptDateTicks, DateTimeKind.Utc); 162 DateTime dateTime; 163 switch (kind) 164 { 165 case DateTimeKind.Unspecified: dateTime = DateTime.SpecifyKind(utcDateTime.ToLocalTime(), DateTimeKind.Unspecified); break; 166 case DateTimeKind.Local: 167 dateTime = utcDateTime.ToLocalTime(); break; 168 default: dateTime = utcDateTime; break; 169 } 170 return dateTime; 171 } 172 173 public static string CheckStr(string str) 174 { 175 string returnStr = ""; 176 if (str != null) 177 { 178 if (str.IndexOf("'") != -1) //判断字符串是否含有单引号 179 { 180 returnStr = str.Replace("'", "''"); 181 str = returnStr; 182 } 183 } 184 return str; 185 } 186 } 187 //创建Class对象,get set 设定获取对象的属性值 188 class dsStore 189 { 190 public int stor_id { get; set; } 191 192 public string stor_nm { get; set; } 193 194 public string stor_addr { get; set; } 195 196 public string fwFeedBackConter { get; set; } 197 198 public string fwFeedBackDate { get; set; } 199 200 public string FwFeedBackRemark { get; set; } 201 202 public string type { get; set; } 203 204 public string isSeccess { get; set; } 205 } 206 207 class dsMR 208 { 209 public int gid_num { get; set; } 210 211 public string co_nm { get; set; } 212 213 public string co_addr { get; set; } 214 215 public string fwFeedBackDate { get; set; } 216 217 public string FwFeedBackRemark { get; set; } 218 219 public string type { get; set; } 220 221 public string isSeccess { get; set; } 222 } 223 }