private string UpdateGtOne(ps_gt data) { PS_gt gt = Ebada.Client.ClientHelper.PlatformSqlMap.GetOne<PS_gt>(string.Format("where gtCode='{0}'",data.gtCode)); if (gt != null) { //foreach(FieldInfo fi in data.GetType().GetFields()){ // try { // gt.GetType().GetProperty(fi.Name).SetValue(gt, fi.GetValue(data), null); // } catch { } //} gt.gtType = data.gtType; gt.gtModle = data.gtModle; gt.gtElev = (int)decimal.Parse(data.gtElev); gt.gtLat = decimal.Parse(data.gtLat); gt.gtLon = decimal.Parse(data.gtLon); gt.gtHeight = decimal.Parse(data.gtHeight); gt.gtJg = data.gtSpan == "是" ? "是" : "否";//借杆 if ((gt.gtLat + gt.gtLon) > 0) { int n = Ebada.Client.ClientHelper.PlatformSqlMap.Update<PS_gt>(gt); upCount += n; } if (data.jsonData != null) { //Console.WriteLine(data.jsonData); List<ps_gtsb> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ps_gtsb>>(data.jsonData); if (list != null && list.Count>0) { List<SqlQueryObject> sqllist = new List<SqlQueryObject>(); SqlQueryObject sqo = new SqlQueryObject(SqlQueryType.Delete, "Delete", "delete from ps_gtsb where gtid='" + gt.gtID + "'"); sqllist.Add(sqo); int num = 0; foreach (ps_gtsb sb in list) { num++; PS_gtsb gtsb = new PS_gtsb() { gtID = gt.gtID, sbModle = sb.xh, sbType = sb.zldm, sbNumber = short.Parse(sb.sl), sbName = sb.zl, sbCode = num.ToString("000") }; gtsb.sbID = gt.gtID + num.ToString("000"); sqo = new SqlQueryObject(SqlQueryType.Insert, gtsb); sqllist.Add(sqo); } Client.ClientHelper.PlatformSqlMap.ExecuteTransationUpdate(sqllist); } //Console.WriteLine(list != null ? list.Count : 0); } //Console.WriteLine("update {0} count {1}", gt.gtCode, n); } return ""; }
private void upload() { DataTable dt = SqliteHelper.ExecuteDataTable("select * from ps_xl"); string str = "开始上传数据:"; writeLine(str); str = "{0} {1} ,杆塔数:{2},实际上传数:{3}"; int n1=0, n2=0; List<ps_gt> uplist = new List<ps_gt>(); upCount = 0; foreach (DataRow row in dt.Rows) { string linecode = row["linecode"].ToString(); DataTable dt2 = SqliteHelper.ExecuteDataTable("select * from ps_gt where linecode='"+linecode+"'"); n1 = dt2.Rows.Count; string ret="0"; int n3 = 0; foreach (DataRow row2 in dt2.Rows) { ps_gt gt = new ps_gt(); foreach (FieldInfo fi in gt.GetType().GetFields()) { try { fi.SetValue(gt, row2[fi.Name]); } catch { } } if (gt.gtLat == "0" || gt.gtLon == "0") continue; //uplist.Add(gt); try { UpdateGtOne(gt); n3++; } catch { } } n2++; //if (uplist.Count > 0) { // ret = uploadgt(uplist); // uplist.Clear(); //} writeLine(string.Format(str, n2, row["linename"], n1, n3)); Application.DoEvents(); //if (ret.Contains("(")) break; } writeLine(string.Format("共更新杆塔数:{0}", upCount)); }