private void saveButton_Click(object sender, RoutedEventArgs e) { ui_handBusy.IsBusy = true; string json = "["; BaseObjectList list = daninfos.ItemsSource as BaseObjectList; List <GeneralObject> removed = new List <GeneralObject>(); //对于每一条记录 foreach (GeneralObject go in list) { // 抄表记录里的上期指数 var lastinputnum = go.GetPropertyValue("lastinputgasnum"); // 本次抄表指数 var lastrecord = go.GetPropertyValue("lastrecord"); //卡表剩余水量 var f_leftgas = go.GetPropertyValue("f_leftgas"); // 本次指数为空,这条不上传 if (lastrecord == null) { continue; } // 本期指数小于上期指数,不上传 if (double.Parse(lastrecord.ToString()) < double.Parse(lastinputnum.ToString())) { continue; } // 从列表中去除 removed.Add(go); //已经有项目,加逗号区分 if (json != "[") { json += ','; } //产生要发送后台的JSON串 json += ("{userid:" + go.GetPropertyValue("f_userid") + ",lastreading:" + lastinputnum + ",reading:" + lastrecord + ",leftgas:" + f_leftgas + ",meterstate:" + meterstate + "}"); } json += "]"; foreach (GeneralObject go in removed) { list.Remove(go); } //将产生的json串送后台服务进行处理 WebClientInfo wci = Application.Current.Resources["server"] as WebClientInfo; string uri = wci.BaseAddress + "/handcharge/record/batch/" + ui_handdate.SelectedDate + "/" + ui_sgnetwork.Text + "/" + ui_sgoperator.Text + "/" + chaobiaoriqi.SelectedDate + "/" + meter.SelectedValue.ToString() + "?uuid=" + System.Guid.NewGuid().ToString(); WebClient client = new WebClient(); client.UploadStringCompleted += client_UploadStringCompleted; client.UploadStringAsync(new Uri(uri), json); }
private void saveButton_Click(object sender, RoutedEventArgs e) { ui_handBusy.IsBusy = true; BaseObjectList list = daninfos.ItemsSource as BaseObjectList; List <GeneralObject> removed = new List <GeneralObject>(); //对于每一条记录 foreach (GeneralObject go in list) { //表具编号 var userid = go.GetPropertyValue("f_userid"); //抄表id var id = go.GetPropertyValue("id"); // 抄表记录里的上期指数 var lastinputnum = go.GetPropertyValue("lastinputgasnum"); // 本次抄表指数 var lastrecord = go.GetPropertyValue("lastrecord"); // 抄表记录里的阶梯类型 var stairType = go.GetPropertyValue("f_stairtype"); // 用水量 var oughtamount = go.GetPropertyValue("oughtamount"); // 本次指数为空,这条不上传 if (lastrecord == null) { continue; } // 本期指数小于上期指数,不上传 if (double.Parse(lastrecord.ToString()) < double.Parse(lastinputnum.ToString())) { MessageBox.Show("表" + userid + "本期指数异常,请核查"); continue; } removed.Add(go); string sql = "update t_handplan set lastrecord=" + lastrecord + ",f_state= '" + "待审核" + "',oughtamount= " + oughtamount + " where id=" + id; HQLAction action = new HQLAction(); action.HQL = sql; action.WebClientInfo = Application.Current.Resources["dbclient"] as WebClientInfo; action.Name = "t_handplan"; action.Completed += action_Completed; action.Invoke(); } foreach (GeneralObject go in removed) { list.Remove(go); } }