You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
244 lines
9.3 KiB
244 lines
9.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Data;
|
|
using Stone.Entity;
|
|
using Gm_WMS.DataAccess.DataService;
|
|
using Stone.Common;
|
|
using System.IO;
|
|
|
|
namespace Stone.WinBiz.BasicData
|
|
{
|
|
public class F_Input : F_Base
|
|
{
|
|
public F_Input()
|
|
{
|
|
this.type = "Input";
|
|
this.name = "基础资料_数据导入";
|
|
this.entity = new Entity_t_Input();
|
|
this.entityView = new Entity_t_Input();
|
|
this.dateWhere = "[AddTime]>='{0}' and [AddTime]<='{1}'";
|
|
}
|
|
|
|
public override void GetView(DataGridView dgv)
|
|
{
|
|
base.GetView(dgv);
|
|
dgv.Columns["Self_bank_code"].HeaderText = "交易行";
|
|
dgv.Columns["Date"].HeaderText = "交易时间段";
|
|
dgv.Columns["RecordCount"].HeaderText = "交易笔数";
|
|
dgv.Columns["RecordAmount"].HeaderText = "交易金额合计";
|
|
dgv.Columns["FileName"].HeaderText = "文件名";
|
|
dgv.Columns["UserName"].HeaderText = "用户";
|
|
dgv.Columns["AddTime"].HeaderText = "导入时间";
|
|
|
|
}
|
|
|
|
public override void Checking(DataRow drData, bool isNew)
|
|
{
|
|
|
|
}
|
|
|
|
public override void Delete(int ID)
|
|
{
|
|
LocalDBService db = null;
|
|
try
|
|
{
|
|
db = new LocalDBService();
|
|
db.BeginTrans();
|
|
|
|
Entity_t_Input t_Input = new Entity_t_Input(db);
|
|
Entity_t_Data t_Data = new Entity_t_Data(db);
|
|
|
|
t_Input.Del($"[ID]={ID}");
|
|
t_Data.Del($"[InputID]={ID}");
|
|
|
|
|
|
db.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (db != null) db.Rollback();
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
if (db != null) db.EndTrans();
|
|
}
|
|
}
|
|
|
|
public void Input(string filename, string bankname)
|
|
{
|
|
LocalDBService db = null;
|
|
System.IO.StreamReader sr = null;
|
|
int n = 1;
|
|
try
|
|
{
|
|
db = new LocalDBService();
|
|
db.BeginTrans();
|
|
|
|
Entity_t_Input t_Input = new Entity_t_Input(db);
|
|
Entity_t_Data t_Data = new Entity_t_Data(db);
|
|
|
|
FileInfo file = new FileInfo(filename);
|
|
|
|
DataRow drInput = t_Input.Table.NewRow();
|
|
drInput["FileName"] = file.Name;
|
|
drInput["RecordCount"] = 0;
|
|
drInput["UserName"] = User.UserInfo.UserName;
|
|
drInput = t_Input.Add(drInput);
|
|
int InputID = Convert.ToInt32(drInput["ID"]);
|
|
|
|
sr = new System.IO.StreamReader(filename, Encoding.UTF8);
|
|
|
|
string line = "";
|
|
|
|
while ((line = sr.ReadLine()) != null)
|
|
{
|
|
if (line.Trim() == "") continue;
|
|
|
|
InputData(t_Data, InputID, line, n);
|
|
|
|
n++;
|
|
}
|
|
|
|
DataTable dtData = t_Data.GetData($"[InputID]={InputID}").Tables[0];
|
|
if (dtData.Rows.Count > 0)
|
|
{
|
|
string d1 = dtData.Compute("Max([Time])", "1=1").ToString();
|
|
string d2 = dtData.Compute("Min([Time])", "1=1").ToString();
|
|
decimal Org_amt = Convert.ToDecimal(dtData.Compute("Sum([Org_amt])", "1=1"));
|
|
|
|
|
|
drInput["Self_bank_code"] = bankname;
|
|
drInput["Date"] = d1 + "-" + d2;
|
|
drInput["RecordCount"] = n - 1;
|
|
drInput["RecordAmount"] = Org_amt;
|
|
|
|
t_Input.Edit(drInput);
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("导入的数据为空");
|
|
}
|
|
|
|
|
|
db.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (db != null) db.Rollback();
|
|
|
|
throw new Exception($"第{n}行导入失败,具体原因为:\r\n{ex.Message}");
|
|
}
|
|
finally
|
|
{
|
|
if (db != null) db.EndTrans();
|
|
if (sr != null) sr.Close();
|
|
}
|
|
}
|
|
|
|
private void InputData(Entity_t_Data t_Data, int InputID, string line, int n)
|
|
{
|
|
string[] sp = line.Split(',');
|
|
if (sp.Length != 37) throw new Exception($"字段个数不正确,请检查导入数据!");
|
|
|
|
DataRow drData = t_Data.Table.NewRow();
|
|
drData["InputID"] = InputID;
|
|
drData["Date"] = sp[0].Trim(); //1交易日期
|
|
drData["Time"] = sp[1].Trim(); //2交易时间
|
|
drData["Self_bank_code"] = GetChar(sp[2].Trim(), 20, "交易行代码"); //3
|
|
drData["Acc_type"] = GetChar(sp[3].Trim(), 2, "公私标识"); //4
|
|
drData["Cst_no"] = GetChar(sp[4].Trim(), 30, "客户号"); //5
|
|
drData["Id_no"] = GetChar(sp[5].Trim(), 50, "身份证件号码/社会信用统一代码/组织机构代码"); //6
|
|
drData["Self_acc_no"] = GetChar(sp[6].Trim(), 40, "账号"); //7
|
|
drData["Card_no"] = GetChar(sp[7].Trim(), 40, "卡号"); //8
|
|
drData["Self_acc_name"] = GetChar(sp[8].Trim(), 120, "账户名称");//9
|
|
drData["Part_bank_code"] = GetChar(sp[9].Trim(), 20, "交易对方行代码");//10
|
|
drData["Part_bank_name"] = GetChar(sp[10].Trim(), 120, "交易对方行名称");//11
|
|
drData["Part_acc_no"] = GetChar(sp[11].Trim(), 40, "交易对方账号(卡号)");//12
|
|
drData["Part_acc_name"] = GetChar(sp[12].Trim(), 120, "交易对方户名");//13
|
|
drData["Lend_flag"] = GetChar(sp[13].Trim(), 2, "资金收付标识");//14
|
|
drData["Tsf_flag"] = GetChar(sp[14].Trim(), 2, "现转标识");//15
|
|
drData["Cur"] = GetChar(sp[15].Trim(), 3, "币种");//16
|
|
drData["Org_amt"] = GetDecimal(sp[16].Trim(), "原币种交易金额");//17
|
|
drData["Usd_amt"] = GetDecimal(sp[17].Trim(), "外币折合美元交易金额");//18
|
|
drData["Balance"] = GetDecimal(sp[18].Trim(), "账户余额");//19
|
|
drData["Agency_flag"] = GetChar(sp[19].Trim(), 2, "代理交易标识");//20
|
|
drData["Agent_name"] = GetChar(sp[20].Trim(), 60, "代理人姓名");//21
|
|
drData["Agent_tel"] = GetChar(sp[21].Trim(), 60, "代理人联系方式");//22
|
|
drData["Agent_type"] = GetChar(sp[22].Trim(), 2, "代理人身份证件种类");//23
|
|
drData["Agent_no"] = GetChar(sp[23].Trim(), 50, "代理人身份证件号码");//24
|
|
drData["Ticd"] = GetChar(sp[24].Trim(), 40, "业务流水号");//25
|
|
drData["Counter_no"] = GetChar(sp[25].Trim(), 30, "柜员号");//26
|
|
drData["Settle_type"] = GetChar(sp[26].Trim(), 20, "业务类型");//27
|
|
drData["Reverse_flag"] = GetChar(sp[27].Trim(), 2, "冲账标识");//28
|
|
drData["Purpose"] = GetChar(sp[28].Trim(), 120, "摘要说明");//29
|
|
drData["Bord_flag"] = GetChar(sp[29].Trim(), 2, "跨境交易标识");//30
|
|
drData["Nation"] = GetChar(sp[30].Trim(), 80, "交易对方所在国家或地区");//31
|
|
drData["Bank_flag"] = GetChar(sp[31].Trim(), 2, "交易方式标识");//32
|
|
drData["Bank_tel"] = GetChar(sp[32].Trim(), 17, "手机银行号码");//33
|
|
drData["Ip_code"] = GetChar(sp[33].Trim(), 80, "Ip地址");//34
|
|
drData["Atm_code"] = GetChar(sp[34].Trim(), 30, "ATM机具编号");//35
|
|
drData["Bank_code"] = GetChar(sp[35].Trim(), 20, "ATM机具所属行行号");//36
|
|
drData["Mac_info"] = GetChar(sp[36].Trim(), 17, "Mac或imei地址");//37
|
|
|
|
drData["MyDateTime"] = GetDateTime(sp[0], sp[1]);
|
|
drData["MyDate"] = GetDateTime(sp[0]);
|
|
t_Data.Add(drData);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private DateTime GetDateTime(string date, string time)
|
|
{
|
|
if (date.Length != 8) throw new Exception($"交易日期[{date}]长度不正确");
|
|
if (time.Length != 6) throw new Exception($"交易时间[{time}]长度不正确");
|
|
|
|
//20180603
|
|
string d = date.Substring(0, 4) + "-" + date.Substring(4, 2) + "-" + date.Substring(6, 2);
|
|
//124824
|
|
string t = time.Substring(0, 2) + ":" + time.Substring(2, 2) + ":" + time.Substring(4, 2);
|
|
|
|
return Convert.ToDateTime($"{d} {t}");
|
|
}
|
|
|
|
private DateTime GetDateTime(string date)
|
|
{
|
|
if (date.Length != 8) throw new Exception($"交易日期[{date}]长度不正确");
|
|
|
|
//20180603
|
|
string d = date.Substring(0, 4) + "-" + date.Substring(4, 2) + "-" + date.Substring(6, 2);
|
|
|
|
return Convert.ToDateTime($"{d}");
|
|
}
|
|
|
|
private string GetChar(string str, int len, string name)
|
|
{
|
|
if(str.Length > len)
|
|
{
|
|
throw new Exception($"{name}[{str}] 长度超过了最大{len}位");
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
private string GetDecimal(string str, string name)
|
|
{
|
|
try
|
|
{
|
|
Convert.ToDecimal(str);
|
|
}
|
|
catch
|
|
{
|
|
throw new Exception($"{name}[{str}] 不是数字型");
|
|
}
|
|
|
|
return str;
|
|
}
|
|
}
|
|
}
|
|
|