基本信息
源码名称:C# 刷卡机自动汇入资料库 源码
源码大小:0.47M
文件格式:.rar
开发语言:C#
更新时间:2016-10-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
刷卡机自动汇入资料库
无
刷卡机自动汇入资料库
无
刷卡机读取 myexe.exe 透过 web service 写入资料库
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
namespace MYEXE
{
class Program
{
static void Main(string[] args)
{
string str1;
// 是否有參數
if (args.Length > 0)
{
str1 = args[0];
if (File.Exists(str1) == false)
{
// 無檔案就停止
str1 = "無此 " str1 " 檔案";
Console.WriteLine(str1);
return;
}
}
else
{
// 沒有參數就停止
//str1 = "20140428.TXT"; //debug 用
str1 = "沒有檔名";
Console.WriteLine(str1);
return;
}
// 改為小寫檔名
str1 = str1.ToLower();
// 建立 log 檔檔名
string str2 = str1.Replace(".txt",".log");
// 取得系統時間 -- 開始
Console.WriteLine(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"));
// 呼叫副程式寫入資料庫和計算筆數
int num = fcount(str1,str2);
// 取得系統時間 -- 結束
Console.WriteLine(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"));
if (num < 0)
{
str1 = "無法開啟" str1 "檔案";
}
Console.WriteLine("{0}:{1}", str1, num);
}
static int fcount(string filename1, string filename2) // 檔案筆數
{
try // 檔案使用中不開啟
{
// 讀取檔案1
string[] str1 = File.ReadAllLines(filename1, System.Text.Encoding.Default);
if (File.Exists(filename2) == false)
{
// 檔案不存在的話先寫入一個空白的檔案
File.WriteAllText(filename2,"", System.Text.Encoding.Default);
}
// 讀取檔案2
string[] str2 = File.ReadAllLines(filename2, System.Text.Encoding.Default);
int num = 0; // 筆數
// 讀取字串
while (num < str1.Length)
{
// 判斷是否已有匯入成功
if (str2.Length > num)
{
if (str1[num].Substring(0, 27) == str2[num].Substring(0, 27))
{
if (str2[num].IndexOf("正確") >= 0 || str2[num].IndexOf("重複刷卡") >= 0)
{
// 已有匯入的時候就不重複執行
str1[num] = str2[num]; // 寫入轉檔訊息
num ;
continue;
}
}
}
// 呼叫 Web Service 寫入資料庫
myexe_ws.Service1 myexe_ws1 = new myexe_ws.Service1();
int imp_chk = myexe_ws1.MyEXE_imp(str1[num]);
// 錯誤讀取的資訊
if (imp_chk < 0)
{
switch (imp_chk)
{
case -1:
str1[num] = str1[num] " 無此 " str1[num].Substring(14, 10) " 卡號";
break;
case -2:
str1[num] = str1[num] " 資料庫錯誤";
break;
case -3:
str1[num] = str1[num] " 重複刷卡記錄";
break;
default:
str1[num] = str1[num] " 不明原因";
break;
}
}
else
{
str1[num] = str1[num] " 正確";
}
num ;
}
// 覆寫 Log 的檔案
File.WriteAllLines(filename2, str1, System.Text.Encoding.Default);
return num; // 回傳檔案筆數
}
catch (Exception)
{
return -1; // 檔案開啟錯誤
}
}
}
}