• C# 读取记事本文件



    public int InsertTable(string[] str, string date, Guid userid, Guid ownid, Guid moneyid)
    {
    int ischeck = 0;
    int issuccess = 0;
    decimal money = 0;
    Guid rguid = Guid.Empty;
    string inSql;
    int ret = 0;

    issuccess = System.Convert.ToInt32(str[11]);
    money = System.Convert.ToDecimal(str[5]);

    string contract = "null";
    string billsdetail = "null";

    if (issuccess==0)
    {
    string GetSql = string.Format(@"select new_billingrecordid,new_contract from new_billingrecord where new_billstatus={0} and new_cardname='{1}' and new_bankcard='{2}' and new_billingsum={3}", 100000000, str[4], str[3], money);
    DataTable ds = helper.GetDataSet(GetSql).Tables[0];
    if (ds != null && ds.Rows.Count != 0)
    {
    billsdetail ="'"+ ds.Rows[0][0].ToString() +"'";
    contract = "'"+ds.Rows[0][1].ToString() +"'";
    string Sql = string.Format(@"update new_billingrecord set new_billstatus={0},new_verifyman='{1}',new_verifytime='{2}' where new_billingrecordid={3}", 100000001,userid, DateTime.Now.AddHours(-8), billsdetail);
    ret=helper.ExecuteSql(Sql);
    if(ret==0)
    {
    ischeck = 0;
    }
    }
    }

    rguid = Guid.NewGuid();
    inSql = string.Format(@"INSERT INTO new_bankimportBase(new_bankimportid,new_name,new_numberofbank,new_bankname,new_cardnumber,new_cardname,new_money,new_number,new_issuccess,new_bankdesc,new_bankdate,new_ischeck,new_contract,new_billsdetail,
    CreatedOn,CreatedBy,ModifiedOn,ModifiedBy,OwnerId,OwnerIdType,OwningBusinessUnit,statecode,statuscode,transactioncurrencyid)VALUES('{0}','{1}','{2}','{3}','{4}','{5}',{6},'{7}',{8},'{9}','{10}',{11},{12},{13},
    '{14}','{15}','{16}','{17}','{18}',{19},'{20}',{21},{22},'{23}')",
    rguid, str[0], str[1], str[2], str[3], str[4], money, str[7], issuccess, str[12], date, ischeck,contract,billsdetail,
    DateTime.Now.AddHours(-8), userid, DateTime.Now.AddHours(-8), userid, userid, 8, ownid, 0, 1, moneyid);
    ret = helper.ExecuteSql(inSql);


    return 0;
    }

    public ActionResult Upload(HttpPostedFileBase file)
    {
    Guid userid = Guid.Empty;
    Guid ownid = Guid.Empty;
    Guid moneyid = Guid.Empty;

    if (file == null)
    {
    return Content("没有文件!", "text/plain");
    }
    var fileName = Path.Combine(Request.MapPath("~/Upload"), Path.GetFileName(file.FileName));
    try
    {
    file.SaveAs(fileName);


    string userName = ConfigurationManager.AppSettings["userName"]; ;
    DataTable dtbUser = helper.GetDataSet("select systemuserid,domainname,businessunitid from systemuserbase where domainname='" + userName + "'").Tables[0];
    if (dtbUser != null && dtbUser.Rows.Count != 0)
    {
    userid = (Guid)dtbUser.Rows[0][0];
    ownid = (Guid)dtbUser.Rows[0][2];
    }
    else
    {
    ViewData["result"] = "用户名错误";
    return Content("上传异常 !", "text/plain");
    }

    DataTable dtMoney = helper.GetDataSet("select TransactionCurrencyId from TransactionCurrency where CurrencyName='人民币'").Tables[0];
    if (dtMoney != null && dtMoney.Rows.Count != 0)
    {
    moneyid = (Guid)dtMoney.Rows[0][0];
    }

    int count = 0;
    StreamReader sr = new StreamReader(fileName, Encoding.Default);
    String line;
    line = sr.ReadLine();//读取记事本第一行

    string[] s = line.Split('|');//将第一行转换成数组
    int total = System.Convert.ToInt32(s[6]);//获取总行数

    while ((line = sr.ReadLine()) != null)
    {
    if (count == total)
    {
    break;
    }
    string[] str = line.Split('|');
    if(str[0]!="")
    {
    int ret = InsertTable(str, s[3],userid,ownid,moneyid);
    if (ret == 0)
    {
    count++;
    }
    }
    }
    }
    catch
    {
    return Content("上传异常 !", "text/plain");
    }

    return Content("上传成功!", "text/plain");
    }

    }
    }

    记事本内容

    79258001|深圳市某某科技技术有限公司|00505|20160222|1|201602|31|2558.0|20|1630.0|11|928.0|
    1|54812956|中国银行科苑支行|6216612000000848933|陈良娣|78.00||10A001||||0|-成功|
    2|54812962|招商银行蔡屋围支行|9555507553117502|杨小莉|78.00||10A002||||0|-成功|
    3|54812965|深圳农村商业银行|6230351814819013|彭素琴|78.00||10A003||||0|-成功|
    4|54812961|平安银行东莞分行|6230582000041198147|吴志英|78.00||10A004||||0|-成功|
    5|54812964|中国农业银深圳分行|6228480128247157679|郭秀|78.00||10A005||||0|-成功|
    6|54812964|中国农业银深圳分行|6228480128247157679|郭的秀金|78.00||10A005||||0|-成功|
    7|54812964|中国农业银深圳分行|6228480128247157679|郭秀金|78.00||10A005||||0|-成功|
    8|54812956|中国银行深圳分行|6013822000623424903|赖启辉|78.00||10A006||||0|-成功|
    9|54812957|中国民生银行福田区景田支行|6226190680192576|陆的雁|78.00||10A007||||0|-成功|
    10|54812961|平安银行深圳分行|6225380098870563|杨鹏|78.00||10A008||||0|-成功|
    11|54812958|中国建设深圳分行|6227007200121050688|韩的|88.00||10A009||||0|-成功|
    12|54812958|中国建设深圳分行|6227007200121050688|韩2|88.00||10A009||||0|-成功|
    13|54812956|中国银行深圳分行|6013822000575994747|陈霞|78.00||10A010||||0|-成功|
    14|54812956|中国银行深圳分行|6013822000575994747|陈2霞|78.00||10A010||||1|-账户余额不足支付|
    15|54812962|招商银行深圳分行|6225807550669517|钟啊|78.00||10A011||||1|-账号不存在|
    16|54812962|招商银行深圳分行|6225807550669517|钟杰|78.00||10A011||||1|-账号不存在|
    17|54812963|工商银行深圳分行|62122640000065622199|凌比武|88.00||10A012||||1|-商业银行拒绝|
    18|54812963|工商银行深圳分行|62122640000065622199|凌比武|88.00||10A012||||1|-商业银行拒绝|
    19|54812958|建设银行深圳分行|6227003241800367104|邹的琼|78.00||10A013||||0|-成功|
    20|54812958|建设银行深圳分行|6227003241800367104|邹惠琼|78.00||10A013||||0|-成功|
    21|54812959|光大银行深圳分行|6226622604906930|黄可鑫|78.00||10A014||||1|-商业银行拒绝|
    22|54812961|平安银行深圳分行|6230582000049620092|齐波|88.00||10A015||||1|-Enrichment process failed : SubAccountEnricher.|
    23|54812961|平安银行深圳分行|6222980015165618|张继聪|88.00||10A016||||0|-成功|
    24|54812960|华夏银行南昌分行|6230200870037202|陈小霞|88.00||10A017||||1|-商业银行拒绝|
    25|54812956|中国银行南昌分行|6013821800689996970|郑少波|88.00||10A018||||0|-成功|
    26|54812958|中国建设银行南昌红谷滩支行|6226223501321338|肖佳丽|88.00||10A019||||1|-账号不存在|
    27|54812957|中国民生银行南昌分行|6227002022270046860|林华|88.00||10A020||||1|-查询付款账户信息失败|
    28|54812956|中国银行深圳分行|6013822000912166199|林海秋|88.00||10A021||||0|-成功|
    29|54812961|平安银行深圳分行|623058000059053699|刘德华|88.00||10A022||||1|-Enrichment process failed : SubAccountEnricher.|
    30|54812964|中国农业银行深圳分行|6228480120138456716|王梅珊|88.00||10A023||||0|-成功|
    31|54812964|中国农业银行深圳分行|6228480120138456716|王梅珊|88.00||10A024||||0|-成功|

  • 相关阅读:
    Cannot run program "/home/mohemi/Program/adt-bundle-linux-x86_64-20130729/sdk//tools/emulator": error=2, 没有那个文件或目录
    在Ubuntu里部署Javaweb环境脑残版
    ios 内存管理 心得
    关于Servlet的PrintWriter 中文乱码问题
    流的对拷
    什么是javaBean
    ios 页面传值4种方式(四) 之通过delegate(代理)
    ios 页面传值4种方式(一) 之全局变量
    Block
    UIView动画学习笔记
  • 原文地址:https://www.cnblogs.com/zhan-shuai/p/5291191.html
Copyright © 2020-2023  润新知