예제 #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            uninfeDummy.ClearControls(this, true, true);

            foreach (var estado in Propriedade.Estados)
            {
                this.edtUF.Items.Add(estado.UF);
            }
            this.edtUF.SelectedIndex = 0;

            var      _PadroesDataSource = new List <PadroesDataSource>();
            XElement axml = XElement.Load(Propriedade.NomeArqXMLWebService_NFSe);
            var      xs   = (from p in axml.Descendants(NFe.Components.NFeStrConstants.Estado)
                             where p.Attribute(NFe.Components.TpcnResources.UF.ToString()).Value == "XX" &&
                             p.Attribute(NFe.Components.TpcnResources.ID.ToString()).Value == p.Attribute(NFe.Components.NFeStrConstants.Padrao).Value
                             orderby p.Attribute(NFe.Components.NFeStrConstants.Padrao).Value
                             select p);

            foreach (var item in xs)
            {
                PadroesNFSe type = WebServiceNFSe.GetPadraoFromString(item.Attribute(NFe.Components.NFeStrConstants.Padrao).Value);
                _PadroesDataSource.Add(new PadroesDataSource {
                    fromType = type.ToString(), fromDescription = EnumHelper.GetEnumItemDescription(type)
                });
            }

            this.edtPadrao.Sorted        = false;
            this.edtPadrao.DataSource    = _PadroesDataSource;// WebServiceNFSe.PadroesNFSeListDataSource.Where(p => p.fromType != PadroesNFSe.NaoIdentificado.ToString()).ToList();
            this.edtPadrao.ValueMember   = "fromType";
            this.edtPadrao.DisplayMember = "fromDescription";

            this.edtPadrao.SelectedIndex = 0;
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.edtCodMun.Focus();
            if (Functions.CodigoParaUF(Convert.ToInt32(this.edtCodMun.Text.Substring(0, 2))) != this.edtUF.SelectedItem.ToString())
            {
                MessageBox.Show("Código do IBGE diverge da UF");
                return;
            }
            if (this.edtMunicipio.Text == "")
            {
                MessageBox.Show("Nome do município deve ser informado");
                this.edtMunicipio.Focus();
                return;
            }

            foreach (Municipio mun in Propriedade.Municipios)
            {
                if (mun.CodigoMunicipio.ToString() == this.edtCodMun.Text)
                {
                    MessageBox.Show("Código IBGE já definido no municipio \"" + mun.Nome + "\"");
                    return;
                }
            }

            try
            {
                WebServiceNFSe.SalvarXMLMunicipios(this.edtUF.SelectedItem.ToString(), this.edtMunicipio.Text, Convert.ToInt32(this.edtCodMun.Text), this.edtPadrao.SelectedItem.ToString(), false);
                RefreshMunicipios();
                this.button2.PerformClick();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int    codmun = Convert.ToInt32((sender as DataGridView).Rows[e.RowIndex].Cells[this.colIBGE.Index].Value);
                string cidade = (sender as DataGridView).Rows[e.RowIndex].Cells[this.colNome.Index].Value.ToString().Trim();
                string padrao = (sender as DataGridView).Rows[e.RowIndex].Cells[this.colPadrao.Index].Value.ToString();
                string uf     = Functions.CodigoParaUF(Convert.ToInt32(codmun.ToString().Substring(0, 2)));

                WebServiceNFSe.SalvarXMLMunicipios(uf, cidade, codmun, padrao, false);

                string cUF = ((ComboElem)(new System.Collections.ArrayList(this.arrUF))[this.comboUf.SelectedIndex]).Valor;
                if (cUF == uf)
                {
                    for (int n = 0; n < this.metroGrid1.RowCount; ++n)
                    {
                        if (this.metroGrid1.Rows[n].Cells[0].Value.ToString() == codmun.ToString())
                        {
                            this.metroGrid1.Rows[n].Cells[this.colPadrao.Index].Value = padrao;
                            break;
                        }
                    }
                }
                if (padrao == PadroesNFSe.NaoIdentificado.ToString())
                {
                    umunicipio.RefreshGrid2();
                }
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm, ex.Message, "");
            }
        }
