|
@@ -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 = 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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+
|
|
|
+ loopstring.Add(item.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+
|
|
|
+
|
|
|
+ Type t = onescvdata.GetType();
|
|
|
+ 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>();
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ readSCV(url, xianlu, chezhan, ref gonglvCsvdata);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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 = "";
|
|
|
}
|
|
|
}
|
|
|
}
|