Exemplo n.º 1
0
        private async void cmdLoad_Click(object sender, EventArgs e)
        {

            ArrayList lstData = new ArrayList();
            grdNom.AutoGenerateColumns = false;
            grdNom.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            grdNom.Columns[0].DataPropertyName = "EgaisCode";
            grdNom.Columns[1].DataPropertyName = "Shortname";
            grdNom.Columns[2].DataPropertyName = "AlcCode";
            grdNom.Columns[3].DataPropertyName = "Vol";
            grdNom.Columns[4].DataPropertyName = "Produce";
            grdNom.Columns[5].DataPropertyName = "Volum";
            string[] lines=File.ReadAllLines(@"egais_list.xml");
            List<string> wlines=new List<string>();
//            lstData.Add("EgaisCode, Shortname, Capacity,Vol, AlcCode, Producer, INN,  KPP" );

            //
            // запрос списка контрагентов
            string ip_adr, ip_port, fsrar_id;
            string url_conn;
            ip_adr = Properties.Settings.Default.ip_adr.Trim();
            ip_port = Properties.Settings.Default.ip_port.Trim();
            fsrar_id = Properties.Settings.Default.fsrar_id.Trim();
            if (ip_port.Length > 0 && ip_port.Length > 0 && fsrar_id.Length > 0)
            {
                url_conn = "http://" + ip_adr + ":" + ip_port;

                foreach (string row in lines)
                {
                    string responseString;
                    //--
                    HttpWebRequest req = WebRequest.Create(row) as HttpWebRequest;
                    req.Method = "GET";
                    try
                    {
                        WebResponse response = (HttpWebResponse)req.GetResponse();

                        using (StreamReader strd = new StreamReader(response.GetResponseStream()))
                        {
                            responseString = strd.ReadToEnd();
                        }
                        response.Close();
                    }
                    catch (WebException ee)
                    {
                        MessageBox.Show("Ошибка запроса к серверу." + ee.Message + " " + ee.Response);
                        responseString = "";
                    }

                    string myAnsXml = responseString;
                    //                MessageBox.Show(myAnsXml);
                    XmlSerializer serT = new XmlSerializer(typeof(Documents));
                    Documents docCl = new Documents();
                    docCl.Document = new DocumentsDocument();
                    docCl.Document.ItemElementName = ItemChoiceType.ReplyAP;
                    docCl.Owner = new SenderInfo() { FSRAR_ID = fsrar_id };
                    docCl.Document.Item = new ReplyAP();
                    //
                    docCl = (Documents)serT.Deserialize(new StringReader(myAnsXml));
                    //выводим визуальное представление документа
                    ReplyAP apList = (ReplyAP)docCl.Document.Item;
                    foreach (var ent in apList.Products)
                    {
                        string impname,impinn,impkpp;
                        if (ent.Importer != null)
                        {
                            if (ent.Importer.ShortName == null)
                            {
                                impname = "";
                            }
                            else
                            { impname = ent.Importer.ShortName; }
                            if (ent.Importer.INN == null)
                            {
                                impinn = "";
                            }
                            else
                            { impinn = ent.Importer.INN; }
                            if (ent.Importer.KPP == null)
                            {
                                impkpp = "";
                            }
                            else
                            { impkpp = ent.Importer.KPP; }
                        } else
                        {
                            impname = "";
                            impinn ="";
                            impkpp = "";
                        }
                        wlines.Add(ent.AlcCode.ToString() + ";" + ent.FullName + ";" + ent.Capacity.ToString() + ";" + ent.AlcVolume.ToString() + ";" + ent.ProductVCode.ToString() + ";" + ent.Producer.ShortName + ";" + ent.Producer.INN + ";" + ent.Producer.KPP+";"+impname+";"+impinn+";"+impkpp);
                        lstData.Add(new { EgaisCode = ent.AlcCode, Shortname = ent.FullName, AlcCode = ent.ProductVCode,  Vol = ent.AlcVolume, Produce = ent.Producer.ShortName, Volum = ent.Capacity }); 
                    }

                }
                bs.DataSource = lstData;
                grdNom.DataSource = bs;
                File.WriteAllLines(@"nnum.csv", wlines.ToArray(),Encoding.Default);
                MessageBox.Show("Запрос выполнен.");
            }
        }
