public DataMngForm(Main Parent) { InitializeComponent(); DataMng = Parent; udisk = new UDisk(); LoadUDiskFile(); }
private void buttonImport_Click(object sender, EventArgs e) { //if ((_oInput == InputOption.LAN) && (_bioType == BioType.ZK)) //{ //} //else if ((_oInput == InputOption.USB) && (_bioType == BioType.ZK)) //{ machineInstanceBindingSource.AddNew(); var udisk = new UDisk(); byte[] byDataBuf = null; int iLength; //length of the bytes to get from the data string sPIN2 = ""; string sVerified = ""; string sTime_second = ""; string sDeviceID = ""; string sStatus = ""; string sWorkcode = ""; openFileDialog1.Filter = "1_attlog(*.dat)|*.dat"; openFileDialog1.FileName = "1_attlog.dat"; //1 stands for one possible deviceid if (openFileDialog1.ShowDialog() == DialogResult.OK) { FileStream stream = new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Read); byDataBuf = File.ReadAllBytes(openFileDialog1.FileName); iLength = Convert.ToInt32(stream.Length); int iStartIndex = 0; int iOneLogLength; //the length of one line of attendence log for (int i = iStartIndex; i < iLength - 2; i++) //modify by darcy on Dec.4 2009 { if (byDataBuf[i] == 13 && byDataBuf[i + 1] == 10) { iOneLogLength = (i + 1) + 1 - iStartIndex; byte[] bySSRAttLog = new byte[iOneLogLength]; Array.Copy(byDataBuf, iStartIndex, bySSRAttLog, 0, iOneLogLength); udisk.GetAttLogFromDat(bySSRAttLog, iOneLogLength, out sPIN2, out sTime_second, out sDeviceID, out sStatus, out sVerified, out sWorkcode); var dat = new DatData { Pin = sPIN2, AttTime = sTime_second, Status = sStatus, Verify = sVerified, Device = sDeviceID, WorkCode = sWorkcode }; _listDat.Add(dat); bySSRAttLog = null; iStartIndex += iOneLogLength; iOneLogLength = 0; } } stream.Close(); } datDataBindingSource.DataSource = null; datDataBindingSource.DataSource = _listDat; //} //else if ((_oInput == InputOption.USB) && (_bioType == BioType.Realand)) //{ //} //else //{ // return; //} }
private void buttonImport_Click(object sender, EventArgs e) { machineInstanceBindingSource.AddNew(); if ((radioButton2.Checked) && (radioButton3.Checked)) { var udisk = new UDisk(); byte[] byDataBuf = null; int iLength;//length of the bytes to get from the data string sPIN2 = ""; string sVerified = ""; string sTime_second = ""; string sDeviceID = ""; string sStatus = ""; string sWorkcode = ""; if (openFileDialog1.ShowDialog() == DialogResult.OK) { openFileDialog1.Filter = @"zklog(*.dat)|*.dat"; FileStream stream = new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Read); byDataBuf = File.ReadAllBytes(openFileDialog1.FileName); iLength = Convert.ToInt32(stream.Length); int iStartIndex = 0; int iOneLogLength; //the length of one line of attendence log for (int i = iStartIndex; i < iLength - 2; i++) //modify by darcy on Dec.4 2009 { if (byDataBuf[i] == 13 && byDataBuf[i + 1] == 10) { iOneLogLength = (i + 1) + 1 - iStartIndex; byte[] bySSRAttLog = new byte[iOneLogLength]; Array.Copy(byDataBuf, iStartIndex, bySSRAttLog, 0, iOneLogLength); udisk.GetAttLogFromDat(bySSRAttLog, iOneLogLength, out sPIN2, out sTime_second, out sDeviceID, out sStatus, out sVerified, out sWorkcode); var dat = new DatData { Pin = sPIN2, AttTime = sTime_second, Status = sStatus, Verify = sVerified, Device = sDeviceID, WorkCode = sWorkcode }; _listDat.Add(dat); bySSRAttLog = null; iStartIndex += iOneLogLength; iOneLogLength = 0; } } stream.Close(); } datDataBindingSource.DataSource = null; datDataBindingSource.DataSource = _listDat; _option = 1; } else if ((radioButton2.Checked) && (radioButton4.Checked)) { openFileDialog1.Filter = @"HisGLog_0001_20170801(*.csv)|*.csv"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { var filename = openFileDialog1.FileName; Console.WriteLine(filename); string[] allLines = File.ReadAllLines(openFileDialog1.FileName); var query = from line in allLines let data = line.Split('\t') select new DatData { Pin = data[2], AttTime = data[8], Device = data[1], Status = data[4], Verify = data[5], WorkCode = data[7] }; foreach (var item in query) { int iResult = 0; if (int.TryParse(item.Pin, out iResult)) { _listDat.Add(item); } } } datDataBindingSource.DataSource = _listDat; _option = 2; } else if ((radioButton2.Checked) && (radioButtonAnviz.Checked)) { try { System.Diagnostics.Process.Start(Directory.GetCurrentDirectory() + @"\x.bat", Directory.GetCurrentDirectory() + @"\anviz\anviz_file\convert.js"); //command process - call to cmd and execute node.js //var startInfo = new ProcessStartInfo //{ // FileName = "cmd.exe", // RedirectStandardInput = true, // RedirectStandardOutput = true, // UseShellExecute = false, // CreateNoWindow = false //}; //var process = new Process { StartInfo = startInfo }; //process.Start(); //var filePath = Directory.GetCurrentDirectory() + @"\anviz\anviz_file\convert.js"; //process.StandardInput.WriteLine(@"node " + filePath); //process.StandardInput.WriteLine("exit"); //process.WaitForExit(); //setting file and display the result var filename = Directory.GetCurrentDirectory() + @"\anviz\anviz_file\bak.xlsx"; Console.WriteLine(filename); app = new Excel.Application { Visible = false }; book = app.Workbooks.Open(filename); sheet = (Excel.Worksheet)book.Sheets[1]; var lastRow = sheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row; var tempList = new List <DatData>(); for (var i = 2; i < lastRow; i++) { var values = (System.Array)sheet.get_Range("A" + i.ToString(), "D" + i.ToString()).Cells.Value; tempList.Add(new DatData { Pin = values.GetValue(1, 1).ToString(), AttTime = values.GetValue(1, 2).ToString(), Status = values.GetValue(1, 3).ToString(), Device = "0", Verify = "0", WorkCode = "0" }); } book.Close(Type.Missing, Type.Missing, Type.Missing); app.Quit(); foreach (var item in tempList) { int iResult = 0; if (int.TryParse(item.Pin, out iResult)) { _listDat.Add(item); } } datDataBindingSource.DataSource = _listDat; _option = 2; } catch (Exception ex) { MessageBox.Show(@"Kindly check the error: " + ex.Message); } } else if ((radioButton2.Checked) && (radioButtonW.Checked)) { openFileDialog1.Filter = @"GLog_001(*.txt)|*.txt"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { var filename = openFileDialog1.FileName; Console.WriteLine(filename); string[] allLines = File.ReadAllLines(openFileDialog1.FileName); var query = from line in allLines let data = line.Split('\t') select new DatData { Pin = data[2], AttTime = data[6], Device = data[1], Status = data[4], Verify = data[5], WorkCode = data[5] }; foreach (var item in query) { int iResult = 0; if (int.TryParse(item.Pin, out iResult)) { _listDat.Add(item); } } } datDataBindingSource.DataSource = _listDat; _option = 2; } else if ((radioButton1.Checked) && (radioButton3.Checked)) { int connectError = 0; } }