Example #1
0
        public void loadData(NFe.Components.TipoAplicativo opcao, string uf)
        {
            this._tipo = opcao;
            this.uf = uf;

            listageral.Clear();
            listaEstados.Clear();

            edtEstados.SelectedIndexChanged -= metroComboBox1_SelectedIndexChanged;
            int oIndex = 0;
            try
            {
                string padraobase = NFe.Components.PadroesNFSe.NaoIdentificado.ToString();
                if (this.configname == null)
                {
                    string fn = System.IO.Path.Combine(Application.StartupPath, "uninfe_ws.xml");
                    NFe.Components.XMLIniFile xml = new NFe.Components.XMLIniFile(fn);
                    switch (this._tipo)
                    {
                        case NFe.Components.TipoAplicativo.Nfse:
                            configname = xml.ReadValue("webservice", "uninfse", "");
                            break;

                        default:
                            padraobase = "";
                            configname = xml.ReadValue("webservice", "uninfe", "");
                            this.metroLabel5.Text = "SVC";
                            this.edtPadrao.Items.Clear();
                            this.edtPadrao.Items.Add(NFe.Components.TipoEmissao.teNone.ToString());
                            this.edtPadrao.Items.Add(NFe.Components.TipoEmissao.teSVCAN.ToString());
                            this.edtPadrao.Items.Add(NFe.Components.TipoEmissao.teSVCRS.ToString());
                            break;
                    }
                    filebackup = this.configname + ".xml.bck";

                    xlabels = new List<string>();
                    ///
                    /// varre os nomes das propriedades da classe, eliminando o esquecimento quando da criacao de novas propriedades
                    /// 
                    NFe.Components.URLws temp = new NFe.Components.URLws();
                    foreach (var se in temp.GetType().GetProperties())
                    {
                        if (se.Name.StartsWith("NFe") || se.Name.StartsWith("CTe") || se.Name.StartsWith("DFe") || se.Name.StartsWith("MDFe"))
                        {
                            if (this._tipo == NFe.Components.TipoAplicativo.Nfe)
                                this.xlabels.Add(se.Name);
                        }
                        else
                            if (this._tipo == NFe.Components.TipoAplicativo.Nfse)
                                this.xlabels.Add(se.Name);
                    }

                    int X = 2;
                    foreach (var label in xlabels)
                    {
                        UserControl2 uc1 = new UserControl2();
                        this.tpProd.Controls.Add(uc1);
                        uc1.folder = System.IO.Path.GetDirectoryName(configname) + "\\producao";
                        uc1.metroLabel1.Text = label;
                        uc1.metroTextBox1.Text = label;
                        uc1.Name = "P_" + label;
                        uc1.Location = new Point(2, X);
                        uc1.Size = new System.Drawing.Size(this.tpProd.Size.Width - 20, uc1.Size.Height);

                        UserControl2 uc2 = new UserControl2();
                        this.tpHomo.Controls.Add(uc2);
                        uc2.folder = System.IO.Path.GetDirectoryName(configname) + "\\homologacao";
                        uc2.metroLabel1.Text = label;
                        uc2.metroTextBox1.Text = label;
                        uc2.Name = "H_" + label;
                        uc2.Location = new Point(2, X);
                        uc2.Size = new System.Drawing.Size(this.tpHomo.Size.Width - 20, uc2.Size.Height);

                        X += uc2.Size.Height + 4;
                    }
                }
                else
                    oIndex = edtEstados.SelectedIndex;

                if (this._tipo == NFe.Components.TipoAplicativo.Nfe)
                {
                    NFe.Components.Propriedade.Estados = null;
                    NFe.Components.Propriedade.NomeArqXMLWebService_NFe = configname;
                }
                XElement axml = XElement.Load(configname);
                var s = (from p in axml.Descendants(NFe.Components.NFeStrConstants.Estado)
                         where  (uf == null && p.Attribute(NFe.Components.TpcnResources.UF.ToString()).Value != "XX") ||
                                (uf != null && p.Attribute(NFe.Components.TpcnResources.UF.ToString()).Value == "XX")
                         orderby p.Attribute(NFe.Components.NFeStrConstants.Nome).Value
                         select p);
                foreach (var item in s)
                {
                    listaEstados.Add(new Estado
                    {
                        Nome = item.Attribute(NFe.Components.NFeStrConstants.Nome).Value,
                        ID = item.Attribute(NFe.Components.TpcnResources.ID.ToString()).Value,
                        UF = item.Attribute(NFe.Components.TpcnResources.UF.ToString()).Value,
                        svc = (this._tipo == NFe.Components.TipoAplicativo.Nfse ? "" : (item.Attribute(NFe.Components.NFeStrConstants.SVC) == null ? NFe.Components.TipoEmissao.teNone.ToString() : item.Attribute(NFe.Components.NFeStrConstants.SVC).Value)),
                        Padrao = item.Attribute(NFe.Components.NFeStrConstants.Padrao) == null ? (this._tipo == NFe.Components.TipoAplicativo.Nfse ? padraobase : "") : item.Attribute(NFe.Components.NFeStrConstants.Padrao).Value
                    });
                    listageral.Add(listaEstados[listaEstados.Count - 1].key);
                }
                edtEstados.DataSource = null;
                edtEstados.Items.Clear();
                edtEstados.DisplayMember = "text";
                edtEstados.ValueMember = NFe.Components.TpcnResources.ID.ToString();
                edtEstados.DataSource = listaEstados;
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(null, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            finally
            {
                edtEstados.SelectedIndex = oIndex;
                metroComboBox1_SelectedIndexChanged(null, null);
                edtEstados.SelectedIndexChanged += metroComboBox1_SelectedIndexChanged;
            }
        }
Example #2
0
        public void loadData(NFe.Components.TipoAplicativo opcao, string uf)
        {
            this._tipo = opcao;
            this.uf    = uf;

            listageral.Clear();
            listaEstados.Clear();

            edtEstados.SelectedIndexChanged -= metroComboBox1_SelectedIndexChanged;
            int oIndex = 0;

            try
            {
                string padraobase = NFe.Components.PadroesNFSe.NaoIdentificado.ToString();
                if (this.configname == null)
                {
                    string fn = System.IO.Path.Combine(Application.StartupPath, "uninfe_ws.xml");
                    NFe.Components.XMLIniFile xml = new NFe.Components.XMLIniFile(fn);
                    switch (this._tipo)
                    {
                    case NFe.Components.TipoAplicativo.Nfse:
                        configname = xml.ReadValue("webservice", "uninfse", "");
                        break;

                    default:
                        padraobase            = "";
                        configname            = xml.ReadValue("webservice", "uninfe", "");
                        this.metroLabel5.Text = "SVC";
                        this.edtPadrao.Items.Clear();
                        this.edtPadrao.Items.Add(NFe.Components.TipoEmissao.teNone.ToString());
                        this.edtPadrao.Items.Add(NFe.Components.TipoEmissao.teSVCAN.ToString());
                        this.edtPadrao.Items.Add(NFe.Components.TipoEmissao.teSVCRS.ToString());
                        break;
                    }
                    filebackup = this.configname + ".xml.bck";

                    xlabels = new List <string>();
                    ///
                    /// varre os nomes das propriedades da classe, eliminando o esquecimento quando da criacao de novas propriedades
                    ///
                    NFe.Components.URLws temp = new NFe.Components.URLws();
                    foreach (var se in temp.GetType().GetProperties())
                    {
                        if (se.Name.StartsWith("NFe") || se.Name.StartsWith("CTe") || se.Name.StartsWith("DFe") || se.Name.StartsWith("MDFe"))
                        {
                            if (this._tipo == NFe.Components.TipoAplicativo.Nfe)
                            {
                                this.xlabels.Add(se.Name);
                            }
                        }
                        else
                        if (this._tipo == NFe.Components.TipoAplicativo.Nfse)
                        {
                            this.xlabels.Add(se.Name);
                        }
                    }

                    int X = 2;
                    foreach (var label in xlabels)
                    {
                        UserControl2 uc1 = new UserControl2();
                        this.tpProd.Controls.Add(uc1);
                        uc1.folder             = System.IO.Path.GetDirectoryName(configname) + "\\producao";
                        uc1.metroLabel1.Text   = label;
                        uc1.metroTextBox1.Text = label;
                        uc1.Name     = "P_" + label;
                        uc1.Location = new Point(2, X);
                        uc1.Size     = new System.Drawing.Size(this.tpProd.Size.Width - 20, uc1.Size.Height);

                        UserControl2 uc2 = new UserControl2();
                        this.tpHomo.Controls.Add(uc2);
                        uc2.folder             = System.IO.Path.GetDirectoryName(configname) + "\\homologacao";
                        uc2.metroLabel1.Text   = label;
                        uc2.metroTextBox1.Text = label;
                        uc2.Name     = "H_" + label;
                        uc2.Location = new Point(2, X);
                        uc2.Size     = new System.Drawing.Size(this.tpHomo.Size.Width - 20, uc2.Size.Height);

                        X += uc2.Size.Height + 4;
                    }
                }
                else
                {
                    oIndex = edtEstados.SelectedIndex;
                }

                if (this._tipo == NFe.Components.TipoAplicativo.Nfe)
                {
                    NFe.Components.Propriedade.Estados = null;
                    NFe.Components.Propriedade.NomeArqXMLWebService_NFe = configname;
                }
                XElement axml = XElement.Load(configname);
                var      s    = (from p in axml.Descendants(NFe.Components.NFeStrConstants.Estado)
                                 where  (uf == null && p.Attribute(NFe.Components.TpcnResources.UF.ToString()).Value != "XX") ||
                                 (uf != null && p.Attribute(NFe.Components.TpcnResources.UF.ToString()).Value == "XX")
                                 orderby p.Attribute(NFe.Components.NFeStrConstants.Nome).Value
                                 select p);
                foreach (var item in s)
                {
                    listaEstados.Add(new Estado
                    {
                        Nome   = item.Attribute(NFe.Components.NFeStrConstants.Nome).Value,
                        ID     = item.Attribute(NFe.Components.TpcnResources.ID.ToString()).Value,
                        UF     = item.Attribute(NFe.Components.TpcnResources.UF.ToString()).Value,
                        svc    = (this._tipo == NFe.Components.TipoAplicativo.Nfse ? "" : (item.Attribute(NFe.Components.NFeStrConstants.SVC) == null ? NFe.Components.TipoEmissao.teNone.ToString() : item.Attribute(NFe.Components.NFeStrConstants.SVC).Value)),
                        Padrao = item.Attribute(NFe.Components.NFeStrConstants.Padrao) == null ? (this._tipo == NFe.Components.TipoAplicativo.Nfse ? padraobase : "") : item.Attribute(NFe.Components.NFeStrConstants.Padrao).Value
                    });
                    listageral.Add(listaEstados[listaEstados.Count - 1].key);
                }
                edtEstados.DataSource = null;
                edtEstados.Items.Clear();
                edtEstados.DisplayMember = "text";
                edtEstados.ValueMember   = NFe.Components.TpcnResources.ID.ToString();
                edtEstados.DataSource    = listaEstados;
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(null, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            finally
            {
                edtEstados.SelectedIndex = oIndex;
                metroComboBox1_SelectedIndexChanged(null, null);
                edtEstados.SelectedIndexChanged += metroComboBox1_SelectedIndexChanged;
            }
        }