예제 #4
0
파일: userGrid2.cs 프로젝트: Klegy/uninfe
        private void dgvDireto_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int    codmun = Convert.ToInt32((sender as DataGridView).Rows[e.RowIndex].Cells[this.colIBGE_D.Index].Value);
                string cidade = (sender as DataGridView).Rows[e.RowIndex].Cells[this.colNome_D.Index].Value.ToString().Trim();
                string padrao = (sender as DataGridView).Rows[e.RowIndex].Cells[this.colPadrao_D.Index].Value.ToString();
                string uf     = Functions.CodigoParaUF(Convert.ToInt32(codmun.ToString().Substring(0, 2)));

                if (!padrao.Equals(currpadrao))
                {
                    var geral = WebServiceNFSe.PadroesNFSeUnicoWSDLDataSource.FirstOrDefault(w => w.fromType == padrao);

                    if (geral != null)/*padrao == PadroesNFSe.NaoIdentificado.ToString() ||
                                       * padrao == PadroesNFSe.BETHA.ToString() ||
                                       * padrao == PadroesNFSe.GINFES.ToString() ||
                                       * padrao == PadroesNFSe.EQUIPLANO.ToString() ||
                                       * padrao == PadroesNFSe.ABASE.ToString())*/
                    {
                        WebServiceNFSe.SalvarXMLMunicipios(uf, cidade, codmun, padrao, true);
                        ///
                        /// remove o municipio da grade
                        this.metroGrid1.Rows.RemoveAt(e.RowIndex);
                    }
                    else
                    {
                        ///
                        /// novo [uf+padrao+municipio] está no arquivo webservice.xml?
                        ///
                        if (System.IO.File.Exists(Propriedade.NomeArqXMLWebService_NFSe))
                        {
                            var axml = XElement.Load(Propriedade.NomeArqXMLWebService_NFSe);
                            var s    = (from p in axml.Descendants(NFeStrConstants.Estado)
                                        where   (string)p.Attribute(TpcnResources.UF.ToString()) == uf &&
                                        (string)p.Attribute(TpcnResources.ID.ToString()) == codmun.ToString() &&
                                        (string)p.Attribute(NFeStrConstants.Padrao) == WebServiceNFSe.GetPadraoFromString(padrao).ToString()
                                        select p).FirstOrDefault();
                            if (s == null)
                            {
                                throw new Exception(@"Padrão não pode ser alterado, já que ele não está configurado no arquivo 'NFSe\WebService.xml'.");
                            }

                            WebServiceNFSe.SalvarXMLMunicipios(uf, cidade, codmun, padrao, true);
                        }
                        else
                        {
                            throw new Exception("Padrão não pode ser alterado, entre em contato com a Unimake.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                (sender as DataGridView).Rows[e.RowIndex].Cells[this.colPadrao_D.Index].Value = currpadrao;
                MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm, ex.Message, "");
            }
        }
예제 #5
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int    codmun = Convert.ToInt32((sender as DataGridView).Rows[e.RowIndex].Cells[this.colIBGE.Index].Value);
                string cidade = (sender as DataGridView).Rows[e.RowIndex].Cells[this.colNome.Index].Value.ToString().Trim();
                string padrao = (sender as DataGridView).Rows[e.RowIndex].Cells[this.colPadrao.Index].Value.ToString();
                string uf     = Functions.CodigoParaUF(Convert.ToInt32(codmun.ToString().Substring(0, 2)));

                if (padrao.Equals(currpadrao))
                {
                    return;
                }

                WebServiceNFSe.SalvarXMLMunicipios(uf, cidade, codmun, padrao, false);

                if (padrao != PadroesNFSe.NaoIdentificado.ToString())
                {
                    ///
                    /// remove o municipio da grade
                    this.metroGrid1.Rows.RemoveAt(e.RowIndex);
                }

                /*
                 *
                 * WANDREY: nao sei pq desse codigo abaixo...
                 *
                 * string cUF = ((ComboElem)(new System.Collections.ArrayList(this.arrUF))[this.comboUf.SelectedIndex]).Valor;
                 * if (cUF == uf)
                 * {
                 *  for (int n = 0; n < this.metroGrid1.RowCount; ++n)
                 *      if (this.metroGrid1.Rows[n].Cells[0].Value.ToString() == codmun.ToString())
                 *      {
                 *          this.metroGrid1.Rows[n].Cells[this.colPadrao.Index].Value = padrao;
                 *          break;
                 *      }
                 * }
                 * if (padrao == PadroesNFSe.NaoIdentificado.ToString())
                 * {
                 *  umunicipio.RefreshGrid2(); //nao precisa pq o refresh será efetuando quando se muda a tabsheet
                 * }
                 */
            }
            catch (Exception ex)
            {
                (sender as DataGridView).Rows[e.RowIndex].Cells[this.colPadrao.Index].Value = currpadrao;
                MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm, ex.Message, "");
            }
        }
예제 #6
0
        private void dgvDireto_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int    codmun = Convert.ToInt32((sender as DataGridView).Rows[e.RowIndex].Cells[this.colIBGE_D.Index].Value);
                string cidade = (sender as DataGridView).Rows[e.RowIndex].Cells[this.colNome_D.Index].Value.ToString().Trim();
                string padrao = (sender as DataGridView).Rows[e.RowIndex].Cells[this.colPadrao_D.Index].Value.ToString();
                string uf     = Functions.CodigoParaUF(Convert.ToInt32(codmun.ToString().Substring(0, 2)));

                WebServiceNFSe.SalvarXMLMunicipios(uf, cidade, codmun, padrao, true);
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(uninfeDummy.mainForm, ex.Message, "");
            }
        }
