123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Uninpho.DBOperation.Model;
- using Uninpho.DBOperation.Operation;
- using System.IO;
- using DevExpress.XtraEditors;
- using DevExpress.XtraGrid.Views.Grid;
- using DevExpress.XtraGrid;
- using DevExpress.XtraBars;
- namespace Uninpho.Tools.components.DataAnalysis
- {
-
- class DWQKCommon
- {
-
- public static string lj;
- public static List<T_dwqkfile_account> filelist = new List<T_dwqkfile_account>();
- /// <summary>
- /// 打开文件夹公共函数
- /// </summary>
- public static void OpenFile(string houzhui,GridView GV,string xianluming, string chezhan)
- {
-
-
- var dialog = new OpenFileDialog();
- dialog.Multiselect = true;
- dialog.Title = "请选择文件夹";
- dialog.Filter = houzhui+"文件(*." + houzhui + ")|*." + houzhui;
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- string[] file = dialog.FileNames;
- for (int i = 0; i < file.Length; i++)
- {
- T_dwqkfile_account tfa = GLFileNameSplit1(file[i], xianluming, chezhan);
- //获取数据后
- var isfile = DataAnalysisToPG.DWQKQueryToPGByNameFile(tfa.Filename) as List<T_dwqkfile_account>;
- lj = file[i]; //传路径
- if (isfile.Count == 0)
- {
- filelist.Add(tfa);
- }
- else
- {
- if (XtraMessageBox.Show("检测到数据库内存在同名数据:\n" + tfa.Filename + ",\n是否覆盖数据库内数据?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
- {
- filejiancedel(tfa);
- filelist.Add(tfa);
- }
- }
- }
-
- }
-
- }
- public static void AddFile()
- {
- DataAnalysisToPG.QKInsertToPG(filelist);
- filelist.Clear();
- }
- public static void CancelAddFile()
- {
- filelist.Clear();
- }
- /// 清理数据库同名数据
- private static void filejiancedel(T_dwqkfile_account file)
- {
-
-
- DataAnalysisToPG.DelToDWQK(file);//清除功率表
-
- }
- /// 解析电务功率数据
- private static T_dwqkfile_account GLFileNameSplit1(string filename,string xianluming, string chezhan)
- {
- string ysname = Path.GetFileName(filename);
- string wjdx = Math.Round((new FileInfo(filename).Length / 1024.0 / 1024.0),2) + " MB";//文件大小
- string lj = filename;//路径
- string minStartTime = null;//日期
- string maxStartTime = null;
- //解析文件
- using (StreamReader reader = new StreamReader(filename))
- {
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- string[] parts = line.Split('$');
- if (parts.Length >= 9)
- {
-
-
- string caijikaishishijian = parts[2];//采集开始时间
-
- DateTime startTime;
- if (DateTime.TryParseExact(caijikaishishijian, "yyyy-MM-dd HH:mm:ss", null, System.Globalization.DateTimeStyles.None, out startTime))
- {
- string formattedStartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
- if (minStartTime == null || string.Compare(formattedStartTime, minStartTime) < 0)
- {
- minStartTime = formattedStartTime;
- }
- if (maxStartTime == null || string.Compare(formattedStartTime, maxStartTime) > 0)
- {
- maxStartTime = formattedStartTime;
- }
- }
- }
- }
- }
- return new T_dwqkfile_account()
- {
- //下次把车站线路写活
- Xianlu = xianluming,
- Chezhan = chezhan,
- Starttime = minStartTime,
- Endtime = maxStartTime,
- Filename = ysname,
- Filesize = wjdx,
- Filestatus = "正常",
- Taskstatus = "算法未执行",
- Srlj = lj,
-
- };
- }
-
-
- /// <summary>
- /// 刷新后恢复选中
- /// </summary>
- /// <param name="gv"></param>
- /// <param name="selectid"></param>
- public static void repushSFZT(GridView gv,List<int> selectid)
- {
- for (int i = 0; i < gv.RowCount; i++)
- {
- for (int j = 0; j < selectid.Count; j++)
- {
- if (gv.GetRowCellValue(i, "Id").ToString() == selectid[j].ToString())
- {
- gv.SelectRow(i);
- break;
- }
- }
- }
- }
- /// <summary>
- /// 获取刷新前id和状态
- /// </summary>
- /// <param name="gv"></param>
- /// <param name="selectid"></param>
- /// <param name="selectrowzt"></param>
- public static void getSFZT(GridView gv,ref List<int> selectid,ref List<string> selectrowzt)
- {
- var sele = gv.GetSelectedRows();
- foreach (var i in sele)
- {
- selectid.Add(Convert.ToInt32(gv.GetRowCellValue(i, "Id").ToString()));
- selectrowzt.Add(gv.GetRowCellValue(i, "Taskstatus").ToString());
- }
- }
- }
- }
|