示例#1
0
    public static int LoadCount()
    {
        try
        {
            XmlDocument   doc = new XmlDocument();
            XmlNode       node;
            XmlNodeReader reader;
            doc.Load("Emails.xml");

            node   = doc.DocumentElement.SelectSingleNode("Count");
            reader = new XmlNodeReader(node);

            while (reader.Read())
            {
                switch (reader.Name)
                {
                case "I":
                {
                    string s = (string)reader.ReadString();
                    return((int)Convert.ToInt64(s));

                    break;
                }
                }
            }
        }
        catch
        {
            Console.WriteLine("Loading of emails.xml has failed!!!");
        }

        return(0);
    }
示例#2
0
        public void NodeReaderReadStringWithEmptyXml()
        {
            var xmlDoc     = new XmlDocument();
            var nodeReader = new XmlNodeReader(xmlDoc);

            Assert.Throws <InvalidOperationException>(() => {
                nodeReader.ResolveEntity();
            });
            Assert.Equal(string.Empty, nodeReader.ReadString());
        }
示例#3
0
        public virtual NvdlValidatorGenerator CreateGenerator(NvdlValidate validate, string schemaType, NvdlConfig config)
        {
            this.validate    = validate;
            this.schema_type = schemaType;
            this.config      = config;

            XmlReader schema = null;

            // FIXME: we need a bit more strict check.
            if (schemaType.Length < 5 ||
                !schemaType.EndsWith("xml") ||
                Char.IsLetter(schemaType, schemaType.Length - 4))
            {
                return(null);
            }

            string     schemaUri  = validate.SchemaUri;
            XmlElement schemaBody = validate.SchemaBody;

            if (schemaUri != null)
            {
                if (schemaBody != null)
                {
                    throw new NvdlCompileException("Both 'schema' attribute and 'schema' element are specified in a 'validate' element.", validate);
                }
                schema = GetSchemaXmlStream(schemaUri, config, validate);
            }
            else if (validate.SchemaBody != null)
            {
                XmlReader r = new XmlNodeReader(schemaBody);
                r.MoveToContent();
                r.Read();                  // Skip "schema" element
                r.MoveToContent();
                if (r.NodeType == XmlNodeType.Element)
                {
                    schema = r;
                }
                else
                {
                    schema = GetSchemaXmlStream(r.ReadString(), config, validate);
                }
            }

            if (schema == null)
            {
                return(null);
            }

            return(CreateGenerator(schema, config));
        }
示例#4
0
    public static void Main()
    {
        XmlNodeReader reader = null;

        try
        {
            //Create and load the XML document.
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<book>" +
                        "<title>Pride And Prejudice</title>" +
                        "<price>19.95</price>" +
                        "<misc/>" +
                        "</book>");

            //Load the XmlNodeReader
            reader = new XmlNodeReader(doc);

            //Parse the XML and display the text content of each of the elements.
            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (reader.IsEmptyElement)
                    {
                        Console.WriteLine("<{0}/>", reader.Name);
                    }
                    else
                    {
                        Console.Write("<{0}> ", reader.Name);
                        reader.Read();               //Read the start tag.
                        if (reader.IsStartElement()) //Handle nested elements.
                        {
                            Console.Write("\r\n<{0}>", reader.Name);
                        }
                        Console.WriteLine(reader.ReadString()); //Read the text content of the element.
                    }
                }
            }
        }

        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
        }
    }
示例#5
0
        public void NodeReaderReadStringWithEntityXml()
        {
            string        fst        = "<!ENTITY fst 'Sample String'>]>";
            string        dtd        = "<!DOCTYPE root[<!ELEMENT root (#PCDATA)>" + fst;
            string        xml        = dtd + "<root>&fst;</root>";
            XmlNodeReader nodeReader = NodeReaderTestHelper.CreateNodeReader(xml);

            Assert.True(nodeReader.Read()); //DTD Read
            Assert.True(nodeReader.Read()); //Root Element Read
            Assert.Equal("root", nodeReader.Name);
            Assert.True(nodeReader.Read()); //EntityReference Read
            Assert.Equal(ReadState.Interactive, nodeReader.ReadState);
            Assert.Equal(XmlNodeType.EntityReference, nodeReader.NodeType);
            nodeReader.ResolveEntity();
            Assert.True(nodeReader.CanResolveEntity);
            Assert.Equal("Sample String", nodeReader.ReadString());
        }
