Example #1
0
        public bool ExportToTxt()
        {
            bool flag;

            try
            {
                string str = string.Concat("SELECT COUNT(*) from ", this.TableName);
                System.Data.Odbc.OdbcCommand sqlCommand = new System.Data.Odbc.OdbcCommand(str, this.conn);
                OdbcDataReader sqlDataReader            = sqlCommand.ExecuteReader();
                sqlDataReader.Read();
                int    num  = Convert.ToInt32(sqlDataReader[0].ToString());
                string str1 = sqlDataReader[0].ToString();
                sqlDataReader.Close();

                if (!(this.SqlCommand != ""))
                {
                    sqlCommand.CommandText = string.Concat("SELECT * from ", this.TableName);
                }
                else
                {
                    sqlCommand.CommandText = this.SqlCommand;
                }
                sqlDataReader = sqlCommand.ExecuteReader();
                int           fieldCount    = sqlDataReader.FieldCount;
                decimal       num1          = new decimal(0);
                StreamWriter  streamWriter  = new StreamWriter(string.Concat(this.filename, ".Txt"));
                StringBuilder stringBuilder = new StringBuilder();
                while (sqlDataReader.Read())
                {
                    decimal num2 = num1;
                    num1 = num2++;
                    this.updateDisplay(num2, num, str1);
                    for (int i = 0; i < fieldCount; i++)
                    {
                        if (!(sqlDataReader[i].GetType().ToString() == "System.Byte[]"))
                        {
                            stringBuilder.Append(sqlDataReader[i].ToString());
                        }
                        else
                        {
                            byte[] item = (byte[])sqlDataReader[i];
                            stringBuilder.Append(DataWriter2.BytesToHex(item));
                        }
                        if ((i >= fieldCount - 1 ? false : i >= 0))
                        {
                            stringBuilder.Append("|");
                        }
                    }
                    stringBuilder.Replace(Environment.NewLine, string.Empty);
                    streamWriter.WriteLine(stringBuilder.ToString());
                    stringBuilder.Length = 0;
                }
                streamWriter.Close();
                streamWriter.Dispose();
                stringBuilder = null;
                sqlCommand.Dispose();
                sqlDataReader.Dispose();
                flag = true;
            }
            catch (OdbcException odbcException1)
            {
                OdbcException odbcException = odbcException1;
                this.SimpleError = "OdbcError";
                this.Error       = odbcException.Message;
                flag             = false;
            }
            catch (IOException oException1)
            {
                IOException oException = oException1;
                this.SimpleError = "FileError";
                this.Error       = oException.Message;
                flag             = false;
            }
            catch (UnauthorizedAccessException unauthorizedAccessException1)
            {
                UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                this.SimpleError = "PermissionsError";
                this.Error       = unauthorizedAccessException.Message;
                flag             = false;
            }
            return(flag);
        }
Example #2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            DataWriter2    dataWriter2;
            string         str;
            CompExportConf compExportConf = new CompExportConf(this.XmlConfig);

            if (compExportConf.load())
            {
                int    year = DateTime.Now.Year;
                string str1 = year.ToString();
                year = DateTime.Now.Month;
                string str2 = year.ToString();
                year = DateTime.Now.Day;
                string  str3 = string.Concat(str1, str2, year.ToString());
                int     num  = compExportConf.GetnumberCompanies();
                decimal num1 = new decimal(0);
                for (int i = 0; i < num; i++)
                {
                    string    companyName        = compExportConf.getCompanyName(i);
                    string    companyConnection  = compExportConf.getCompanyConnection(i);
                    ArrayList compExportDetails2 = compExportConf.getCompExportDetails2(i);
                    int       count = compExportDetails2.Count;
                    dataWriter2 = new DataWriter2(companyConnection, companyName, this);
                    bool flag = dataWriter2.Connect();
                    if (!flag)
                    {
                        this.logger.WriteToLog("-----------------------------------");
                        this.logger.WriteToLog(string.Concat("ERROR Couldn't Connect to ", companyName));
                        this.logger.WriteToLog("-----------------------------------");
                    }
                    else
                    {
                        this.logger.WriteToLog("-----------------------------------");
                        this.logger.WriteToLog(string.Concat("Connected to ", companyName));
                        this.logger.WriteToLog("-----------------------------------");
                    }
                    if ((compExportDetails2.Count <= 0 ? false : flag))
                    {
                        this.backgroundWorker1.ReportProgress(0, "");
                        for (int j = 0; j < compExportDetails2.Count; j++)
                        {
                            string[] strArrays = compExportDetails2[j].ToString().Split(new char[] { '|' });
                            string   str4      = strArrays[0];
                            str = strArrays[1];
                            string str5  = strArrays[2];
                            string str6  = strArrays[3];
                            string upper = companyName.Substring(0, 3).ToUpper();
                            string str7  = string.Concat(upper, "_", str, str3);
                            string str8  = string.Concat(this.DestinationFolder, "\\", str7);
                            dataWriter2.setExportDetails(str4, str6, str8);
                            bool txt = dataWriter2.ExportToTxt();
                            num1 = num1++;
                            decimal num2 = num1 / count;
                            int     num3 = (int)(num2 * new decimal(100));
                            this.backgroundWorker1.ReportProgress(num3, str4);
                            if (txt)
                            {
                                this.logger.WriteToLog(string.Concat(str, " Complete"));
                            }
                            else
                            {
                                if (dataWriter2.GetSError() == "SqlError")
                                {
                                    goto Label1;
                                }
                                if ((dataWriter2.GetSError() == "FileError" ? false : !(dataWriter2.GetSError() == "PermissionsError")))
                                {
                                    this.backgroundWorker1.CancelAsync();
                                    Application.Exit();
                                }
                                else
                                {
                                    this.logger.WriteToLog(string.Concat(str, dataWriter2.GetSError()));
                                    if (Settings.Default.IncludeErrors)
                                    {
                                        this.logger.WriteToLog(string.Concat(str, " ", dataWriter2.GetError()));
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    dataWriter2.Close();
                    dataWriter2 = null;
                    count       = 0;
                    num1        = new decimal(0);
                }
                if (this.logger != null)
                {
                    this.logger.CloseLog();
                }
            }
            else
            {
                this.logger.WriteToLog(string.Concat("Problem with XML config file ", compExportConf.GetSmallError()));
                this.logger.WriteToLog("-----------------------------------");
                if (Settings.Default.IncludeErrors)
                {
                    this.logger.WriteToLog(compExportConf.GetBigError());
                }
                MessageBox.Show("Problem with XML Config file\nPlease correct.");
            }
            return;

Label1:
            this.logger.WriteToLog(string.Concat(str, " ", dataWriter2.GetSError()));
            if (Settings.Default.IncludeErrors)
            {
                this.logger.WriteToLog(dataWriter2.GetError());
            }
            //	goto Label0;
        }