WinParameter.xaml.cs 5.54 KB
using RCS.Dal;
using RCS.Model.Entity;
using RCS.WinClient.Common;
using System.Windows;
using System.Windows.Input;

namespace RCS.WinClient.Views.Pages
{
    /// <summary>
    /// WinTest.xaml 的交互逻辑
    /// </summary>
    public partial class WinParameter : Window
    {
        public WinParameter()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Init.DownKeyValue();
            DGrid_KeyValue.ItemsSource = App.Config_KeyValueDic.Values.ToList();
        }

        private void BtnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        //重写Closing方法
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }

        private void Btn_OK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                foreach (var keyValue in App.Config_KeyValueDic.Values)
                {
                    if (!float.TryParse(keyValue.Value, out float doubleValue))
                    {
                        ComnMethod.Message($"参数变量【{keyValue}】的值必须是 数值类型 !");
                        return;
                    }
                    keyValue.DoubleValue = doubleValue;
                }
                BaseDal<Config_KeyValue> _configDb = new BaseDal<Config_KeyValue>();
                //除了流水号不更新,其他都更新
                var keyValues = App.Config_KeyValueDic.Values.Where(t => t.KeyVariable != "Tno").ToArray();
                var updateResult = _configDb.Update(keyValues);

                if (updateResult.IsSuccess)
                {
                    ComnMethod.Message("保存参数成功!");
                }
                else
                {
                    ComnMethod.Message($"保存参数失败!原因:{updateResult.Message}");
                }

                //if (!float.TryParse(Tbox_FullCharge.Text, out float fullCharge))
                //{
                //    ComnMethod.Message("满电量必须是 数值类型 !");
                //    return;
                //}
                //if (!float.TryParse(Tbox_SafeCharge.Text, out float safeCharge))
                //{
                //    ComnMethod.Message("安全电量必须是 数值类型 !");
                //    return;
                //}
                //if (!float.TryParse(Tbox_DangerCharge.Text, out float dangerCharge))
                //{
                //    ComnMethod.Message("危险电量必须是 数值类型 !");
                //    return;
                //}
                //if (!float.TryParse(Tbox_MinCharges.Text, out float minCharges))
                //{
                //    ComnMethod.Message("最少充电量必须是 数值类型 !");
                //    return;
                //}
                //if (!float.TryParse(Tbox_MinTime.Text, out float minTime))
                //{
                //    ComnMethod.Message("最少充电时间必须是 数值类型 !");
                //    return;
                //}
                //App.FullCharge = fullCharge;
                //App.SafeCharge = safeCharge;
                //App.DangerCharge = dangerCharge;
                //App.MinCharges = minCharges;
                //App.MinTime = minTime;

                //var updateresult1 = _configDb.Update(it => it.KeyVariable == "Cfull", it => new Config_KeyValue()
                //{
                //    Value = Tbox_FullCharge.Text,
                //});
                //var updateresult2 = _configDb.Update(it => it.KeyVariable == "Savety", it => new Config_KeyValue()
                //{
                //    Value = Tbox_SafeCharge.Text,
                //});
                //var updateresult3 = _configDb.Update(it => it.KeyVariable == "Danger", it => new Config_KeyValue()
                //{
                //    Value = Tbox_DangerCharge.Text,
                //});
                //var updateresult4 = _configDb.Update(it => it.KeyVariable == "MinCharges", it => new Config_KeyValue()
                //{
                //    Value = Tbox_MinCharges.Text,
                //});
                //var updateresult5 = _configDb.Update(it => it.KeyVariable == "MinTime", it => new Config_KeyValue()
                //{
                //    Value = Tbox_MinTime.Text,
                //});

                //if (updateresult1.Success && updateresult2.Success && updateresult3.Success && updateresult4.Success && updateresult5.Success)
                //{
                //    ComnMethod.Message("保存参数成功!");
                //}
                //else
                //{
                //    var msg = "保存参数失败!原因:";
                //    if (!updateresult1.Success)     msg += "  " + updateresult1.Msg;
                //    if (!updateresult2.Success)     msg += "  " + updateresult2.Msg;
                //    if (!updateresult3.Success)     msg += "  " + updateresult3.Msg;
                //    if (!updateresult4.Success)     msg += "  " + updateresult4.Msg;
                //    if (!updateresult5.Success)     msg += "  " + updateresult5.Msg;
                //    ComnMethod.Message(msg);
                //}


            }
            catch (Exception Ex)
            {
                ComnMethod.Message(Ex.ToString());
            }
        }



    }
}