示例#6
0
    PmlElement ReadNodes(XmlNodeReader node,
                         PmlElement data,
                         string path        = "",
                         string elementName = "")
    {
        while (node.Read())
        {
            if (node.NodeType == XmlNodeType.Element)
            {
                string type = node.GetAttribute("type");
                // Directory element
                if ((type ?? string.Empty).Equals("dir", StringComparison.OrdinalIgnoreCase))
                {
                    ReadNodes(node, data,
                              (string.IsNullOrEmpty(path) ? string.Empty : (path + "/")) + node.Name,
                              node.Name);
                }
                // Link element
                else if ((type ?? string.Empty).Equals("link", StringComparison.OrdinalIgnoreCase))
                {
                    string     linkPath = node.GetAttribute("path");
                    PmlElement linkedElement;
                    if (!_loadedElements.TryGetValue(linkPath, out linkedElement))
                    {
                        linkedElement = Load(linkPath);
                    }
                    data.Add((path + "/" + node.Name).ToLower(), linkedElement.GetStringValue(node.GetAttribute("data")));
                }
                // Common data element
                else
                {
                    data.Add((path + "/" + node.Name).ToLower(), node.ReadString());
                }
            }
            else if (node.NodeType == XmlNodeType.Element)
            {
                if (node.Name.Equals(elementName, StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
            }
        }

        return(data);
    }
示例#7
0
        /// <summary>
        /// 执行Procedure
        /// </summary>
        /// <param name="commandText">Procedure名称</param>
        /// <param name="parameters">参数列表</param>
        public override void ExecuteProcedure(string commandText, ref ArrayList parameters)
        {
            OpenConnection();
            using (SqlCommand command = (SqlCommand)this.Connection.CreateCommand())
            {
                command.CommandText = commandText;
                command.CommandType = CommandType.StoredProcedure;

                object[] parameterValues = new object[parameters.Count];
                for (int i = 0; i < parameters.Count; i++)
                {
                    SqlParameter para = new SqlParameter();
                    para.ParameterName = ((ProcedureParameter)parameters[i]).Name;
                    para.SqlDbType     = CSharpType2SqlType(((ProcedureParameter)parameters[i]).Type);
                    if (((ProcedureParameter)parameters[i]).Length != 0)
                    {
                        para.Size = ((ProcedureParameter)parameters[i]).Length;
                    }
                    else
                    {
                        para.Size = 100;
                    }
                    if (((ProcedureParameter)parameters[i]).Direction != DirectionType.Input)
                    {
                        para.Direction = (ParameterDirection)System.Enum.Parse(typeof(ParameterDirection), System.Enum.GetName(typeof(DirectionType), ((ProcedureParameter)parameters[i]).Direction));
                    }
                    else
                    {
                        para.Direction = ParameterDirection.Input;
                    }
                    para.Value         = ((ProcedureParameter)parameters[i]).Value;
                    parameterValues[i] = para;
                    command.Parameters.Add(para);
                }
                if (this.Transaction != null)
                {
                    command.Transaction = (SqlTransaction)this.Transaction;
                }
#if DEBUG
                DateTime dtStart = DateTime.Now;
                string   sqlText = this.spellCommandText(command.CommandText, parameterValues);
#endif
                try
                {
                    //2006/09/12 新增 读取配置文件Log日志文件
                    XmlDocument   xmldoc = null;
                    XmlNodeReader xr     = null;
                    try
                    {
                        string constr = "";
                        if (!this.AllowSQLLog && this.SQLLogConnectString == String.Empty)
                        {
                            xmldoc = new XmlDocument();

                            xmldoc.Load(System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\dblog.xml");

                            xr = new XmlNodeReader(xmldoc);

                            while (xr.Read())
                            {
                                if (xr.GetAttribute("name") == "BS")
                                {
                                    this.AllowSQLLog = (xr.ReadString() == "false" ? false : true);
                                }
                                if (xr.GetAttribute("name") == "Constr")
                                {
                                    this.SQLLogConnectString = xr.ReadString();
                                }
                            }
                        }


                        if (this.AllowSQLLog && this.SQLLogConnectString != String.Empty)
                        {
                            //Laws Lu,2007/04/03 Log executing user
                            //db.dblog1(constr,this.spellCommandText(command.CommandText,parameterValues);
                            //db.dblog1(this.SQLLogConnectString, this.spellCommandText(command.CommandText, parameterValues), this.ExecuteUser);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.Message);
                    }
                    finally
                    {
                        if (xr != null)
                        {
                            xr.Close();
                        }
                        if (xmldoc != null)
                        {
                            xmldoc.Clone();
                        }
                    }

                    command.ExecuteNonQuery();
                    for (int i = 0; i < parameters.Count; i++)
                    {
                        if (((ProcedureParameter)parameters[i]).Direction != DirectionType.Input)
                        {
                            ((ProcedureParameter)parameters[i]).Value = ((SqlParameter)parameterValues[i]).Value;
                        }
                    }

#if DEBUG
                    DateTime dtEnd = DateTime.Now;
                    RecordLog("Execute SQL", sqlText, dtStart, dtEnd);
#endif
                }
                catch (System.Data.OleDb.OleDbException e)
                {
                    //Log.Error(e.Message + " Parameter SQL:" + this.spellCommandText(command.CommandText, parameterValues));
#if DEBUG
                    DateTime dtEnd = DateTime.Now;
                    RecordLog("Execute SQL", sqlText, dtStart, dtEnd);
#endif

                    if (e.ErrorCode == -2147217873)
                    {
                        //ExceptionManager.Raise(this.GetType(), "$ERROR_DATA_ALREADY_EXIST", e);
                        ExceptionManager.Raise(this.GetType(), "$Error_Command_Execute", e);
                    }
                    else
                    {
                        ExceptionManager.Raise(this.GetType(), "$Error_Command_Execute", e);
                    }
                }
                catch (Exception e)
                {
                    //Log.Error(e.Message + " Parameter SQL:" + this.spellCommandText(command.CommandText, parameterValues));
#if DEBUG
                    DateTime dtEnd = DateTime.Now;
                    RecordLog("Execute SQL", sqlText, dtStart, dtEnd);
#endif

                    ExceptionManager.Raise(this.GetType(), "$Error_Command_Execute", e);
                }
                finally
                {
                    //Laws Lu,2006/12/20 修改如果自动关闭为True并且不在Transaction中时才会自动关闭Connection
                    if (this.Transaction == null && AutoCloseConnection == true)
                    {
                        CloseConnection();
                    }
                }
            }
        }
示例#8
0
        public override void Execute(string commandText, string[] parameters, Type[] parameterTypes, object[] parameterValues)
        {
            OpenConnection();
            using (OracleCommand command = (OracleCommand)this.Connection.CreateCommand())
            {
                command.CommandText = this.changeParameterPerfix(commandText);

                for (int i = 0; i < parameters.Length; i++)
                {
                    if (parameterValues[i].ToString() == string.Empty)
                    {
                        parameterValues[i] = DBNull.Value;
                    }
                    command.Parameters.Add(parameters[i], CSharpType2OracleType(parameterTypes[i])).Value = parameterValues[i];
                    //					command.CommandText =   ChangeParameterPerfix(command.CommandText, parameters[i]);
                }
                if (this.Transaction != null)
                {
//					command.Transaction = (OracleTransaction)this.Transaction;
                }
                DateTime dtStart = new DateTime();
                try
                {
                    //2006/09/12 新增 读取配置文件Log日志文件
                    XmlDocument xmldoc = new XmlDocument();
                    string      constr = "";
                    xmldoc.Load(System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\dblog.xml");

                    XmlNodeReader xr = new XmlNodeReader(xmldoc);

                    while (xr.Read())
                    {
                        if (xr.GetAttribute("name") == "BS")
                        {
                            ProgramBool = xr.ReadString();
                        }
                        if (xr.GetAttribute("name") == "Constr")
                        {
                            constr = xr.ReadString();
                        }
                    }


                    if (ProgramBool == "true")
                    {
                        db.dblog1(constr, this.spellCommandText(command.CommandText, parameterValues));
                    }

                    command.ExecuteNonQuery();

                    //修改	在Debug模式下不允许Log日志文件
#if DEBUG
                    dtStart = DateTime.Now;
                    Log.Info("************StartDateTime:" + dtStart.ToString() + "," + dtStart.Millisecond);
                    Log.Info(" Parameter SQL:" + this.spellCommandText(command.CommandText, parameterValues));
#endif

#if DEBUG
                    DateTime dtEnd = DateTime.Now;
                    TimeSpan ts    = dtEnd - dtStart;
                    Log.Info("************EndDateTime:" + dtEnd.ToString() + "," + dtEnd.Millisecond + "*********"
                             + "Cost: " + ts.Seconds + ":" + ts.Milliseconds);
#endif
                }
                catch (Oracle.DataAccess.Client.OracleException e)
                {
                    //added by leon.li @20130311
                    Log.Error(e.StackTrace);
                    //end added
                    Log.Error(e.Message + " Parameter SQL:" + this.spellCommandText(command.CommandText, parameterValues));
#if DEBUG
                    DateTime dtEnd = DateTime.Now;
                    TimeSpan ts    = dtEnd - dtStart;
                    Log.Info("************EndDateTime:" + dtEnd.ToString() + "," + dtEnd.Millisecond + "*********"
                             + "Cost: " + ts.Seconds + ":" + ts.Milliseconds);
#endif
                }
                catch (Exception e)
                {
                    //added by leon.li @20130311
                    Log.Error(e.StackTrace);
                    //end added
                    Log.Error(e.Message + " Parameter SQL:" + this.spellCommandText(command.CommandText, parameterValues));
#if DEBUG
                    DateTime dtEnd = DateTime.Now;
                    TimeSpan ts    = dtEnd - dtStart;
                    Log.Info("************EndDateTime:" + dtEnd.ToString() + "," + dtEnd.Millisecond + "*********"
                             + "Cost: " + ts.Seconds + ":" + ts.Milliseconds);
#endif

                    ExceptionManager.Raise(this.GetType(), "$Error_Command_Execute", e);
                }
                finally
                {
                    if (this.Transaction == null)
                    {
                        CloseConnection();
                    }
                }
            }
        }
示例#9
0
        protected bool SetValue(string name, XmlNodeReader reader, ref bool hasAlreadyMoveToNext)
        {
            hasAlreadyMoveToNext = false;
            if (name == null || name.Length < 1)
            {
                return(false);
            }

            try
            {
                PropertyInfo pi   = this.GetType().GetProperty(name);
                Type         type = pi.PropertyType;

                if (XObjectHelper.IsXObjectType(type))
                {
                    object theproperty = this.GetType().InvokeMember(name,
                                                                     /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                                     BindingFlags.Instance | BindingFlags.GetProperty,
                                                                     null, this, new object[] { });

                    if (theproperty == null && reader.IsEmptyElement == false)
                    {
                        theproperty = type.Assembly.CreateInstance(type.FullName);
                        this.GetType().InvokeMember(name,
                                                    /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                    BindingFlags.Instance | BindingFlags.SetProperty,
                                                    null, this, new object[] { theproperty });
                    }

                    if (theproperty != null)
                    {
                        XObjectHelper.XBaseType.InvokeMember("InnerLoad",
                                                             BindingFlags.DeclaredOnly |
                                                             BindingFlags.Public | BindingFlags.NonPublic |
                                                             BindingFlags.Instance | BindingFlags.InvokeMethod,
                                                             null, theproperty, new object[] { reader, name });

                        return(true);
                    }
                }

                if (XObjectHelper.IsXObjectCollectionType(type))
                {
                    object thecollection = this.GetType().InvokeMember(name,
                                                                       /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                                       BindingFlags.Instance | BindingFlags.GetProperty,
                                                                       null, this, new object[] { });

                    if (thecollection == null && reader.IsEmptyElement == false)
                    {
                        thecollection = type.Assembly.CreateInstance(type.FullName);
                        this.GetType().InvokeMember(name,
                                                    /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                    BindingFlags.Instance | BindingFlags.SetProperty,
                                                    null, this, new object[] { thecollection });
                    }

                    if (thecollection != null)
                    {
                        XObjectHelper.XBaseType.InvokeMember("InnerLoad",
                                                             BindingFlags.DeclaredOnly |
                                                             BindingFlags.Public | BindingFlags.NonPublic |
                                                             BindingFlags.Instance | BindingFlags.InvokeMethod,
                                                             null, thecollection, new object[] { reader, name });

                        return(true);
                    }
                }

                if (type == typeof(string))
                {
                    object[] olist = pi.GetCustomAttributes(XObjectHelper.XRawXmlStringAttributeType, false);
                    if (olist != null && olist.Length > 0)
                    {
                        XRawXmlStringAttribute a = olist[0] as XRawXmlStringAttribute;
                        if (a != null && a.EnableRawXmlString)
                        {
                            string rawXmlString = reader.ReadInnerXml();
                            hasAlreadyMoveToNext = true;

                            return(SetValueEx(name, rawXmlString));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("(" + name + ") " + e.ToString());
                XObjectManager.NotifyException(this, e);
                return(false);
            }

            return(SetValueEx(name, reader.ReadString()));
        }
示例#10
0
    public static void On_Load()
    {
        try
        {
            XmlDocument   doc = new XmlDocument();
            XmlNode       node;
            XmlNodeReader reader;
            doc.Load("Emails.xml");

            int count = (int)LoadCount();

            ArrayList keys = new ArrayList();
            for (int i = 0; i < count; ++i)
            {
                node   = doc.DocumentElement.SelectSingleNode("Account" + i.ToString());
                reader = new XmlNodeReader(node);

                while (reader.Read())
                {
                    switch (reader.Name)
                    {
                    case "Name":
                    {
                        string s = (string)reader.ReadString();
                        keys.Add(s);
                        break;
                    }
                    }
                }
            }

            ArrayList vals = new ArrayList();
            for (int i = 0; i < count; ++i)
            {
                node   = doc.DocumentElement.SelectSingleNode("Email" + i.ToString());
                reader = new XmlNodeReader(node);

                while (reader.Read())
                {
                    switch (reader.Name)
                    {
                    case "E":
                    {
                        string s = (string)reader.ReadString();
                        vals.Add(s);
                        break;
                    }
                    }
                }
            }

            for (int i = 0; i < count; ++i)
            {
                string key = (string)keys[i];
                string val = (string)vals[i];

                Emails.Add(key, val);
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Console.WriteLine("Loading of emails.xml has failed!!!");
        }
    }
示例#11
0
        public override RetornoTransmitir LerRetorno(FrgNFSe nota, XmlDocument xmlResposta)
        {
            var      sucesso           = false;
            var      cancelamento      = false;
            var      numeroNF          = "";
            var      numeroRPS         = "";
            DateTime?dataEmissaoRPS    = null;
            var      situacaoRPS       = "";
            var      codigoVerificacao = "";
            var      protocolo         = "";
            long     numeroLote        = nota.Documento.TDFe.Tide.FNumeroLote;
            var      descricaoProcesso = "";
            var      descricaoErro     = "";
            var      area = EnumAreaLeitura.Nenhum;
            var      codigoErroOuAlerta = "";
            var      _EnumRespostaRPS   = EnumRespostaRPS.Nenhum;
            var      linkImpressaoAux   = string.Empty;

            var numNF = nota.Documento.TDFe.Tide.FNumeroLote.ToString();

            using (XmlReader x = new XmlNodeReader(xmlResposta))
            {
                while (x.Read())
                {
                    if (x.NodeType == XmlNodeType.Element && area != EnumAreaLeitura.Erro)
                    {
                        switch (_EnumRespostaRPS)
                        {
                        case EnumRespostaRPS.Nenhum:
                            #region "EnumRespostaRPS"
                        {
                            switch (x.Name.ToString().ToLower())
                            {
                            case "retorno":             // Consultar RPS
                                _EnumRespostaRPS = EnumRespostaRPS.ConsultarNfseRpsResposta; break;
                            }
                            break;
                        }

                            #endregion   "EnumRespostaRPS"
                        case EnumRespostaRPS.EnviarLoteRpsResposta:
                        {
                            switch (x.Name.ToString().ToLower())
                            {
                            case "protocolo":
                                protocolo = x.ReadString();
                                sucesso   = true;
                                break;

                            case "listamensagemretorno":
                            case "mensagemretorno":
                                area = EnumAreaLeitura.Erro;
                                break;
                            }
                            break;
                        }

                        case EnumRespostaRPS.ConsultarNfseRpsResposta:
                        {
                            switch (x.Name.ToString().ToLower())
                            {
                            case "codigo":
                                if (x.ReadString().ToLower().Contains("sucesso"))
                                {
                                    sucesso = true;
                                }
                                else
                                {
                                    area = EnumAreaLeitura.Erro;
                                }

                                break;

                            case "numero_nfse":
                                if (numeroNF.Equals(""))
                                {
                                    numeroNF = x.ReadString();
                                }
                                else if (numeroRPS.Equals(""))
                                {
                                    numeroRPS = x.ReadString();
                                    //long.TryParse(numeroRPS, out numeroLote);
                                }
                                break;

                            case "data_nfse":
                                DateTime emissao;
                                DateTime.TryParse(x.ReadString(), out emissao);
                                dataEmissaoRPS = emissao;
                                break;

                            case "situacao_codigo_nfse":
                                if (x.ReadString().Equals("2"))
                                {
                                    sucesso     = true;
                                    situacaoRPS = "C";
                                }
                                break;

                            case "datahoracancelamento":
                                if (cancelamento)
                                {
                                    sucesso     = true;
                                    situacaoRPS = "C";
                                }
                                break;

                            case "cod_verificador_autenticidade":
                                codigoVerificacao = x.ReadString();
                                break;

                            case "link_nfse":
                                linkImpressaoAux = x.ReadString();
                                break;

                            case "listamensagemretorno":
                            case "mensagemretorno":
                                area = EnumAreaLeitura.Erro;
                                break;
                            }
                            break;
                        }

                        case EnumRespostaRPS.CancelarNfseResposta:
                        {
                            switch (x.Name.ToString().ToLower())
                            {
                            case "cancelamento":
                                cancelamento = true;
                                break;

                            case "datahoracancelamento":
                                if (cancelamento)
                                {
                                    sucesso     = true;
                                    situacaoRPS = "C";
                                }
                                break;

                            case "numero":
                                if (numeroNF.Equals(""))
                                {
                                    numeroNF = x.ReadString();
                                }
                                else if (numeroRPS.Equals(""))
                                {
                                    numeroRPS = x.ReadString();
                                    //long.TryParse(numeroRPS, out numeroLote);
                                }
                                break;

                            case "listamensagemretorno":
                            case "mensagemretorno":
                                area = EnumAreaLeitura.Erro;
                                break;
                            }
                            break;
                        }
                        }
                    }

                    #region Erro
                    if (area == EnumAreaLeitura.Erro)
                    {
                        if (x.NodeType == XmlNodeType.Element && x.Name == "codigo")
                        {
                            codigoErroOuAlerta = x.ReadString();
                        }
                        else if (x.NodeType == XmlNodeType.Element && x.Name == "mensagem")
                        {
                            if (string.IsNullOrEmpty(descricaoErro))
                            {
                                descricaoErro      = string.Concat("[", codigoErroOuAlerta, "] ", x.ReadString());
                                codigoErroOuAlerta = "";
                            }
                            else
                            {
                                descricaoErro      = string.Concat(descricaoErro, "\n", "[", codigoErroOuAlerta, "] ", x.ReadString());
                                codigoErroOuAlerta = "";
                            }
                        }
                        else if (x.NodeType == XmlNodeType.Element && x.Name == "correcao")
                        {
                            var correcao = x.ReadString().ToString().Trim() ?? "";
                            if (correcao != "")
                            {
                                descricaoErro = string.Concat(descricaoErro, " ( Sugestão: " + correcao + " ) ");
                            }
                        }
                    }
                    #endregion Erro
                }
                x.Close();
            }

            var dhRecbto = "";
            var error    = "";
            var success  = "";

            if (dataEmissaoRPS != null && dataEmissaoRPS.Value != null)
            {
                nota.Documento.TDFe.Tide.DataEmissaoRps = dataEmissaoRPS.Value;
                nota.Documento.TDFe.Tide.DataEmissao    = dataEmissaoRPS.Value;
                dhRecbto = dataEmissaoRPS.Value.ToString();
            }

            var xMotivo = descricaoErro != "" ? string.Concat(descricaoProcesso, "[", descricaoErro, "]") : descricaoProcesso;
            if ((sucesso && !string.IsNullOrEmpty(numeroNF)) || (!string.IsNullOrEmpty(numNF) && Generico.MesmaNota(numeroNF, numNF) && situacaoRPS != ""))
            {
                sucesso = true;
                success = "Sucesso";
            }
            else
            {
                var msgRetornoAux = xMotivo;

                if ((msgRetornoAux.Contains("O numero do lote do contribuinte informado, já existe.") ||
                     msgRetornoAux.Contains("O número do lote do contribuinte informado, já existe.")) &&
                    msgRetornoAux.Contains("Protocolo:"))
                {
                    var protocoloAux = msgRetornoAux.Substring(msgRetornoAux.LastIndexOf("Protocolo: ") + 10);
                    protocoloAux = Generico.RetornarApenasNumeros(protocoloAux);

                    if (!String.IsNullOrEmpty(protocoloAux))
                    {
                        protocolo = protocoloAux;
                        xMotivo   = String.Empty;
                    }
                }

                error = xMotivo;
                if (string.IsNullOrEmpty(xMotivo))
                {
                    if (protocolo != "")
                    {
                        error = "Não foi possível finalizar a transmissão. Aguarde alguns minutos e execute um consulta para finalizar a operação. Protocolo gerado: " + protocolo.ToString().Trim();
                    }
                    else
                    {
                        error = "Não foi possível finalizar a transmissão. Tente novamente mais tarde ou execute uma consulta.";
                    }
                }
            }

            var cStat = "";
            var xml   = "";

            if (sucesso && situacaoRPS != "C")
            {
                cStat = "100";
                nota.Documento.TDFe.Tide.FStatus = EnumNFSeRPSStatus.srNormal;
                xMotivo = "NFSe Normal";
            }
            else if (sucesso && situacaoRPS == "C")
            {
                cStat = "101";
                nota.Documento.TDFe.Tide.FStatus = EnumNFSeRPSStatus.srCancelado;
                xMotivo = "NFSe Cancelada";
            }
            //if (cStat == "100" || cStat == "101")
            //{
            //var xmlRetorno = nota.MontarXmlRetorno(nota, numeroNF, protocolo);
            xml = xmlResposta.OuterXml;
            //}

            return(new RetornoTransmitir(error, success)
            {
                chave = numeroNF != "" && numeroNF != "0" ?
                        GerarChaveNFSe(nota.Documento.TDFe.TPrestador.FIdentificacaoPrestador.FEmitIBGEUF, nota.Documento.TDFe.Tide.DataEmissaoRps, nota.Documento.TDFe.TPrestador.FCnpj, numeroNF, 56) : "",
                cStat = cStat,
                xMotivo = xMotivo,
                numero = numeroNF,
                nProt = protocolo,
                xml = xml,
                digVal = codigoVerificacao,
                NumeroLote = numeroLote,
                NumeroRPS = numeroRPS,
                DataEmissaoRPS = dataEmissaoRPS,
                dhRecbto = dhRecbto,
                CodigoRetornoPref = codigoErroOuAlerta,
                LinkImpressao = linkImpressaoAux
            });
        }
示例#12
0
        //从Xml Element(association)得到相应 Association
        private Association GetAssociation(XmlNodeReader node)
        {
            int         dep = node.Depth;
            Association a   = new Association();
            //取得关联名
            string associationName = node.GetAttribute("name").Trim();

            if (associationName == null || associationName == "")
            {
                throw new PlException("Association定义错误:关联未设置 name!");
            }

            while (node.Read() && node.Depth > dep)
            {
                //若该Node是Element类型
                if (node.NodeType == XmlNodeType.Element)
                {
                    string elementName = node.Name;
                    switch (elementName)
                    {
                    case "fromClass":
                        a.FromClass = node.ReadString().Trim();
                        //未找到名为:FromClass的类的Map信息
                        if (classMaps[a.FromClass] == null)
                        {
                            string err = "关联" + associationName + "的FromClass:" +
                                         a.FromClass + "未找到Map信息!";
                            throw new PlException(err);
                        }
                        break;

                    case "toClass":
                        a.ToClass = node.ReadString().Trim();
                        //未找到名为:ToClass的类的Map信息
                        if (classMaps[a.ToClass] == null)
                        {
                            string err = "关联" + associationName + "的ToClass:" +
                                         a.ToClass + "未找到Map信息!";
                            throw new PlException(err);
                        }
                        break;

                    case "cardinality":
                        string t = node.ReadString().Trim();
                        if (t == "oneToMany")
                        {
                            a.Cardinality = CardinalityTypes.OneToMany;
                        }
                        else
                        {
                            if (t == "oneToOne")
                            {
                                a.Cardinality = CardinalityTypes.OneToOne;
                            }
                            else
                            {
                                throw new PlException(associationName + "中不能识别的Cardinality定义!");
                            }
                        }
                        break;

                    case "target":
                        a.Target = node.ReadString().Trim();
                        break;

                    case "retrieveAutomatic":
                        if (node.ReadString().Trim() == "true")
                        {
                            a.RetrieveAutomatic = true;
                        }
                        break;

                    case "deleteAutomatic":
                        if (node.ReadString().Trim() == "true")
                        {
                            a.DeleteAutomatic = true;
                        }
                        break;

                    case "saveAutomatic":
                        if (node.ReadString().Trim() == "true")
                        {
                            a.SaveAutomatic = true;
                        }
                        break;

                    case "fromAttribute":
                        a.FromAttribute = node.ReadString().Trim();
                        break;

                    case "toAttribute":
                        a.ToAttribute = node.ReadString().Trim();
                        break;

                    default:
                        throw new PlException("associationName" + "中不能识别定义:" + elementName);
                    }
                }
            }
            if (a.Cardinality == CardinalityTypes.None)
            {
                throw new PlException(associationName + "关联中cardinality属性未设置!");
            }
            return(a);
        }
示例#13
0
        /// <summary>
        /// 执行SQL语句,并返回影响行数
        /// </summary>
        /// <param name="commandText">SQL语句</param>
        /// <param name="parameters">参数名称列表</param>
        /// <param name="parameterTypes">参数类型列表</param>
        /// <param name="parameterValues">参数值列表</param>
        /// <returns>影响行数</returns>
        public override int ExecuteWithReturn(string commandText, string[] parameters, Type[] parameterTypes, object[] parameterValues)
        {
            int iReturn = 0;

            OpenConnection();
            using (OleDbCommand command = (OleDbCommand)this.Connection.CreateCommand())
            {
                command.CommandText = this.changeParameterPerfix(commandText);

                for (int i = 0; i < parameters.Length; i++)
                {
                    command.Parameters.Add(parameters[i], CSharpType2OleDbType(parameterTypes[i])).Value = parameterValues[i];
                    //					command.CommandText =   ChangeParameterPerfix(command.CommandText, parameters[i]);
                }
                if (this.Transaction != null)
                {
                    command.Transaction = (OleDbTransaction)this.Transaction;
                }
#if DEBUG
                DateTime dtStart = DateTime.Now;
                string   sqlText = this.spellCommandText(command.CommandText, parameterValues);
#endif
                try
                {
                    //2006/09/12 新增 读取配置文件Log日志文件
                    XmlDocument   xmldoc = null;
                    XmlNodeReader xr     = null;
                    try
                    {
                        string constr = "";
                        if (!this.AllowSQLLog && this.SQLLogConnectString == String.Empty)
                        {
                            xmldoc = new XmlDocument();

                            xmldoc.Load(System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\dblog.xml");

                            xr = new XmlNodeReader(xmldoc);

                            while (xr.Read())
                            {
                                if (xr.GetAttribute("name") == "BS")
                                {
                                    this.AllowSQLLog = (xr.ReadString() == "false" ? false : true);
                                }
                                if (xr.GetAttribute("name") == "Constr")
                                {
                                    constr = xr.ReadString();
                                }
                            }
                        }


                        if (this.AllowSQLLog && this.SQLLogConnectString != String.Empty)
                        {
                            //Laws Lu,2007/04/03 Log executing user
                            //db.dblog1(constr,this.spellCommandText(command.CommandText,parameterValues);
                            db.dblog1(this.SQLLogConnectString, this.spellCommandText(command.CommandText, parameterValues), this.ExecuteUser);
                        }
                    }
                    catch (Exception ex)
                    {
                        //added by leon.li @20130311
                        Log.Error(ex.StackTrace);
                        //end added
                        Log.Error(ex.Message);
                    }
                    finally
                    {
                        if (xr != null)
                        {
                            xr.Close();
                        }
                        if (xmldoc != null)
                        {
                            xmldoc.Clone();
                        }
                    }

                    iReturn = command.ExecuteNonQuery();
#if DEBUG
                    DateTime dtEnd = DateTime.Now;
                    RecordLog("Execute SQL", sqlText, dtStart, dtEnd);
#endif
                }
                catch (System.Data.OleDb.OleDbException e)
                {
                    //added by leon.li @20130311
                    Log.Error(e.StackTrace);
                    //end added
                    Log.Error(e.Message + " Parameter SQL:" + this.spellCommandText(command.CommandText, parameterValues));
#if DEBUG
                    DateTime dtEnd = DateTime.Now;
                    RecordLog("Execute SQL", sqlText, dtStart, dtEnd);
#endif

                    if (e.ErrorCode == -2147217873)
                    {
                        //ExceptionManager.Raise(this.GetType(), "$ERROR_DATA_ALREADY_EXIST", e);
                        ExceptionManager.Raise(this.GetType(), "$Error_Command_Execute", e);
                    }
                    else
                    {
                        ExceptionManager.Raise(this.GetType(), "$Error_Command_Execute", e);
                    }
                }
                catch (Exception e)
                {
                    //added by leon.li @20130311
                    Log.Error(e.StackTrace);
                    //end added
                    Log.Error(e.Message + " Parameter SQL:" + this.spellCommandText(command.CommandText, parameterValues));
#if DEBUG
                    DateTime dtEnd = DateTime.Now;
                    RecordLog("Execute SQL", sqlText, dtStart, dtEnd);
#endif

                    ExceptionManager.Raise(this.GetType(), "$Error_Command_Execute", e);
                }
                finally
                {
                    //Laws Lu,2006/12/20 修改如果自动关闭为True并且不在Transaction中时才会自动关闭Connection
                    if (this.Transaction == null && AutoCloseConnection == true)
                    {
                        //CloseConnection();
                    }
                }
                return(iReturn);
            }
        }