Example #1
0
        /// <summary>
        /// 经营户下载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOperators_Click(object sender, EventArgs e)
        {
            btnOperators.Enabled = false;
            try
            {
                com.szscgl.ncp.sDataInfrace webserver = new com.szscgl.ncp.sDataInfrace();
                string AreaMarket = string.Empty;
                KunShanEntity.GetTokenRequest.webService querySignContact = new KunShanEntity.GetTokenRequest.webService();
                querySignContact.request          = new KunShanEntity.GetTokenRequest.Request();
                querySignContact.request.name     = Global.ServerName;
                querySignContact.request.password = Global.MD5(Global.ServerPassword);
                string response = XmlHelper.EntityToXml <KunShanEntity.GetTokenRequest.webService>(querySignContact);
                //System.Console.WriteLine(string.Format("GetAreaMarket-Request:{0}", response));
                AreaMarket = webserver.GetAreaMarket(response);
                //System.Console.WriteLine(string.Format("GetAreaMarket-Response:{0}", AreaMarket));
                List <KunShanEntity.AreaMarket> models = JsonHelper.JsonToEntity <List <KunShanEntity.AreaMarket> >(AreaMarket);
                if (models != null && models.Count > 0)
                {
                    //List<KunShanEntity.AreaMarket> models = as List<KunShanEntity.AreaMarket>;
                    sql.DeleteAreaMarket("", out err);        //删除原有的数据
                    sql.DeleteKSAreaSignContact("", out err); //删除原有的经用户数据
                    KunShanEntity.SignContact indata = new KunShanEntity.SignContact();
                    KunShanEntity.AreaMarket  AM     = new KunShanEntity.AreaMarket();
                    int markcount = 0;
                    for (int i = 0; i < models.Count; i++)
                    {
                        //目前MarketRef只有为1或者2的时候才有经营户数据
                        //if (!models[i].MarketRef.Equals("1") && !models[i].MarketRef.Equals("2"))
                        //{
                        //    continue;
                        //}
                        AM.Abbreviation = models[i].Abbreviation;
                        AM.LicenseNo    = models[i].LicenseNo;
                        AM.MarketName   = models[i].MarketName;
                        AM.MarketRef    = getmarket(models[i].MarketRef);

                        sql.InAreaMarket(AM, out err);
                        //根据主体单位获取经营户信息
                        string AreaSignContact = string.Empty;
                        KunShanEntity.GetAreaSignContactReqyest.webService getAreaSignContactReqyest = new KunShanEntity.GetAreaSignContactReqyest.webService();
                        getAreaSignContactReqyest.request           = new KunShanEntity.GetAreaSignContactReqyest.Request();
                        getAreaSignContactReqyest.request.LicenseNo = models[i].LicenseNo;
                        getAreaSignContactReqyest.head          = new KunShanEntity.GetAreaSignContactReqyest.Head();
                        getAreaSignContactReqyest.head.name     = Global.ServerName;
                        getAreaSignContactReqyest.head.password = Global.MD5(Global.ServerPassword);
                        response        = XmlHelper.EntityToXml <KunShanEntity.GetAreaSignContactReqyest.webService>(getAreaSignContactReqyest);
                        AreaSignContact = webserver.GetAreaSignContact(response);
                        if ("-1001|您市场在签约有效期内没有经营户!" == AreaSignContact)
                        {
                            continue;
                        }
                        List <KunShanEntity.SignContact> _models = JsonHelper.JsonToEntity <List <KunShanEntity.SignContact> >(AreaSignContact);
                        if (_models != null && _models.Count > 0)
                        {
                            for (int j = 0; j < _models.Count; j++)
                            {
                                indata.LicenseNo    = AM.LicenseNo;
                                indata.Abbreviation = AM.Abbreviation;
                                indata.MarketName   = AM.MarketName;
                                indata.MarketRef    = AM.MarketRef;

                                indata.PositionDistrictName = _models[j].PositionDistrictName;
                                indata.PositionNo           = _models[j].PositionNo;
                                indata.DABH       = _models[j].DABH;
                                indata.Contactor  = _models[j].Contactor;
                                indata.ContactTel = _models[j].ContactTel;


                                sql.InKSAreaSignContact(indata, out err);
                                markcount = markcount + 1;
                            }
                        }
                        //System.Console.WriteLine(string.Format("GetAreaSignContactReqyest-Response:{0}", AreaSignContact));
                    }

                    MessageBox.Show("经营户信息下载成功", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    searchKSmanage("");
                }
                else
                {
                    MessageBox.Show(AreaMarket + "\r\n请确保输入的用户名与密码无误!", "下载提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                btnOperators.Enabled = true;
            }
            btnOperators.Enabled = true;
        }
Example #2
0
        /// <summary>
        /// 通信测试
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnCommunicate_Click(object sender, EventArgs e)
        {
            try
            {
                BtnCommunicate.Enabled = false;
                if (Global.linkNet() == false)
                {
                    MessageBox.Show("无法连接到互联网,请检查网络连接!", "系统提示");
                    BtnCommunicate.Enabled = true;
                    return;
                }

                if (Txt_Url.Text.Trim() == "")
                {
                    MessageBox.Show("服务器地址不能为空", "提示");
                    BtnCommunicate.Enabled = true;
                    return;
                }
                if (Txt_User.Text.Trim() == "")
                {
                    MessageBox.Show("用户名不能为空", "提示");
                    BtnCommunicate.Enabled = true;
                    return;
                }
                if (Txt_PassWord.Text.Trim() == "")
                {
                    MessageBox.Show("密码不能为空", "提示");
                    BtnCommunicate.Enabled = true;
                    return;
                }
                if (txtManufacture.Text.Trim() == "")
                {
                    MessageBox.Show("设备厂家不能为空", "提示");
                    BtnCommunicate.Enabled = true;
                    return;
                }
                if (txtMachineModel.Text.Trim() == "")
                {
                    MessageBox.Show("设备型号不能为空", "提示");
                    BtnCommunicate.Enabled = true;
                    return;
                }
                if (txtMachineSerial.Text.Trim() == "")
                {
                    MessageBox.Show("设备系列号不能为空", "提示");
                    BtnCommunicate.Enabled = true;
                    return;
                }

                Global.ServerAdd      = Txt_Url.Text.Trim();
                Global.ServerName     = Txt_User.Text.Trim();
                Global.ServerPassword = Txt_PassWord.Text.Trim();
                //Global.DetectUnit = txtDetectUnit.Text.Trim();//检测单位

                string address = Txt_Url.Text.Trim();
                //if (address.Substring(address.Length - 1, 1) == "/")
                //{
                //    address = address + "sDataInfrace.asmx";
                //}
                //else
                //{
                //    address = address + "/sDataInfrace.asmx";
                //}
                // 保存 applicationSettings 范围的设置
                if (address != "")
                {
                    string configFileName      = AppDomain.CurrentDomain.BaseDirectory + "数据采集系统.exe.config";
                    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                    doc.Load(configFileName);
                    string             configString = @"configuration/applicationSettings/WorkstationUI.Properties.Settings/setting[@name='数据采集系统_com_szscgl_ncp_sDataInfrace']/value";
                    System.Xml.XmlNode configNode   = doc.SelectSingleNode(configString);
                    if (configNode != null)
                    {
                        configNode.InnerText = address;
                        doc.Save(configFileName);
                        // 刷新应用程序设置,这样下次读取时才能读到最新的值。
                        Properties.Settings.Default.Reload();
                    }
                }
                KunShanEntity.GetTokenRequest.webService getTokenRequest = new KunShanEntity.GetTokenRequest.webService();
                getTokenRequest.request          = new KunShanEntity.GetTokenRequest.Request();
                getTokenRequest.request.name     = Global.ServerName;
                getTokenRequest.request.password = Global.MD5(Global.ServerPassword);
                string response = XmlHelper.EntityToXml <KunShanEntity.GetTokenRequest.webService>(getTokenRequest);
                //签到 获取令牌
                com.szscgl.ncp.sDataInfrace webserver = new com.szscgl.ncp.sDataInfrace();
                string ReturnMessage = webserver.checkIn(response);
                KunShanEntity.GetTokenResponse.webService getTokenResponse = XmlHelper.XmlToEntity <KunShanEntity.GetTokenResponse.webService>(ReturnMessage);
                if (getTokenResponse != null && getTokenResponse.response.error.Length == 0 && getTokenResponse.response.tokenNo.Length > 0)
                {
                    Global.Token = getTokenResponse.response.tokenNo;
                }
                else if (getTokenResponse.response.error.Length > 0)
                {
                    MessageBox.Show("通信失败:" + getTokenResponse.response.error);
                    //errMsg = getTokenResponse.response.error;
                }
                //获取市场信息
                if (getTokenResponse.response.error.Length == 0)
                {
                    KunShanEntity.QueryMarketRequest.webService getQueryMarket = new KunShanEntity.QueryMarketRequest.webService();
                    getQueryMarket.request          = new KunShanEntity.QueryMarketRequest.Request();
                    getQueryMarket.request.name     = Global.ServerName;
                    getQueryMarket.request.password = Global.MD5(Global.ServerPassword);
                    response = XmlHelper.EntityToXml <KunShanEntity.QueryMarketRequest.webService>(getQueryMarket);
                    //System.Console.WriteLine(string.Format("QueryMarket-Request:{0}", response));
                    string rtnweb = webserver.QueryMarket(response);
                    KunShanEntity.QueryMarketResponse.Response market = null;
                    market = JsonHelper.JsonToEntity <KunShanEntity.QueryMarketResponse.Response>(rtnweb.Replace("[", "").Replace("]", ""));
                    if (market != null)
                    {
                        txtDetectUnit.Text   = market.MarketName;
                        txtDetectUnitNo.Text = market.LicenseNo;
                        Global.DetectUnit    = market.MarketName;
                        Global.DetectUnitNo  = market.LicenseNo;
                        Global.communicate   = "通信测试";
                        MessageBox.Show("通讯成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                Communication();
                //ReturnMessage=clsHpptPost.BeihaiCommunicateTest(Global.ServerAdd, Global.ServerName, Global.ServerPassword, 1, out err);
                //if (ReturnMessage.Contains("status"))
                //{
                //    clsCommunication com = JsonHelper.JsonToEntity<clsCommunication>(ReturnMessage);
                //    if (com.status == "1")
                //    {
                //        Global.CheckUnitcode = com.unit;
                //        txtOrganizeNo.Text = Global.CheckUnitcode;
                //        MessageBox.Show("通信测试成功!","系统提示",MessageBoxButtons.OK ,MessageBoxIcon.Information);
                //    }
                //}
                //else
                //{
                //    MessageBox.Show("通信测试失败,请检查设置!","提示");
                //}

                // 保存 applicationSettings 范围的设置
                //string configFileName = AppDomain.CurrentDomain.BaseDirectory + "数据采集系统.exe.config";
                //System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                //doc.Load(configFileName);
                //string configString = @"configuration/applicationSettings/WorkstationUI.Properties.Settings/setting[@name='数据采集系统_WebReference_PutService']/value";
                //System.Xml.XmlNode configNode = doc.SelectSingleNode(configString);
                //if (configNode != null)
                //{
                //    configNode.InnerText = Global.ServerAdd;
                //    doc.Save(configFileName);
                //    // 刷新应用程序设置,这样下次读取时才能读到最新的值。
                //    Properties.Settings.Default.Reload();
                //}


                //this.Close();
                BtnCommunicate.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                BtnCommunicate.Enabled = true;
            }
        }