Exemplo n.º 1
0
        private void btnPullData_Click(object sender, EventArgs e)
        {
            try
            {
                ShowStatusBar(string.Empty, true);

                ICollection <MachineInfo> lstMachineInfo = manipulator.GetLogData(objZkeeper, int.Parse(tbxMachineNumber.Text.Trim()));

                if (lstMachineInfo != null && lstMachineInfo.Count > 0)
                {
                    if (manipulator.PreviousCount == lstMachineInfo.Count && lstMachineInfo.Count > 0)// >0 and same as previous, so deleteting is safe
                    {
                        //objZkeeper.ClearGLog(tbxMachineNumber.Text.ToInt());
                        manipulator.PreviousCount = 0;
                    }
                    else//insert into database
                    {
                        var   connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["ZK_db"].ConnectionString;
                        MsSql sql = new MsSql(connectionstring);

                        foreach (var m in lstMachineInfo)
                        {
                            Attn_tblZKMaster objAttn_tblZKMaster = new Attn_tblZKMaster();
                            objAttn_tblZKMaster.DeviceID = m.MachineNumber.ToString();
                            objAttn_tblZKMaster.UserID   = m.IndRegID.ToString();
                            var zx = DateTime.Parse(m.DateTimeRecord);
                            objAttn_tblZKMaster.LogTime = DateTime.Parse(m.DateTimeRecord);

                            //var xx =DateTime.ParseExact( m.DateTimeRecord,"MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);//6/6/2018 9:47:31 PM
                            //check already inserted
                            var q  = $"select count(*) cnt from Attn_tblZKMaster where DeviceID='{objAttn_tblZKMaster.DeviceID}' and UserID='{objAttn_tblZKMaster.UserID}' and LogTime='{objAttn_tblZKMaster.LogTime}'";
                            var ds = sql.ExecuteDataSet(q, "tt");
                            if (ds.Tables[0].Rows[0][0].ToString().ToInt() == 0)
                            {
                                sql.InsertObject(objAttn_tblZKMaster);
                            }
                        }
                        manipulator.PreviousCount = lstMachineInfo.Count;
                    }

                    /////////////////////////
                    BindToGridView(lstMachineInfo);
                    ShowStatusBar(lstMachineInfo.Count + " records found !!", true);
                    //dd.SaveInformation(lstMachineInfo);
                }
                else
                {
                    DisplayListOutput("No records found");
                }
            }
            catch (Exception ex)
            {
                DisplayListOutput(ex.Message);
            }
        }