Beispiel #1
0
        private async void RoomButton_Click(object sender, RoutedEventArgs e)
        {
            ElectricityByRoomNum electricityData = new ElectricityByRoomNum();

            if (roomSettings.Values.ContainsKey("building") && roomSettings.Values.ContainsKey("room"))
            {
                paramList.Add(new KeyValuePair <string, string>("building", roomSettings.Values["building"].ToString()));
                paramList.Add(new KeyValuePair <string, string>("room", roomSettings.Values["room"].ToString()));
                //储存ElectricityByStuNum数据的实例
                string electricityJson = await netWork.GetElectricityByRoomNum(byRoomNumUri, paramList);

                electricityData = netWork.ByRoomNumStringConvertToModel(electricityJson);
            }
            //输入错误弹窗
            if (ComboBox.SelectedItem == null || RoomTextBox.Text.ToString().Length != 3 || electricityData.elec_inf.elec_spend == null)
            {
                var msgPopup = new MessagePopup(); //MessagePop构造方法可传string型参数作为弹窗的提示
                msgPopup.ShowWindow();
            }
            else
            {
                roomSettings.Values["isBindingRoom"]   = true;
                roomSettings.Values["BindingRoomDate"] = DateTime.Now.ToString();
                this.Frame.Navigate(typeof(SettedPage)); //设置成功之后跳转的成功画面 @Boss Qin检查下
            }
        }
Beispiel #2
0
        public async void IniData()//使用学号查询电费接口初始化数据
        {
            if (bool.Parse(settings.Values["isBindingRoom"].ToString()))
            {
                try
                {
                    paramList.Add(new KeyValuePair <string, string>("building", settings.Values["building"].ToString()));
                    paramList.Add(new KeyValuePair <string, string>("room", settings.Values["room"].ToString()));
                    //储存ElectricityByStuNum数据的实例
                    string electricityJson = await netWork.GetElectricityByRoomNum(byRoomNumUri, paramList);

                    ElectricityByRoomNum electricityData = new ElectricityByRoomNum();
                    electricityData = netWork.ByRoomNumStringConvertToModel(electricityJson);
                    //本月电费消费
                    string elec_Cost = electricityData.elec_inf.elec_cost[0] + "." + electricityData.elec_inf.elec_cost[1];//Cost数组转为String
                    electricityData.elec_inf.elec_perday = elec_Cost;
                    //百分比
                    if (!settings.Values.ContainsKey("limitCharge"))
                    {
                        settings.Values["limitCharge"] = 20;
                    }
                    electricityData.elec_inf.elec_percent = (double.Parse(elec_Cost) / double.Parse(settings.Values["limitCharge"].ToString()) * 100);
                    dialPlate.Percent = electricityData.elec_inf.elec_percent;
                    //电费余额
                    electricityData.elec_inf.elec_chargeBalance = (int.Parse(electricityData.elec_inf.elec_end) - int.Parse(electricityData.elec_inf.elec_start)).ToString();
                    this.dialPlate.BalanceProperty = electricityData.elec_inf.elec_chargeBalance;
                    //电量剩余度数
                    electricityData.elec_inf.elec_dumpEnergy = (30 - (int.Parse(electricityData.elec_inf.elec_end) - int.Parse(electricityData.elec_inf.elec_start))).ToString();
                    this.dialPlate.DumpEnergyProperty        = electricityData.elec_inf.elec_dumpEnergy;
                    //设置数据源
                    this.DataContext = electricityData.elec_inf;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
            else
            {
                try
                {
                    //储存ElectricityByStuNum数据的实例
                    string electricityIniJson = await netWork.GetElectricityByStuNum(byStuNumUri, paramIniList);

                    ElectricityByStuNum electricityIniData = new ElectricityByStuNum();
                    electricityIniData = netWork.ByStuNumStringConvertToModel(electricityIniJson);
                    //本月电费消费
                    string elec_Cost = electricityIniData.data.result.current.elec_cost[0] + "." + electricityIniData.data.result.current.elec_cost[1];//Cost数组转为String
                    electricityIniData.data.result.current.elec_perday = elec_Cost;
                    //百分比
                    if (!settings.Values.ContainsKey("limitCharge"))
                    {
                        settings.Values["limitCharge"] = 20;
                    }
                    electricityIniData.data.result.current.elec_percent = (double.Parse(elec_Cost) / double.Parse(settings.Values["limitCharge"].ToString()) * 100);
                    dialPlate.Percent = electricityIniData.data.result.current.elec_percent;
                    //电费余额
                    electricityIniData.data.result.current.elec_chargeBalance = (int.Parse(electricityIniData.data.result.current.elec_end) - int.Parse(electricityIniData.data.result.current.elec_start)).ToString();
                    this.dialPlate.BalanceProperty = electricityIniData.data.result.current.elec_chargeBalance;
                    //电量剩余度数
                    electricityIniData.data.result.current.elec_dumpEnergy = (30 - (int.Parse(electricityIniData.data.result.current.elec_end) - int.Parse(electricityIniData.data.result.current.elec_start))).ToString();
                    this.dialPlate.DumpEnergyProperty = electricityIniData.data.result.current.elec_dumpEnergy;
                    //设置数据源
                    this.DataContext = electricityIniData.data.result.current;
                    Debug.WriteLine(this.dialPlate.DumpEnergyProperty);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
Beispiel #3
0
        public ElectricityByRoomNum ByRoomNumStringConvertToModel(string str)
        {
            ElectricityByRoomNum electricityRootobject = JsonConvert.DeserializeObject <ElectricityByRoomNum>(str);

            return(electricityRootobject);
        }