Browse Source

feat:导入功能第一版

mux 4 months ago
parent
commit
1225f09ef6

+ 5 - 2
DPTools/components/DWForm/ImportGLdataForm.Designer.cs

@@ -70,6 +70,7 @@
             new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
             this.xianlumingText.Size = new System.Drawing.Size(345, 24);
             this.xianlumingText.TabIndex = 3;
+            this.xianlumingText.EditValueChanged += new System.EventHandler(this.xianlumingText_TextChanged);
             this.xianlumingText.SelectedIndexChanged += new System.EventHandler(this.xianlumingText_SelectedIndexChanged);
             // 
             // zhanmingText
@@ -92,6 +93,7 @@
             this.NewcancelBtn.Size = new System.Drawing.Size(73, 28);
             this.NewcancelBtn.TabIndex = 7;
             this.NewcancelBtn.Text = "取消";
+            this.NewcancelBtn.Click += new System.EventHandler(this.NewcancelBtn_Click);
             // 
             // newCreateBtnSon
             // 
@@ -100,13 +102,13 @@
             this.newCreateBtnSon.Name = "newCreateBtnSon";
             this.newCreateBtnSon.Size = new System.Drawing.Size(73, 28);
             this.newCreateBtnSon.TabIndex = 8;
-            this.newCreateBtnSon.Text = "新建";
+            this.newCreateBtnSon.Text = "导入";
             this.newCreateBtnSon.Click += new System.EventHandler(this.newCreateBtnSon_Click);
             // 
             // simpleButton2
             // 
             this.simpleButton2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.simpleButton2.Location = new System.Drawing.Point(394, 152);
+            this.simpleButton2.Location = new System.Drawing.Point(395, 153);
             this.simpleButton2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
             this.simpleButton2.Name = "simpleButton2";
             this.simpleButton2.Size = new System.Drawing.Size(86, 30);
@@ -153,6 +155,7 @@
             this.MinimizeBox = false;
             this.Name = "ImportGLdataForm";
             this.Text = "导入功率配置文件";
+            this.Load += new System.EventHandler(this.ImportGLdataForm_Load);
             ((System.ComponentModel.ISupportInitialize)(this.xianlumingText.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.zhanmingText.Properties)).EndInit();
             this.ResumeLayout(false);

+ 196 - 0
DPTools/components/DWForm/ImportGLdataForm.cs