예제 #7
0
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int    codmun = Convert.ToInt32((sender as DataGridView).Rows[e.RowIndex].Cells[0].Value);
                string cidade = (sender as DataGridView).Rows[e.RowIndex].Cells[1].Value.ToString().Trim();
                string padrao = (sender as DataGridView).Rows[e.RowIndex].Cells[2].Value.ToString();
                string uf     = Functions.CodigoParaUF(Convert.ToInt32(codmun.ToString().Substring(0, 2)));

                WebServiceNFSe.SalvarXMLMunicipios(uf, cidade, codmun, padrao, this.tabControl1.SelectedIndex == 1);

                if (tabControl1.SelectedIndex == 1)
                {
                    string cUF = ((ComboElem)(new System.Collections.ArrayList(arrUF))[comboUf.SelectedIndex]).Valor;
                    if (cUF == uf)
                    {
                        for (int n = 0; n < dataGridView1.RowCount; ++n)
                        {
                            if (dataGridView1.Rows[n].Cells[0].Value.ToString() == codmun.ToString())
                            {
                                dataGridView1.Rows[n].Cells[2].Value = padrao;
                                break;
                            }
                        }
                    }
                    if (padrao == PadroesNFSe.NaoIdentificado.ToString())
                    {
                        ///
                        /// a criacao de um timer foi um arremedo que fiz para que o municipio seja excluido da grade
                        /// tentei excluir diretamente ou dar um rebuild, mas este componente dá um erro de recursividade.
                        timerRefresh       = new Timer();
                        timerRefresh.Tick += new EventHandler(timerRefresh_Tick);
                        timerRefresh.Start();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #8
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            this.edtCodMun.Focus();
            if (Functions.CodigoParaUF(Convert.ToInt32(this.edtCodMun.Text.Substring(0, 2))) != this.edtUF.SelectedItem.ToString())
            {
                MetroFramework.MetroMessageBox.Show(this, "Código do IBGE diverge da UF", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.edtMunicipio.Text == "")
            {
                MetroFramework.MetroMessageBox.Show(this, "Nome do município deve ser informado", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.edtMunicipio.Focus();
                return;
            }

            foreach (Municipio mun in Propriedade.Municipios)
            {
                if (mun.CodigoMunicipio.ToString() == this.edtCodMun.Text)
                {
                    MetroFramework.MetroMessageBox.Show(this, "Código IBGE já definido no municipio \"" + mun.Nome + "\"", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            try
            {
                WebServiceNFSe.SalvarXMLMunicipios(this.edtUF.SelectedItem.ToString(),
                                                   this.edtMunicipio.Text,
                                                   Convert.ToInt32(this.edtCodMun.Text),
                                                   (this.edtPadrao.SelectedItem as PadroesDataSource).fromType,
                                                   false);

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(null, ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #9
0
        /// <summary>
        /// Carrega a lista de webservices definidos no arquivo WebService.XML
        /// </summary>
        public static bool CarregaWebServicesList()
        {
            bool atualizaWSDL = false;

            if (webServicesList == null)
            {
                webServicesList = new List <webServices>();

                XmlDocument doc = new XmlDocument();
                /// danasa 1-2012
                if (Propriedade.TipoAplicativo == TipoAplicativo.Nfse)
                {
                    Propriedade.Municipios = null;
                    Propriedade.Municipios = new List <Municipio>();

                    if (File.Exists(Propriedade.NomeArqXMLMunicipios))
                    {
                        doc.Load(Propriedade.NomeArqXMLMunicipios);
                        XmlNodeList estadoList = doc.GetElementsByTagName("Registro");
                        foreach (XmlNode registroNode in estadoList)
                        {
                            XmlElement registroElemento = (XmlElement)registroNode;
                            if (registroElemento.Attributes.Count > 0)
                            {
                                int    IDmunicipio = Convert.ToInt32(registroElemento.Attributes[0].Value);
                                string Nome        = registroElemento.Attributes[1].Value;
                                string Padrao      = registroElemento.Attributes[2].Value;
                                string UF          = Functions.CodigoParaUF(Convert.ToInt32(IDmunicipio.ToString().Substring(0, 2))).Substring(0, 2);

                                ///
                                /// danasa 9-2013
                                /// verifica se o 'novo' padrao existe, nao existindo retorna para atualizar os wsdl's dele
                                string dirSchemas = Path.Combine(Propriedade.PastaExecutavel, "schemas\\NFSe\\" + Padrao);
                                if (!Directory.Exists(dirSchemas))
                                {
                                    atualizaWSDL = true;
                                }
                                PadroesNFSe pdr = WebServiceNFSe.GetPadraoFromString(Padrao);

                                ///
                                /// adiciona na lista que será usada na manutencao
                                Propriedade.Municipios.Add(new Municipio(IDmunicipio, UF, Nome, pdr));

                                webServices wsItem = new webServices(IDmunicipio, Nome, UF);

                                //PreencheURLw(wsItem.URLHomologacao, "URLHomologacao", WebServiceNFSe.URLHomologacao(pdr), "");
                                //PreencheURLw(wsItem.URLProducao, "URLProducao", WebServiceNFSe.URLProducao(pdr), "");
                                PreencheURLw(wsItem.LocalHomologacao, "LocalHomologacao", WebServiceNFSe.WebServicesHomologacao(pdr, IDmunicipio), "");
                                PreencheURLw(wsItem.LocalProducao, "LocalProducao", WebServiceNFSe.WebServicesProducao(pdr, IDmunicipio), "");

                                webServicesList.Add(wsItem);
                            }
                        }
                        if (webServicesList.Count > 0)
                        {
                            ///
                            /// nao vou sair daqui pq pode ser que no "Webservice.xml" tenha algum municipio
                            /// que o usuário nao tenha incluido
                            ///
                            //return;
                        }
                    }
                }
                /// danasa 1-2012

                if (File.Exists(Propriedade.NomeArqXMLWebService))
                {
                    doc.Load(Propriedade.NomeArqXMLWebService);
                    XmlNodeList estadoList = doc.GetElementsByTagName("Estado");
                    foreach (XmlNode estadoNode in estadoList)
                    {
                        XmlElement estadoElemento = (XmlElement)estadoNode;
                        if (estadoElemento.Attributes.Count > 0)
                        {
                            if (estadoElemento.Attributes[2].Value != "XX")
                            {
                                int    ID   = Convert.ToInt32(estadoElemento.Attributes[0].Value);
                                string Nome = estadoElemento.Attributes[1].Value;
                                string UF   = estadoElemento.Attributes[2].Value;

                                /// danasa 1-2012
                                ///
                                /// verifica se o ID já está na lista
                                /// isto previne que no xml de configuracao tenha duplicidade e evita derrubar o programa
                                ///
                                bool jahExiste = false;
                                foreach (webServices temp in webServicesList)
                                {
                                    if (temp.ID == ID)
                                    {
                                        jahExiste = true;
                                        break;
                                    }
                                }
                                if (jahExiste)
                                {
                                    continue;
                                }

                                webServices wsItem = new webServices(ID, Nome, UF);
                                XmlNodeList urlList;

                                #region URL´s de Homologação
                                //urlList = estadoElemento.GetElementsByTagName("URLHomologacao");
                                //if (urlList.Count > 0)
                                //    PreencheURLw(wsItem.URLHomologacao, "URLHomologacao", urlList.Item(0).OuterXml, UF);
                                #endregion

                                #region URL´s de produção
                                //urlList = estadoElemento.GetElementsByTagName("URLProducao");
                                //if (urlList.Count > 0)
                                //    PreencheURLw(wsItem.URLProducao, "URLProducao", urlList.Item(0).OuterXml, UF);
                                #endregion

                                #region WSDL´s locais de Homologação
                                urlList = estadoElemento.GetElementsByTagName("LocalHomologacao");
                                if (urlList.Count > 0)
                                {
                                    PreencheURLw(wsItem.LocalHomologacao, "LocalHomologacao", urlList.Item(0).OuterXml, UF);
                                }
                                #endregion

                                #region WSDL´s locais de Produção
                                urlList = estadoElemento.GetElementsByTagName("LocalProducao");
                                if (urlList.Count > 0)
                                {
                                    PreencheURLw(wsItem.LocalProducao, "LocalProducao", urlList.Item(0).OuterXml, UF);
                                }
                                #endregion

                                webServicesList.Add(wsItem);

                                // danasa 1-2012
                                if (Propriedade.TipoAplicativo == TipoAplicativo.Nfse)
                                {
                                    ///
                                    /// adiciona na lista que será usada na manutencao
                                    foreach (string p0 in WebServiceNFSe.PadroesNFSeList)
                                    {
                                        if (p0 != PadroesNFSe.NaoIdentificado.ToString())
                                        {
                                            if (wsItem.LocalHomologacao.RecepcionarLoteRps.ToLower().IndexOf(p0.ToLower()) > 0 ||
                                                wsItem.LocalProducao.RecepcionarLoteRps.ToLower().IndexOf(p0.ToLower()) > 0)
                                            {
                                                Propriedade.Municipios.Add(new Municipio(ID, UF, Nome, WebServiceNFSe.GetPadraoFromString(p0)));
                                                break;
                                            }
                                        }
                                    }
                                }
                                // danasa 1-2012
                            }
                        }
                    }
                }
            }
            return(atualizaWSDL);
        }