public static bool OutputJson(SummaryDataJson dataJson)
 {
     try
     {
         if (!Directory.Exists("./dataOutput/json"))
         {
             Directory.CreateDirectory("./dataOutput/json");
         }
         var dateTimeStr = dataJson.DateTime.ToString("yyyy-MM-dd_H-mm-ss");
         FilePath = "./dataOutput/json/" + dateTimeStr + "_OutData.json";
         var fileStream = new FileStream(FilePath, FileMode.CreateNew,
                                         FileAccess.Write);
         var json         = JsonConvert.SerializeObject(dataJson);
         var streamWriter = new StreamWriter(fileStream, Encoding.UTF8);
         streamWriter.Write(json);
         streamWriter.Close();
         return(true);
     }
     catch (IOException)
     {
         FilePath = "目标位置已存在同名文件, 请自行检查后再执行导出操作!";
         return(false);
     }
     catch (Exception ex)
     {
         FilePath = ex.Message + ":" + ex.StackTrace;
         return(false);
     }
 }
Ejemplo n.º 2
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            _dataJson = GetDataJson();
            if (_dataJson == null)
            {
                return;
            }

            var collectItems = _dataJson.PoleResult;
            var itemDisplays = new List <CollectedResult>();


            var items = dataGridElecmatrixShow.Items;

            collectItems.ForEach(pole =>
            {
                itemDisplays.Add(new CollectedResult(pole));
                var item = items[pole.A / 2] as DataRowView;
                item.Row[pole.B / 2 + 1] = Math.Round(pole.Elec, 2);
            });

            dataGridPoleResultShow.ItemsSource = itemDisplays;
            dataGridElecShow.ItemsSource       = _dataJson.ElecDetect;
            var dictionary = _dataJson.Preference;

            labelSumNum.Content        = dictionary["sumNum"];
            labelCompletedNum.Content  = dictionary["completedNum"];
            labelElecThreshold.Content = dictionary["elecThreshold"];
            try
            {
                labelEnabledPoleNum.Content = dictionary["enabledPoleNum"];
            }
            catch (KeyNotFoundException)
            {
                labelEnabledPoleNum.Content = dictionary["EnabledPoleNum"];
            }

            labelDatatime.Content = _dataJson.DateTime.ToString("G");
            labelUser.Content     = _dataJson.UserName;
            labelNote.Content     = _dataJson.Note;
        }
 public ProducePresenter SetDataJson(SummaryDataJson dataJson)
 {
     _dataJson = dataJson;
     return(this);
 }