Exemplo n.º 2
0
        private async void button1_Click(object sender, EventArgs e)
        {
            //
            // запрос списка контрагентов
            string ip_adr, ip_port, fsrar_id;
            string url_conn;
            ip_adr = Properties.Settings.Default.ip_adr.Trim();
            ip_port = Properties.Settings.Default.ip_port.Trim();
            fsrar_id = Properties.Settings.Default.fsrar_id.Trim();
            if (ip_port.Length > 0 && ip_port.Length > 0 && fsrar_id.Length > 0)
            {
                url_conn = "http://" + ip_adr + ":" + ip_port;
                if (txtINN.TextLength > 0)
                {
                    QueryParameters queryAP = new QueryParameters();
                    try
                    {
                        queryAP.Parameters = new Parameter[1] { new Parameter() };
                        queryAP.Parameters[0].Name = "ИНН";
                        queryAP.Parameters[0].Value = this.txtINN.Text;
                    }
                    catch (Exception)
                    {

                        throw;
                    }
                    //заголовок XML запроса
                    Documents doc = new Documents();
                    doc.Document = new DocumentsDocument();
                    doc.Document.ItemElementName = ItemChoiceType.QueryAP;
                    //FSRAR_ID = "020000122345"
                    doc.Owner = new SenderInfo() { FSRAR_ID = fsrar_id };
                    doc.Document.Item = queryAP;
                    StringBuilder xmlStrBld = new StringBuilder();
                    StringBuilder sb = new StringBuilder();
                    XmlWriterSettings set = new XmlWriterSettings();
                    Guid guid = Guid.NewGuid();
                    string Boundary = guid.ToString().Replace("-", "");
                    sb.AppendLine("--" + Boundary);
                    //                sb.AppendLine(String.Format("ContentDisposition: form-data; name=\"{0}\";","select.xml"));
                    sb.AppendLine("Content-Disposition: form-data; name=\"xml_file\"; filename=\"QueryAPSingle.xml\"");
                    sb.AppendLine(@"Content-Type: multipart/boundary; charset=utf-8");
                    sb.AppendLine();
                    string xmlStr;
                    set.Encoding = Encoding.UTF8;
                    set.OmitXmlDeclaration = true;
                    using (XmlWriter txtWriter = XmlWriter.Create(xmlStrBld, set))
                    {
                        XmlSerializer xmlS = new XmlSerializer(doc.GetType());
                        xmlS.Serialize(txtWriter, doc);
                        txtWriter.Flush();
                        txtWriter.Close();
                        sb.AppendLine(xmlStrBld.ToString());
                        sb.AppendLine("--" + Boundary + "--");
                        sb.AppendLine();
                        xmlStr = sb.ToString();

                    }
                    //Асинхронный вызов
//                    EgaisRequest erq = new EgaisRequest();
                    Task<string> SendXmlTask = erq.SendXml(xmlStr, url_conn, Boundary, "QueryAP", "POST");
                    string myAnsXml = await SendXmlTask;
                    //                MessageBox.Show(myAnsXml);
                    XmlSerializer serT = new XmlSerializer(typeof(Documents));
                    Documents docCl = new Documents();
                    docCl.Document = new DocumentsDocument();
                    docCl.Document.ItemElementName = ItemChoiceType.ReplyAP;
                    docCl.Owner = new SenderInfo() { FSRAR_ID = fsrar_id };
                    docCl.Document.Item = new ReplyAP();
                    //
                    docCl = (Documents)serT.Deserialize(new StringReader(myAnsXml));
                    //выводим визуальное представление документа
                    ReplyAP apList = (ReplyAP)docCl.Document.Item;
                    ArrayList lstData = new ArrayList();
                    foreach (var ent in apList.Products)
                    {
                        lstData.Add(new { EgaisCode = ent.AlcCode, Shortname = ent.FullName, AlcCode = ent.ProductVCode, Vol=ent.AlcVolume,Produce = ent.Producer.ShortName, Volum=ent.Capacity  });
                    }
                    grdNom.AutoGenerateColumns = false;
                    grdNom.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                    grdNom.Columns[0].DataPropertyName = "EgaisCode";
                    grdNom.Columns[1].DataPropertyName = "Shortname";
                    grdNom.Columns[2].DataPropertyName = "AlcCode";
                    grdNom.Columns[3].DataPropertyName = "Vol";
                    grdNom.Columns[4].DataPropertyName = "Produce";
                    grdNom.Columns[5].DataPropertyName = "Volum";

                    bs.DataSource = lstData;
                    grdNom.DataSource = bs;
                }
                else
                {
                    this.errProv.SetError(cmdNom, "ИНН должно быть заполнено!");
                }
            }
            else
            {
                MessageBox.Show("Заполните начальные установки программы!");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// по списку url с ТТН выполняет запросы, преобразовывает ответы в xml,
        /// десериализует ответы в объекты и помещает объекты в список ТТН
        /// </summary>
        /// <returns></returns>
        public async Task GetTtn() // чтение ТТН в список
        {
            string responseString;
            if (urlListTtn.Count>0)
            {
                XmlSerializer serT = new XmlSerializer(typeof(Documents));
                foreach (string url in urlListTtn)
                {
                    HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
                    req.Method = "GET";
                    try
                    {
                        WebResponse response = (HttpWebResponse)req.GetResponse();

                        using (StreamReader strd = new StreamReader(response.GetResponseStream()))
                        {
                            responseString = strd.ReadToEnd();
                            Documents docSer = new Documents();
                            docSer.Document = new DocumentsDocument();
                            docSer.Document.ItemElementName = ItemChoiceType.WayBill;
                            docSer.Owner = new SenderInfo() { FSRAR_ID = fsrar_id };
                            docSer.Document.Item = new WayBillType();
                            docSer = (Documents)serT.Deserialize(new StringReader(responseString));
                            docTTN.Add(docSer);
                        }
                        response.Close();
                    }
                    catch (WebException e)
                    {
                        MessageBox.Show("Ошибка запроса к серверу." + e.Message + " " + e.Response);
                        responseString = "";
                    }
                }
            }
        }