/// <summary>
        /// 获取读卡器设置
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static bool GetCardReaderBaseConfig(ref CardReaderBasicConfig config, string clienttype)
        {
            SCdoc = new XmlDocument();
            string fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory;
            string scfilePath        = "";

            if (clienttype == "Select")
            {
                scfilePath = string.Format("{0}SeatClient\\SeatClient.exe.config", fileDircetoryPath);
            }
            else if (clienttype == "Leave")
            {
                scfilePath = string.Format("{0}LeaveClient.exe.config", fileDircetoryPath);
            }
            if (File.Exists(scfilePath))
            {
                try
                {
                    SCdoc.Load(scfilePath);

                    XmlNodeList nodes = SCdoc.SelectNodes("//configuration/appSettings/add");
                    foreach (XmlNode node in nodes)
                    {
                        if (node.Attributes["key"].Value == "CardSnType")
                        {
                            int t = int.Parse(node.Attributes["value"].Value);
                            switch (t)
                            {
                            case 0:
                                config.CardID10Or16   = 10;
                                config.CardIDIsChange = false;
                                break;

                            case 1:
                                config.CardID10Or16   = 16;
                                config.CardIDIsChange = false;
                                break;

                            case 2:
                                config.CardID10Or16   = 16;
                                config.CardIDIsChange = true;
                                break;

                            case 3:
                                config.CardID10Or16   = 10;
                                config.CardIDIsChange = true;
                                break;
                            }
                        }
                        else if (node.Attributes["key"].Value == "IsBeep")
                        {
                            config.IsBeep = bool.Parse(node.Attributes["value"].Value);
                        }
                        else if (node.Attributes["key"].Value == "cardSnLength")
                        {
                            if (node.Attributes["value"].Value == "Full")
                            {
                                config.IsAdd0 = true;
                            }
                            else
                            {
                                config.IsAdd0 = false;
                            }
                        }
                        else if (node.Attributes["key"].Value == "XZX_ServerEndPort")
                        {
                            config.XZX_ServerEndPort = node.Attributes["value"].Value;
                        }
                        else if (node.Attributes["key"].Value == "XZX_SysCode")
                        {
                            config.XZX_SysCode = node.Attributes["value"].Value;
                        }
                        else if (node.Attributes["key"].Value == "XZX_TerminalNo")
                        {
                            config.XZX_TerminalNo = node.Attributes["value"].Value;
                        }
                        else if (node.Attributes["key"].Value == "XZX_Offline")
                        {
                            config.XZX_Offline = bool.Parse(node.Attributes["value"].Value);
                        }
                        else if (node.Attributes["key"].Value == "XZX_AddReader")
                        {
                            config.XZX_AddReader = bool.Parse(node.Attributes["value"].Value);
                        }
                        else if (node.Attributes["key"].Value == "XZX_IsOnelyReaderCardId")
                        {
                            config.XZX_IsOnelyReaderCardId = bool.Parse(node.Attributes["value"].Value);
                        }
                        else if (node.Attributes["key"].Value == "Hook_isCardNo")
                        {
                            config.Hook_isCardNo = bool.Parse(node.Attributes["value"].Value);
                        }
                        else if (node.Attributes["key"].Value == "PosPort")
                        {
                            config.FKport = node.Attributes["value"].Value;
                        }
                        else if (node.Attributes["key"].Value == "IPOSMethod")
                        {
                            switch (node.Attributes["value"].Value)
                            {
                            case "PosObject.PosObject,PosObject": config.CardReaderTye = 0; break;

                            case "PosObject.PosObject,PosObject_XZX": config.CardReaderTye = 1; break;

                            case "PosObject.PosObject,PosObject_FK": config.CardReaderTye = 2; break;

                            case "PosObject.PosObject,PosObject_HOOK": config.CardReaderTye = 3; break;

                            case "PosObject.PosObject,PosObject_CUT": config.CardReaderTye = 4; break;

                            case "PosObject.PosObject,PosObject_Customer": config.CardReaderTye = 5; break;
                            }
                        }
                    }
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        private void button13_Click(object sender, EventArgs e)
        {
            Code.CardReaderBasicConfig config = new Code.CardReaderBasicConfig();
            if (rb_mh.Checked)
            {
                if (rb_10.Checked)
                {
                    config.CardID10Or16 = 10;
                }
                else
                {
                    config.CardID10Or16 = 16;
                }
                config.CardIDIsChange = cb_change.Checked;
                config.IsAdd0         = cb_add0.Checked;
            }

            else if (rb_fk.Checked)
            {
                if (fk_10.Checked)
                {
                    config.CardID10Or16 = 10;
                }
                else
                {
                    config.CardID10Or16 = 16;
                }
                config.CardIDIsChange = fk_change.Checked;
                config.IsAdd0         = fk_add0.Checked;
            }
            config.IsBeep            = cb_Isbeep.Checked;
            config.FKport            = fk_port.Text;
            config.XZX_Offline       = xzx_off.Checked;
            config.XZX_ServerEndPort = txt_xzx_ip.Text;
            config.XZX_SysCode       = txt_xzx_sys.Text;
            config.XZX_TerminalNo    = txt_xzx_tre.Text;
            config.XZX_AddReader     = xzx_addreader.Checked;
            if (rb_xzx_readcardid.Checked)
            {
                config.XZX_IsOnelyReaderCardId = true;
            }
            else
            {
                config.XZX_IsOnelyReaderCardId = false;
            }
            if (rb_gz_cardid.Checked)
            {
                config.Hook_isCardNo = false;
            }
            else
            {
                config.Hook_isCardNo = true;
            }
            if (rb_mh.Checked)
            {
                config.CardReaderTye = 0;
            }
            else if (rb_xzx.Checked)
            {
                config.CardReaderTye = 1;
            }
            else if (rb_fk.Checked)
            {
                config.CardReaderTye = 2;
            }
            else if (rb_gz.Checked)
            {
                config.CardReaderTye = 3;
            }
            else if (rb_cut.Checked)
            {
                config.CardReaderTye = 4;
            }
            else if (rb_dz.Checked)
            {
                config.CardReaderTye = 5;
            }
            if (Code.CardReaderConfig.SaveConfig(config, clientmode))
            {
                MessageBox.Show("保存成功!");
            }
            else
            {
                MessageBox.Show("保存失败!");
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static bool SaveConfig(CardReaderBasicConfig config, string clienttype)
        {
            SCdoc = new XmlDocument();
            string fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory;
            string scfilePath        = "";

            if (clienttype == "Select")
            {
                scfilePath = string.Format("{0}SeatClient\\SeatClient.exe.config", fileDircetoryPath);
            }
            else if (clienttype == "Leave")
            {
                scfilePath = string.Format("{0}LeaveClient.exe.config", fileDircetoryPath);
            }
            if (File.Exists(scfilePath))
            {
                bool isbeepUpdate = false;
                bool isxzx_isreadcarddidupdate = false;
                bool ishook_isreadecard        = false;
                try
                {
                    SCdoc.Load(scfilePath);

                    XmlNodeList nodes = SCdoc.SelectNodes("//configuration/appSettings/add");
                    foreach (XmlNode node in nodes)
                    {
                        if (node.Attributes["key"].Value == "CardSnType")
                        {
                            if (config.CardID10Or16 == 10)
                            {
                                if (config.CardIDIsChange)
                                {
                                    node.Attributes["value"].Value = "3";
                                }
                                else
                                {
                                    node.Attributes["value"].Value = "0";
                                }
                            }
                            else
                            {
                                if (config.CardIDIsChange)
                                {
                                    node.Attributes["value"].Value = "2";
                                }
                                else
                                {
                                    node.Attributes["value"].Value = "1";
                                }
                            }
                        }
                        else if (node.Attributes["key"].Value == "IsBeep")
                        {
                            if (config.IsBeep)
                            {
                                node.Attributes["value"].Value = "true";
                            }
                            else
                            {
                                node.Attributes["value"].Value = "false";
                            }
                            isbeepUpdate = true;
                        }
                        else if (node.Attributes["key"].Value == "cardSnLength")
                        {
                            if (config.IsAdd0)
                            {
                                node.Attributes["value"].Value = "Full";
                            }
                            else
                            {
                                node.Attributes["value"].Value = "Part";
                            }
                        }
                        else if (node.Attributes["key"].Value == "XZX_ServerEndPort")
                        {
                            node.Attributes["value"].Value = config.XZX_ServerEndPort;
                        }
                        else if (node.Attributes["key"].Value == "XZX_SysCode")
                        {
                            node.Attributes["value"].Value = config.XZX_SysCode;
                        }
                        else if (node.Attributes["key"].Value == "XZX_TerminalNo")
                        {
                            node.Attributes["value"].Value = config.XZX_TerminalNo;
                        }
                        else if (node.Attributes["key"].Value == "XZX_Offline")
                        {
                            if (config.XZX_Offline)
                            {
                                node.Attributes["value"].Value = "true";
                            }
                            else
                            {
                                node.Attributes["value"].Value = "false";
                            }
                        }
                        else if (node.Attributes["key"].Value == "XZX_AddReader")
                        {
                            if (config.XZX_AddReader)
                            {
                                node.Attributes["value"].Value = "true";
                            }
                            else
                            {
                                node.Attributes["value"].Value = "false";
                            }
                        }
                        else if (node.Attributes["key"].Value == "XZX_IsOnelyReaderCardId")
                        {
                            if (config.XZX_IsOnelyReaderCardId)
                            {
                                node.Attributes["value"].Value = "true";
                            }
                            else
                            {
                                node.Attributes["value"].Value = "false";
                            }
                            isxzx_isreadcarddidupdate = true;
                        }
                        else if (node.Attributes["key"].Value == "Hook_isCardNo")
                        {
                            if (config.Hook_isCardNo)
                            {
                                node.Attributes["value"].Value = "true";
                            }
                            else
                            {
                                node.Attributes["value"].Value = "false";
                            }
                            ishook_isreadecard = true;
                        }
                        else if (node.Attributes["key"].Value == "PosPort")
                        {
                            node.Attributes["value"].Value = config.FKport;
                        }
                        else if (node.Attributes["key"].Value == "IPOSMethod")
                        {
                            switch (config.CardReaderTye)
                            {
                            case 0: node.Attributes["value"].Value = "PosObject.PosObject,PosObject"; break;

                            case 1: node.Attributes["value"].Value = "PosObject.PosObject,PosObject_XZX"; break;

                            case 2: node.Attributes["value"].Value = "PosObject.PosObject,PosObject_FK"; break;

                            case 3: node.Attributes["value"].Value = "PosObject.PosObject,PosObject_HOOK"; break;

                            case 4: node.Attributes["value"].Value = "PosObject.PosObject,PosObject_CUT"; break;

                            case 5: node.Attributes["value"].Value = "PosObject.PosObject,PosObject_Customer"; break;
                            }
                        }
                        else if (node.Attributes["key"].Value == "ICardReader")
                        {
                            switch (config.CardReaderTye)
                            {
                            case 0: node.Attributes["value"].Value = "CardReaderObject.CardReaderObject,CardReaderObject"; break;

                            case 1: node.Attributes["value"].Value = "CardReaderObject.CardReaderObject,CardReaderObject_XZX"; break;

                            case 2: node.Attributes["value"].Value = "CardReaderObject.CardReaderObject,CardReaderObject_FK"; break;

                            case 3: node.Attributes["value"].Value = "CardReaderObject.CardReaderObject,CardReaderObject_HOOK"; break;

                            case 4: node.Attributes["value"].Value = "CardReaderObject.CardReaderObject,CardReaderObject_CUT"; break;

                            case 5: node.Attributes["value"].Value = "CardReaderObject.CardReaderObject,CardReaderObject_Customer"; break;
                            }
                        }
                    }
                    if (!isbeepUpdate)
                    {
                        XmlNode    node    = SCdoc.SelectSingleNode("//configuration/appSettings");
                        XmlElement element = SCdoc.CreateElement("add");
                        element.SetAttribute("key", "IsBeep");
                        element.SetAttribute("value", "true");
                        node.AppendChild(element);
                    }
                    if (!isxzx_isreadcarddidupdate)
                    {
                        XmlNode    node    = SCdoc.SelectSingleNode("//configuration/appSettings");
                        XmlElement element = SCdoc.CreateElement("add");
                        element.SetAttribute("key", "XZX_IsOnelyReaderCardId");
                        element.SetAttribute("value", "false");
                        node.AppendChild(element);
                    }
                    if (!ishook_isreadecard)
                    {
                        XmlNode    node    = SCdoc.SelectSingleNode("//configuration/appSettings");
                        XmlElement element = SCdoc.CreateElement("add");
                        element.SetAttribute("key", "Hook_isCardNo");
                        element.SetAttribute("value", "true");
                        node.AppendChild(element);
                    }
                    SCdoc.Save(scfilePath);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        private void SeatManageConfigTool_Load(object sender, EventArgs e)
        {
            Code.HostConfig             hostconfig          = new Code.HostConfig();
            Code.ClientBasicConfig      clientconfig        = new Code.ClientBasicConfig();
            Code.CardReaderBasicConfig  cardReaderConfig    = new Code.CardReaderBasicConfig();
            Code.WebConfigSetting       webConfigSeeting    = new Code.WebConfigSetting();
            Code.LeaveClientBesicConfig leaveConfigSetting  = new Code.LeaveClientBesicConfig();
            Code.DeviceSettingConfig    deviceSettingConfig = new Code.DeviceSettingConfig();
            Code.ShutDownConfig         shutDownConfig      = new Code.ShutDownConfig();
            if (Code.ReadSeatHostConfigV3.ReadConfig(ref hostconfig))
            {
                foreach (string server in hostconfig.HostServer)
                {
                    if (server == "WcfHost")
                    {
                        cb_WCF.Checked = true;
                    }
                    else if (server == "MonitorService")
                    {
                        cb_Watch.Checked = true;
                    }
                    else if (server == "DataTransferService")
                    {
                        cb_DT.Checked = true;
                    }
                }
                txt_DBIP.Text               = hostconfig.DBIP;
                txt_DBName.Text             = hostconfig.DBName;
                txt_DBpw.Text               = hostconfig.DBPW;
                txt_DBUser.Text             = hostconfig.DBUser;
                txt_SeverWCFConnString.Text = hostconfig.WCFString;
                txt_weixinendportwcf.Text   = hostconfig.WeChatWCFString;
                txt_FilePath.Text           = hostconfig.MediaFilePath;
                txt_ServerSchoolNo.Text     = hostconfig.SchoolNo;
                txt_ServerLoopTime.Text     = hostconfig.LoopTime;
                txt_Uploadtime.Text         = hostconfig.UploadTime;
                if (Code.WebConfig.ReadConfig(ref webConfigSeeting))
                {
                    cb_web_pw_change.Checked = webConfigSeeting.IsChangePW;
                }
                else
                {
                    MessageBox.Show("无法自动获取管理网站配置文件,请确保和Host服务文件夹放置在同一目录,并且文件夹为“SeatManageWebV5”");
                    gb_web.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[1].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[2].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[3].Controls)
                {
                    c.Enabled = false;
                }
            }
            else if (Code.ReadSeatClientConfig.GetSeatClientBaseConfig(ref clientconfig) && Code.CardReaderConfig.GetCardReaderBaseConfig(ref cardReaderConfig, "Select"))
            {
                clientmode = "Select";
                txt_clientwcfstring.Text = clientconfig.WCFConnString;
                txt_schoolno.Text        = clientconfig.SchoolNo;
                txt_campusno.Text        = clientconfig.CampusNo;
                txt_deviceno.Text        = clientconfig.TerminalNum;
                txt_defualtmedia.Text    = clientconfig.DefaultMedia;
                txt_adloop.Text          = clientconfig.SCLoopTime;
                txt_sentloop.Text        = clientconfig.SentStatusTime;
                txt_update.Text          = clientconfig.UpdateTime;
                txt_mac.Text             = GetMacAddress.GetLocalAddress()[0];
                gb_xzx.Enabled           = false;
                gb_mh.Enabled            = false;
                gb_fk.Enabled            = false;
                gb_gz.Enabled            = false;
                gb_cut.Enabled           = false;
                gb_dz.Enabled            = false;

                switch (cardReaderConfig.CardReaderTye)
                {
                case 0: rb_mh.Checked = true; break;

                case 1: rb_xzx.Checked = true; break;

                case 2: rb_fk.Checked = true; break;

                case 3: rb_gz.Checked = true; break;

                case 4: rb_cut.Checked = true; break;

                case 5: rb_dz.Checked = true; break;
                }
                if (cardReaderConfig.CardID10Or16 == 10)
                {
                    fk_10.Checked = true;
                    rb_10.Checked = true;
                }
                else
                {
                    fk_16.Checked = true;
                    rb_16.Checked = true;
                }
                cb_Isbeep.Checked     = cardReaderConfig.IsBeep;
                fk_port.Text          = cardReaderConfig.FKport;
                txt_xzx_ip.Text       = cardReaderConfig.XZX_ServerEndPort;
                txt_xzx_sys.Text      = cardReaderConfig.XZX_SysCode;
                txt_xzx_tre.Text      = cardReaderConfig.XZX_TerminalNo;
                xzx_addreader.Checked = cardReaderConfig.XZX_AddReader;
                xzx_off.Checked       = cardReaderConfig.XZX_Offline;
                if (cardReaderConfig.Hook_isCardNo)
                {
                    rb_gz_cardno.Checked = true;
                }
                else
                {
                    rb_gz_cardid.Checked = true;
                }
                if (cardReaderConfig.XZX_IsOnelyReaderCardId)
                {
                    rb_xzx_readcardid.Checked = true;
                }
                else
                {
                    rb_xzx_readcardno.Checked = true;
                }
                cb_change.Checked = cardReaderConfig.CardIDIsChange;
                fk_change.Checked = cardReaderConfig.CardIDIsChange;
                cb_add0.Checked   = cardReaderConfig.IsAdd0;
                fk_add0.Checked   = cardReaderConfig.IsAdd0;

                if (Code.DeviceSetting.GetDeviceSetting(ref deviceSettingConfig))
                {
                    txt_d_IP.Text       = deviceSettingConfig.IP;
                    txt_d_dns.Text      = deviceSettingConfig.DNS;
                    txt_d_getway.Text   = deviceSettingConfig.Gateway;
                    txt_d_mask.Text     = deviceSettingConfig.Mask;
                    txt_pc_name.Text    = deviceSettingConfig.PCName;
                    cb_staticIP.Checked = deviceSettingConfig.IsStaticIP;
                }
                if (Code.DeviceSetting.GetShotDownSetting(ref shutDownConfig))
                {
                    cb_sd.Checked = shutDownConfig.IsUsed;
                    txt_sd_h.Text = shutDownConfig.ShutDownHour;
                    txt_sd_m.Text = shutDownConfig.ShutDownMin;
                    txt_sd_s.Text = shutDownConfig.ShutDownWaitSec;
                }
                foreach (Control c in tabControl1.TabPages[0].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[2].Controls)
                {
                    c.Enabled = false;
                }
                tabControl1.SelectedIndex = 1;
            }
            else if (Code.LeaveClientConfig.GetLeaveClientConfig(ref leaveConfigSetting) && Code.CardReaderConfig.GetCardReaderBaseConfig(ref cardReaderConfig, "Leave"))
            {
                clientmode             = "Leave";
                txt_leave_wcfconn.Text = leaveConfigSetting.WCFConnString;
                switch (leaveConfigSetting.LeaveMode)
                {
                case "0": rb_leave_s.Checked = true; break;

                case "1": rb_leave_sl.Checked = true; break;

                case "2": rb_leave_l.Checked = true; break;

                case "3": rb_leave_s.Checked = true; break;
                }
                if (leaveConfigSetting.SetUpMode == "1")
                {
                    rb_win_max.Checked = true;
                }
                else
                {
                    rb_win_min.Checked = true;
                }
                gb_xzx.Enabled = false;
                gb_mh.Enabled  = false;
                gb_fk.Enabled  = false;
                gb_gz.Enabled  = false;
                gb_cut.Enabled = false;
                gb_dz.Enabled  = false;

                switch (cardReaderConfig.CardReaderTye)
                {
                case 0: rb_mh.Checked = true; break;

                case 1: rb_xzx.Checked = true; break;

                case 2: rb_fk.Checked = true; break;

                case 3: rb_gz.Checked = true; break;

                case 4: rb_cut.Checked = true; break;

                case 5: rb_dz.Checked = true; break;
                }
                if (cardReaderConfig.CardID10Or16 == 10)
                {
                    fk_10.Checked = true;
                    rb_10.Checked = true;
                }
                else
                {
                    fk_16.Checked = true;
                    rb_16.Checked = true;
                }
                cb_Isbeep.Checked     = cardReaderConfig.IsBeep;
                fk_port.Text          = cardReaderConfig.FKport;
                txt_xzx_ip.Text       = cardReaderConfig.XZX_ServerEndPort;
                txt_xzx_sys.Text      = cardReaderConfig.XZX_SysCode;
                txt_xzx_tre.Text      = cardReaderConfig.XZX_TerminalNo;
                xzx_addreader.Checked = cardReaderConfig.XZX_AddReader;
                xzx_off.Checked       = cardReaderConfig.XZX_Offline;
                if (cardReaderConfig.Hook_isCardNo)
                {
                    rb_gz_cardno.Checked = true;
                }
                else
                {
                    rb_gz_cardid.Checked = true;
                }
                if (cardReaderConfig.XZX_IsOnelyReaderCardId)
                {
                    rb_xzx_readcardid.Checked = true;
                }
                else
                {
                    rb_xzx_readcardno.Checked = true;
                }
                cb_change.Checked = cardReaderConfig.CardIDIsChange;
                fk_change.Checked = cardReaderConfig.CardIDIsChange;
                cb_add0.Checked   = cardReaderConfig.IsAdd0;
                fk_add0.Checked   = cardReaderConfig.IsAdd0;
                foreach (Control c in tabControl1.TabPages[0].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[1].Controls)
                {
                    c.Enabled = false;
                }
                tabControl1.SelectedIndex = 2;
            }
            else
            {
                MessageBox.Show("获取配置文件失败,请把配置工具拷贝到宿主服务或者终端的根目录下,再次尝试!");
                foreach (Control c in tabControl1.TabPages[0].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[1].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[2].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[3].Controls)
                {
                    c.Enabled = false;
                }
                btnBackupProgram.Enabled  = false;
                tabControl1.SelectedIndex = 4;
            }
        }