Exemplo n.º 1
0
        public object Value(string name)
        {
            EPField f = this[name];

            if (f != null)
            {
                f.Value = _links.GetValue(name);
                return(f.Value);
            }
            return(_links.GetValue(name));
        }
        public string ReceiveData(DataTable tblSrc, bool bSilent)
        {
            string error = null;

            System.IO.StreamWriter sw = null;
            if (tblSrc == null)
            {
                return("Source data is null");
            }
            if (tblSrc.Columns.Count == 0)
            {
                return("Source data is empty");
            }
            try
            {
                string sf           = _links.GetValue(FILENAME) as string;
                bool   bWriteHeader = HasHeader;
                if (bWriteHeader)
                {
                    if (System.IO.File.Exists(sf))
                    {
                        System.IO.FileInfo fi = new System.IO.FileInfo(sf);
                        if (fi.Length > 0)
                        {
                            bWriteHeader = false;
                        }
                    }
                }
                System.Text.StringBuilder sb;
                //
                sw = new System.IO.StreamWriter(sf, _bAppend, EncodeUtility.GetEncoding(EncodingType), BufferSize);
                if (bWriteHeader)
                {
                    sb = new System.Text.StringBuilder();
                    sb.Append(DataTransferConvert.Encode(_delimiter, tblSrc.Columns[0].ColumnName));
                    for (int i = 1; i < tblSrc.Columns.Count; i++)
                    {
                        sb.Append(DataTransferConvert.Delimiter(_delimiter));
                        sb.Append(DataTransferConvert.Encode(_delimiter, tblSrc.Columns[i].ColumnName));
                    }
                    sw.WriteLine(sb.ToString());
                }
                for (int r = 0; r < tblSrc.Rows.Count; r++)
                {
                    sb = new System.Text.StringBuilder();
                    sb.Append(DataTransferConvert.Encode(_delimiter, StringUtility.ToString(tblSrc.Rows[r][0])));
                    for (int i = 1; i < tblSrc.Columns.Count; i++)
                    {
                        sb.Append(DataTransferConvert.Delimiter(_delimiter));
                        sb.Append(DataTransferConvert.Encode(_delimiter, StringUtility.ToString(tblSrc.Rows[r][i])));
                    }
                    sw.WriteLine(sb.ToString());
                }
            }
            catch (Exception er)
            {
                error = ExceptionLimnorDatabase.FormExceptionText(er, "Error saving data to file {0}", Filename);
                TraceLogClass.TraceLog.ShowMessageBox = !bSilent;
                TraceLogClass.TraceLog.Log(er);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
            }
            return(error);
        }