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;
        }