@@ -8,6 +8,11 @@ using System.Linq;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using DevExpress.XtraEditors;
+using Uninpho.DBOperation.Model;
+using System.IO;
+using Uninpho.DBOperation.Operation;
+using System.Text.RegularExpressions;
+using System.Reflection;
 
 namespace Uninpho.Tools.components.DWForm
 {
@@ -55,12 +60,203 @@ namespace Uninpho.Tools.components.DWForm
 
         private void simpleButton2_Click(object sender, EventArgs e)
         {
+            // 创建一个OpenFileDialog实例  
+            OpenFileDialog openFileDialog = new OpenFileDialog
+            {
+                // 设置文件对话框的标题  
+                Title = "选择文件",
 
+                // 初始目录,可选  
+                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
+
+                // 设置过滤条件,只显示文本文件,可以根据需要修改  
+                Filter = "所有文件 (*.*)|*.*"
+            };
+
+            // 显示文件对话框并检查用户是否选择了文件  
+            if (openFileDialog.ShowDialog() == DialogResult.OK)
+            {
+                // 将选择的文件路径写入文本框  
+                txtindir.Text = openFileDialog.FileName;
+            }
         }
 
         private void newCreateBtnSon_Click(object sender, EventArgs e)
         {
+            saveData2PG(txtindir.Text, xianlumingText.Text, zhanmingText.Text);
+            //打开表格数据转成实体类
+            //if (TZCommonFunc.GetTabledata(TableName.T_gonglv_account))
+            //{
+                //插入数据
+               // SqlQueryable_QX.Insertdata_GL(TZCommonFunc.Listdata_gl);
+               // this.data_binding();
+           // }
+        }
+
+
+        /// <summary>
+        /// メソッド概要 取文件的编码格式
+        /// </summary>
+        /// <remarks>
+        /// 機能仕様 取文件的编码格式
+        /// </remarks>
+        public static Encoding GetEncoding(string filePath)
+        {
+            using (var reader = new StreamReader(filePath, Encoding.Default, true))
+            {
+                if (reader.Peek() >= 0)
+                {
+                    reader.Read();
+                }
+
+                Encoding encoding = reader.CurrentEncoding;
+                reader.Close();
+                return encoding;
+            }
+        }
+
+        /// <summary>
+        /// 读scv
+        /// </summary>
+        /// <param name="url"></param>
+        private static void readSCV(string url, string xianlu, string chezhan, ref List<T_gonglv_account> gonglvCsvdata)
+        {
+            StreamReader sr = new StreamReader(url, GetEncoding(url));
+            sr.ReadLine();
+            sr.ReadLine();
+            while (!sr.EndOfStream)
+            {
+                string origonss = sr.ReadLine();
+                origonss = origonss.Replace("  ", " ");
+                origonss = origonss.Replace("/t", ",");
+                origonss = origonss.Replace(" ", ",");
+                var arrayarr = origonss.ToCharArray();
+                if (arrayarr[0] == ',' && arrayarr[1] == ',')
+                {
+                    //简单判断这行是否是多余,例如“,,,,,,,,,,,,,,,,”这种行的录入
+                    continue;
+                }
+                T_gonglv_account onescvdata = new T_gonglv_account();
+                onescvdata.Chezhan = chezhan;
+                onescvdata.Xianlu = xianlu;
+                onescvdata.Qxxh = arrayarr[0].ToString();
+                onescvdata.Id = Guid.NewGuid().ToString(); 
+                List<string> loopstring = new List<string>();
+
+                //使用正则去除属性字段中的逗号的影响
+                Regex re = new Regex("(?<=,\").*?(?=\",)", RegexOptions.None);
+                MatchCollection mc = re.Matches(origonss);
+                //保存原始
+                foreach (var item in mc)
+                {
+                    //string ddd = item.ToString().Replace("\"\"", "\"");
+                    loopstring.Add(item.ToString());
+                }
+                //替换属性字段中的逗号为"$$$$$$$$$$$$$yxc$$$$$$$$$$$$$$$"
+                origonss = Regex.Replace(origonss, "(?<=,\").*?(?=\",)", "$$$$$$$$$$$$$yxc$$$$$$$$$$$$$$$");
+                string[] looparr = origonss.Split(',');
+                //还原之前被替换的字段属性值
+                int ii = 0;
+                for (int i = 0; i < looparr.Length; i++)
+                {
+                    if (looparr[i] == "\"$$$$$$$yxc$$$$$$$$\"")
+                    {
+                        looparr[i] = loopstring[ii++];
+                    }
+                }
+                ii = 0;
+                //存入T_xxxw_csvdata
+                //string[] propnames = new string[] { "Id", "Listid", "Cld", "Gzidh", "Nc", "Lc", "Gc", "Pmwz", "Spcg", "Gj", "Gddhdb", "Gddb", "Gddhcb", "Gdcb", "Gxdhdb", "Gxdb", "Gxdbcb", "Gxcb", "Dxg", "Zggc", "Yggc", "Zgpm", "Ygpm", "Sygc", "Sygddb", "Sygdcb", "Sypmwz", "Sygxdb", "Sygxcb", "Syspcg", "Sygj", "Fjzj", "Fjidh", "Fjsjcg", "Fjsccg", "Fjsjgj", "Fjscgj", "Fjsj5mgd", "Fjsc5mgd", "Fjsj150mgd", "Fjsc150mgd", "Fjsj5mgx", "Fjsc5mgx", "Fjsj150mgx", "Fjsc150mgx" };
+                Type t = onescvdata.GetType();//获得该类的Type
+                foreach (PropertyInfo pi in t.GetProperties())
+                {
+                    if (pi.Name != "Id" && pi.Name != "Qxxh" && pi.Name != "Xianlu" && pi.Name != "Chezhan")
+                    {
+                        pi.SetValue(onescvdata, looparr[ii++]);
+                    }
+                }
+                gonglvCsvdata.Add(onescvdata);
+            }
+            sr.Close();
+        }
+        static string uuid_ = string.Empty;//预防报错
+        public static string saveData2PG(string url, string xianlu, string chezhan)
+        {
+            string uuid = uuid_;
+            List<T_gonglv_account> gonglvCsvdata = new List<T_gonglv_account>();
+            //string[] filename = Path.GetFileNameWithoutExtension(url).Split('_');
+            try
+            {
+                readSCV(url, xianlu, chezhan, ref gonglvCsvdata);
+                //uuid = DataAnalysisToPG.Insertdata_gl_CsvList(new T_gonglv_account()
+                //{
+                //    Qxxh = filename[0],
+                //    Xianlu = xianlu,
+                //    Chezhan = chezhan,
+                //    Dcbh = filename[1],
+
+                //});
+                //foreach (var item in gonglvCsvdata)
+                //{
+                //    item.Id = uuid;
+                //}
+                DataAnalysisToPG.Insert_gl_data_CsvData(gonglvCsvdata);
+                XtraMessageBox.Show("导入成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
+
+            }
+            catch (Exception)
+            {
+                XtraMessageBox.Show("导入失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            }
+            return uuid;
+        }
+
+        private void NewcancelBtn_Click(object sender, EventArgs e)
+        {
+            this.Close();
+        }
+        List<T_daocha_account> daochaData = new List<T_daocha_account>();
+
+        /// <summary>
+        /// 加载模糊查询的数据
+        /// </summary>
+        private void ImportGLdataForm_Load(object sender, EventArgs e)
+        {
+            daochaData = DBOperation.Operation.DataAnalysisToPG.QueryDCTZALL();
+            //整理线路名集合
+            var listtgXLMALL = daochaData.GroupBy(c => c.Xlm).Select(c => c.First()).ToList();
+            foreach (var item in listtgXLMALL)
+            {
+                xianlumingText.Properties.Items.Add(item.Xlm);
+            }
+        }
+
 
+        /// <summary>
+        /// 线路名查询
+        /// </summary>
+        private void xianlumingText_TextChanged(object sender, EventArgs e)
+        {
+            zhanmingText.Properties.Items.Clear();
+            var isInputTrueXLM = daochaData.FindAll(delegate (T_daocha_account dc)
+            {
+                return dc.Xlm == xianlumingText.Text;
+            });
+            //线路名
+            if (isInputTrueXLM.Count != 0)
+            {
+                var listtg = isInputTrueXLM.GroupBy(c => c.Czm).Select(c => c.First()).ToList();
+                foreach (var item in listtg)
+                {
+                    zhanmingText.Properties.Items.Add(item.Czm);
+                }
+                zhanmingText.Enabled = true;
+            }
+            else
+            {
+                zhanmingText.Enabled = false;
+            }
+            zhanmingText.Text = "";
         }
     }
 }

+ 2 - 1
DPTools/components/TableName.cs

@@ -13,6 +13,7 @@ namespace Uninpho.Tools.components
         DC_Data = 2,
         GJ_Data = 4,
         T_xxxw_csvdata = 8,
-        T_xxxw_csvlist = 16
+        T_xxxw_csvlist = 16,
+        T_gonglv_account = 32
     }
 }

