/// <summary>
        /// 下发用户指纹
        /// </summary>
        /// <param name="sn">设备序列号</param>
        /// <param name="pin">用户工号</param>
        private void uploadUserFingerTemplate(string sn, string pin)
        {
            DeviceModel deviceModel = new DeviceBll().Get(sn);

            if (!deviceModel.IsBioDataSupport(BioType.FingerPrint))
            {
                return;
            }

            List <TmpFPModel> templateList = _tmpFPBll.Get(pin);
            DeviceCmdModel    cmd          = new DeviceCmdModel
            {
                DevSN = sn
            };
            string verTmp = deviceModel.GetBioVersion(BioType.FingerPrint).Split('.')[0];

            //send upload FingerTmp commands
            foreach (TmpFPModel template in templateList)
            {
                cmd.CommitTime = DateTime.Now;
                if (template.MajorVer != verTmp)
                {
                    continue;
                }
                if (template.MajorVer != "12")
                {
                    cmd.Content = string.Format(Commands.Command_UpdateFingerTmp, template.Pin, template.Fid,
                                                template.Size, template.Valid, template.Tmp);
                }
                else
                {
                    cmd.Content = string.Format(Commands.Command_UpdateBioData, template.Pin, template.Fid,
                                                "", template.Valid, template.Duress, "1", template.MajorVer, template.MinorVer, "", template.Tmp);
                }
                if (string.IsNullOrEmpty(cmd.Content))
                {
                    UserMessageShow(9, "");
                    return;
                }
                lblMsg.Visible = false;
                try
                {
                    if (_cmdBll.Add(cmd) >= 0)
                    {
                        UserMessageShow(2, "");
                    }
                    else
                    {
                        UserMessageShow(3, "");
                    }
                }
                catch { }
            }
        }
        /// <summary>
        /// 更新用户照片ID
        /// </summary>
        /// <param name="sn">设备序列号</param>
        /// <param name="pin">用户工号</param>
        private void uploadUserPhotoID(string sn, string pin)
        {
            string path        = System.Environment.CurrentDirectory;
            string PathofImage = path;
            string strBase64   = "";

            path += "\\Photo\\" + pin + ".jpg";
            if (PathofImage != null && PathofImage != "")//本地目录有对应用户图像
            {
                if (!File.Exists(path))
                {
                    UserMessageShow(10, "");
                    return;
                }
                long imageSize = 0;
                strBase64 = ImgToBase64String(path, out imageSize);

                if (imageSize >= 50 * 1024)
                {
                    MessageBox.Show("please choice photo size less than 50Kb", "Error");
                }
                else
                {
                    DeviceCmdModel cmd = new DeviceCmdModel();
                    cmd.DevSN      = sn;
                    cmd.CommitTime = DateTime.Now;
                    cmd.Content    = string.Format(Commands.Command_UpdateUserPic, pin,
                                                   strBase64.Length.ToString(), strBase64);

                    if (string.IsNullOrEmpty(cmd.Content))
                    {
                        UserMessageShow(9, "");
                        return;
                    }
                    lblMsg.Visible = false;
                    try
                    {
                        if (_cmdBll.Add(cmd) >= 0)
                        {
                            UserMessageShow(2, "");
                        }
                        else
                        {
                            UserMessageShow(3, "");
                        }
                    }
                    catch { }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 下发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpload_Click(object sender, EventArgs e)
        {
            if (null == new DeviceBll().Get(cmbDevice.Text))
            {
                lblMsg.Text = "Please input Device SN.";
                return;
            }
            if (null == _bll.GetByWorkCode(tb_WorkCode.Text.Trim()))
            {
                lblMsg.Text = "Please save workcode first.";
                return;
            }

            if (string.IsNullOrWhiteSpace(tb_WorkCode.Text.Trim()))
            {
                lblMsg.Text = "Please select workcode item.";
                return;
            }
            DeviceCmdModel cmd = new DeviceCmdModel();

            cmd.DevSN      = cmbDevice.Text;
            cmd.CommitTime = DateTime.Now;
            string workName = tb_WorkName.Text;

            byte[] bName = Encoding.UTF8.GetBytes(workName);

            workName = Encoding.Default.GetString(bName);

            cmd.Content = string.Format(Commands.Command_UpdateWorkCode, _dt.Select($"workcode='{tb_WorkCode.Text.Trim()}'")[0]["ID"].ToString(), tb_WorkCode.Text.Trim(), workName);

            if (string.IsNullOrEmpty(cmd.Content))
            {
                lblMsg.Text = "The command is error.";
                return;
            }
            lblMsg.Visible = true;
            try
            {
                if (_cmdBll.Add(cmd) >= 0)
                {
                    lblMsg.Text = "Operate successful.";
                }
                else
                {
                    lblMsg.Text = "Operate fail.";
                }
            }
            catch { }
        }
Exemplo n.º 4
0
        /// <summary>add a record
        /// </summary>
        public int Add(DeviceCmdModel dCmd)
        {
            string sql = string.Format(@"
insert into DeviceCmds(
       DevSN,Content,CommitTime,TransTime,ResponseTime,ReturnValue
   ) values (
       @DevSN,@Content,@CommitTime,@TransTime,@ResponseTime,@ReturnValue
);");

            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@DevSN",        dCmd.DevSN),
                new SQLiteParameter("@Content",      dCmd.Content),
                new SQLiteParameter("@CommitTime",   dCmd.CommitTime),
                new SQLiteParameter("@TransTime",    null),
                new SQLiteParameter("@ResponseTime", null),
                new SQLiteParameter("@ReturnValue",  dCmd.ReturnValue)
            };
            return(SqliteHelper.ExecuteNonQuery(sql, parameters));
        }
Exemplo n.º 5
0
        /// <summary>Save cmd to database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_devSN))
            {
                lblMsg.Visible = true;
                lblMsg.Text    = "Please select a device";
                return;
            }

            if (string.IsNullOrEmpty(rtxtCmd.Text))
            {
                lblMsg.Visible = true;
                lblMsg.Text    = "Cmd content is empty";
                return;
            }

            if (!CheckCmd(rtxtCmd.Text))
            {
                lblMsg.Visible = true;
                lblMsg.Text    = "Cmd content is invalid";
                return;
            }

            DeviceCmdModel model = new DeviceCmdModel();

            model.DevSN      = _devSN;
            model.Content    = rtxtCmd.Text;
            model.CommitTime = Tools.GetDateTimeNow();

            if (_bll.Add(model) > 0)
            {
                lblMsg.Visible = true;
                lblMsg.Text    = "Success";
            }
            else
            {
                lblMsg.Visible = true;
                lblMsg.Text    = "Fail";
            }
        }
        /// <summary>
        /// 下发用户掌静脉数据
        /// </summary>
        /// <param name="sn">设备序列号</param>
        /// <param name="pin">用户工号</param>
        private void uploadPalmTemplate(string sn, string pin)
        {
            DeviceModel deviceModel = new DeviceBll().Get(sn);

            DeviceCmdModel cmd = new DeviceCmdModel();

            cmd.DevSN = sn;
            if (deviceModel.IsBioDataSupport(BioType.Palm))
            {
                List <TmpBioDataModel> bioList = _tmpBioDataBll.Get(pin, BioType.Palm.ToString("D"));
                //send upload face commands
                foreach (TmpBioDataModel bioTmp in bioList)
                {
                    cmd.CommitTime = DateTime.Now;
                    cmd.Content    = string.Format(Commands.Command_UpdateBioData, bioTmp.Pin, bioTmp.No, bioTmp.Index, bioTmp.Valid,
                                                   bioTmp.Duress, bioTmp.Type, bioTmp.MajorVer, bioTmp.MinorVer, bioTmp.Format, bioTmp.Tmp);

                    if (string.IsNullOrEmpty(cmd.Content))
                    {
                        UserMessageShow(9, "");
                        return;
                    }
                    lblMsg.Visible = false;
                    try
                    {
                        if (_cmdBll.Add(cmd) >= 0)
                        {
                            UserMessageShow(2, "");
                        }
                        else
                        {
                            UserMessageShow(3, "");
                        }
                    }
                    catch { }
                }
            }
        }
        /// <summary>
        /// 下发用户面部数据
        /// </summary>
        /// <param name="sn">设备序列号</param>
        /// <param name="pin">用户工号</param>
        private void uploadUserFaceTemplate(string sn, string pin)
        {
            DeviceModel deviceModel = new DeviceBll().Get(sn);


            DeviceCmdModel cmd = new DeviceCmdModel();

            cmd.DevSN = sn;
            if (deviceModel.IsBioDataSupport(BioType.Face))
            {
                List <TmpFaceModel> faceList = _faceBll.Get(pin);
                //send upload face commands
                foreach (TmpFaceModel faceTmp in faceList)
                {
                    cmd.CommitTime = DateTime.Now;
                    cmd.Content    = string.Format(Commands.Command_UpdateFaceTmp, faceTmp.Pin, faceTmp.Fid,
                                                   faceTmp.Valid, faceTmp.Size, faceTmp.Tmp);

                    if (string.IsNullOrEmpty(cmd.Content))
                    {
                        UserMessageShow(9, "");
                        return;
                    }
                    lblMsg.Visible = false;
                    try
                    {
                        if (_cmdBll.Add(cmd) >= 0)
                        {
                            UserMessageShow(2, "");
                        }
                        else
                        {
                            UserMessageShow(3, "");
                        }
                    }
                    catch { }
                }
            }
            if (deviceModel.IsBioDataSupport(BioType.VisilightFace))
            {
                List <TmpBioPhotoModel> biophotoList = _tmpBioPhotoBll.Get(pin, BioType.Comm.ToString("D") + "," + BioType.VisilightFace.ToString("D"));
                //send upload biophoto commands
                foreach (TmpBioPhotoModel bioPhotoTmp in biophotoList)
                {
                    cmd.CommitTime = DateTime.Now;
                    cmd.Content    = string.Format(Commands.Command_UpdateBioPhoto, bioPhotoTmp.Pin, bioPhotoTmp.Type,
                                                   bioPhotoTmp.Size, bioPhotoTmp.Content, "0", "", "0");

                    if (string.IsNullOrEmpty(cmd.Content))
                    {
                        UserMessageShow(9, "");
                        return;
                    }
                    lblMsg.Visible = false;
                    try
                    {
                        if (_cmdBll.Add(cmd) >= 0)
                        {
                            UserMessageShow(2, "");
                        }
                        else
                        {
                            UserMessageShow(3, "");
                        }
                    }
                    catch { }
                }
            }
        }
        /// <summary>
        /// 下发按钮事件
        /// </summary>
        private void btnUpload_Click(object sender, EventArgs e)
        {
            string privilege = string.Empty;
            string curPin    = string.Empty;

            byte[] bName = new byte[24];

            string uName = "", sName = "";

            if (null == new DeviceBll().Get(cmbDevice.Text))
            {
                UserMessageShow(1, "");
                return;
            }
            if (null == _bll.Get(txtPin.Text.Trim()))
            {
                lblMsg.Visible = true;
                lblMsg.Text    = "Please save user.";
                return;
            }

            lblMsg.Visible = false;

            GetCurSelectRows();
            if (_CurSelectRows.Count == 0)
            {
                lblMsg.Visible = true;
                lblMsg.Text    = "Please select user item.";
                return;
            }
            //send upload Userinfo commands
            foreach (DataGridViewRow item in _CurSelectRows)
            {
                privilege = item.Cells["colPrivilege"].Value.ToString();
                if (privilege == "14")
                {
                    privilege = "14";
                }
                else
                {
                    privilege = "0";
                }
                curPin = item.Cells["colUserPin"].Value.ToString();
                DeviceCmdModel cmd = new DeviceCmdModel();
                cmd.DevSN      = cmbDevice.Text;
                cmd.CommitTime = DateTime.Now;
                sName          = item.Cells["colUserName"].Value.ToString();
                bName          = System.Text.Encoding.UTF8.GetBytes(sName);

                uName = System.Text.Encoding.Default.GetString(bName);
                sName = uName;

                //for (int i = 1; i < 1000; i++)
                {
                    cmd.Content = string.Format(Commands.Command_UpdateUserInfo, item.Cells["colUserPin"].Value.ToString(), sName,
                                                privilege, item.Cells["colPassword"].Value.ToString(), item.Cells["colCardNumber"].Value.ToString(), item.Cells["colGroup"].Value.ToString(), item.Cells["colTimezone"].Value.ToString());


                    if (string.IsNullOrEmpty(cmd.Content))
                    {
                        UserMessageShow(9, "");
                        return;
                    }
                    lblMsg.Visible = false;
                    try
                    {
                        if (_cmdBll.Add(cmd) >= 0)
                        {
                            UserMessageShow(2, "");

                            if (cb_FP.Checked == true)
                            {
                                uploadUserFingerTemplate(cmd.DevSN, curPin);
                            }
                            if (cb_Face.Checked == true)
                            {
                                uploadUserFaceTemplate(cmd.DevSN, curPin);
                            }
                            if (cb_Palm.Checked == true)
                            {
                                uploadPalmTemplate(cmd.DevSN, curPin);
                            }
                            if (cb_Photo.Checked == true)
                            {
                                uploadUserPhotoID(cmd.DevSN, curPin);
                            }
                        }
                        else
                        {
                            UserMessageShow(3, "");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Upload Error/nException:" + ex.Message + " " + ex.StackTrace);
                    }
                }
            }
        }
        /// <summary>上传短消息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpload_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmbDevSN.Text))
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text    = "DevSN is Empty.";
                return;
            }
            if (null == _bll.Get(txtSmsID.Text.Trim()))
            {
                this.lblMsg.Visible = true;
                lblMsg.Text         = "Please save first.";
                return;
            }
            if (string.IsNullOrEmpty(txtSmsID.Text))
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text    = "SmdID is Empty.";
                return;
            }
            if (string.IsNullOrEmpty(txtContent.Text))
            {
                this.lblMsg.Visible = true;
                this.lblMsg.Text    = "Content is Empty.";
                return;
            }
            lblMsg.Visible = false;

            DeviceCmdModel cmd = new DeviceCmdModel();

            cmd.DevSN      = cmbDevSN.Text;
            cmd.CommitTime = Tools.GetDateTimeNow();

            string content   = txtContent.Text.Trim();
            string type      = cmbType.SelectedValue.ToString();
            string smsID     = txtSmsID.Text.Trim();
            int    validTime = Tools.TryConvertToInt32(numValidTime.Value);
            string beginTime = dtpBeginTime.Value.ToString("yyyy-MM-dd HH:mm:ss");

            cmd.Content = string.Format(Commands.Command_UpdateSMS, content, type, smsID, validTime, beginTime);

            DeviceCmdBll cmdBll = new DeviceCmdBll();

            if (type == "254")
            {//用户短消息
                if (cmdBll.Add(cmd) >= 0)
                {
                    string userID = txtUserID.Text.Trim();
                    cmd.Content = string.Format(Commands.Command_UpdateUserSMS, userID, smsID);
                }
                else
                {
                    this.lblMsg.Visible = true;
                    this.lblMsg.Text    = "Operate fail.";
                    return;
                }
            }

            this.lblMsg.Visible = true;

            if (cmdBll.Add(cmd) >= 0)
            {
                this.lblMsg.Text = "Operate successful.";
            }
            else
            {
                this.lblMsg.Text = "Operate fail.";
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// 新增
 /// </summary>
 /// <param name="dCmd"></param>
 /// <returns></returns>
 public int Add(DeviceCmdModel dCmd)
 {
     return(_dal.Add(dCmd));
 }