+ 18 - 0
Uninpho.DBOperation/Operation/DataAnalysisToPG.cs

@@ -159,6 +159,24 @@ namespace Uninpho.DBOperation.Operation
             db.Insertable(updateObjs).ExecuteCommand();//get change row count
             return db.Queryable<T_xxxw_csvlist>().Where(it => it.Jiancharen == updateObjs.Jiancharen && it.Jianchariqi == updateObjs.Jianchariqi).Single().Id;
         }
+
+        /// <summary>
+        /// 插入功率信息数据表
+        /// </summary>
+        /// <param name="listqx"></param>
+        public static void Insert_gl_data_CsvData(List<T_gonglv_account> gonglvCsvdata)
+        {
+            db.Insertable<T_gonglv_account>(gonglvCsvdata).ExecuteCommand();//get change row count
+        }
+        /// <summary>
+        /// 插入功率信息数据表
+        /// </summary>
+        /// <param name="listqx"></param>
+        public static string Insertdata_gl_CsvList(T_gonglv_account gonglvCsvdata)
+        {
+            db.Insertable(gonglvCsvdata).ExecuteCommand();//get change row count
+            return db.Queryable<T_gonglv_account>().Where(it => it.Chezhan == gonglvCsvdata.Chezhan).Single().Id;
+        }
         /// <summary>
         /// T_file_account表添加新数据
         /// </summary>

+ 9 - 0
Uninpho.DBOperation/Operation/SqlQueryable_QX.cs

@@ -58,6 +58,15 @@ namespace Uninpho.DBOperation.Operation
             return listqk;
         }
 
+        /// <summary>
+        /// 插入功率信息数据表
+        /// </summary>
+        /// <param name="listgj"></param>
+        public static void Insertdata_GL(List<T_gonglv_account> listgj)
+        {
+            db.Insertable<T_gonglv_account>(listgj).ExecuteCommand();//get change row count
+        }
+
         /// <summary>
         /// 插入曲线信息数据表
         /// </summary>