////////////////////////
        ///

        private String ConvertCellToColumn(String SheetName, String Cell)
        {
            String Column = "";
            int    index  = 0;
            int    alph   = 0;

            if (char.IsLetter(Cell[index]))
            {
                alph = Cell[index] - 'A';
            }

            Column = Cell.Substring(1);

            if (!char.IsDigit(Column[0]))
            {
                String exception_str = "";
                exception_str += "Invalid Cell reference" + "\r\n";
                CSyntaxErrorLog.AddLine(exception_str);
                throw new CParserException(-100, exception_str, -1);
            }

            int       rec_num = Convert.ToInt32(Column) - 2;
            String    name    = ((DataTable)m_Table[SheetName + "$"]).Columns[alph].ToString();
            DataTable t       = ((DataTable)m_Table[SheetName + "$"]);

            return(t.Rows[rec_num][name].ToString());
        }
        /// <summary>
        ///    Open the connections to oracle and Excel
        /// </summary>
        /// <param name="FileName"></param>
        private void OpenConnections(String ExcelConStr, String OrclConStr)
        {
            try
            {
                if (conn_excel != null)
                {
                    System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Excel connection already opened");
                }

                conn_excel = new OleDbConnection(ExcelConStr);
                conn_excel.Open();

                if (conn_oracle != null)
                {
                    System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Excel connection already opened");
                }

                conn_oracle = new OracleConnection(OrclConStr);
                conn_oracle.Open();

                GlobalSettings.oracle_connection_count++;
                GlobalSettings.excel_connection_count++;
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
                CSyntaxErrorLog.AddLine(e.ToString());
                Close();
                throw new CParserException(-100, e.ToString(), -1);
            }
        }
        /// <summary>
        ///    Sum Excel data
        /// </summary>
        /// <param name="SheetName"></param>
        /// <param name="CellName_Start"></param>
        /// <param name="CellName_End"></param>
        /// <returns></returns>
        public double SumRange(String SheetName, String CellName_Start
                               , String CellName_End, int ScaleFactor)
        {
            String Column_Start = "";
            String Column_End   = "";
            int    index        = 0;
            int    alph         = 0;
            int    alph1        = 0;

            if (char.IsLetter(CellName_Start[index]) &&
                char.IsLetter(CellName_End[index]))
            {
                alph  = CellName_Start[index] - 'A';
                alph1 = CellName_End[index] - 'A';

                if (alph != alph1)
                {
                    String exception_str = "";
                    exception_str += "Cell Name mismatch" + "\r\n";
                    CSyntaxErrorLog.AddLine(exception_str);
                    throw new CParserException(-100, exception_str, -1);
                }
            }
            else
            {
                String exception_str = "";
                exception_str += "Invalid Cell reference" + "\r\n";
                CSyntaxErrorLog.AddLine(exception_str);
                throw new CParserException(-100, exception_str, -1);
            }

            Column_Start = CellName_Start.Substring(1);
            Column_End   = CellName_End.Substring(1);

            if (!(char.IsDigit(Column_Start[0]) || char.IsDigit(Column_End[0])))
            {
                String exception_str = "";
                exception_str += "Invalid Cell reference" + "\r\n";
                CSyntaxErrorLog.AddLine(exception_str);
                throw new CParserException(-100, exception_str, -1);
            }

            int rec_num  = Convert.ToInt32(Column_Start) - 2;
            int rec_num1 = Convert.ToInt32(Column_End) - 2;

            String ColumnName = ((DataTable)m_Table[SheetName + "$"]).Columns[alph].ToString();

            return(SumColumn(SheetName, ColumnName, rec_num, rec_num1, ScaleFactor));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sql"></param>
 public void DeleteData(string sql)
 {
     try
     {
         OracleCommand tmpcommand = new OracleCommand(sql, conn_oracle);
         tmpcommand.CommandTimeout = 90;
         tmpcommand.ExecuteNonQuery();
     }
     catch (Exception e)
     {
         CSyntaxErrorLog.AddLine(e.ToString());
         Close();
         throw new CParserException(-100, "Error Executing Query", -1);
     }
 }
 /// <summary>
 ///   Routine for Meta Data collection of Excel sheets
 ///
 /// </summary>
 /// <returns></returns>
 private DataTable GetTables()
 {
     try
     {
         DataTable schemaTable = conn_excel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
                                                                new object[] { null, null, null, "TABLE" });
         return(schemaTable);
     }
     catch (Exception e)
     {
         System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
         CSyntaxErrorLog.AddLine(e.ToString());
         throw new CParserException(-100, e.ToString(), -1);
     }
 }
 /// <summary>
 ///   Move the spread sheet File to Quarantine
 /// </summary>
 /// <param name="s"></param>
 public void MoveToQuarantine(ForeCastFileInfo s)
 {
     try
     {
         String DirName     = s.PathName + "\\" + "QUARANTINE\\";
         String XlFile      = s.XlsFile;
         int    nindex      = XlFile.LastIndexOf("\\");
         String filename    = XlFile.Substring(nindex + 1);
         String newfilename = DirName +
                              DateAsStr(DateTime.Now) + "_" +
                              filename;
         /////////////////////////////////////////////
         ///
         ///   IF Quarantine Folder does not exist
         ///   Create a new one
         if (!Directory.Exists(DirName))
         {
             Directory.CreateDirectory(DirName);
         }
         ///////////////////////////////////////////
         ///
         ///  Copy the File to Quarantine
         ///
         if (!ForeCastUpdatorService.CanFilebeAccessed(XlFile))
         {
             throw new Exception(XlFile + " Copy: Cannot be accessed or opened by another app");
         }
         File.Copy(XlFile, newfilename, true);
         //////////////////////////////////////////////
         ///  Delete the file
         ///
         if (!ForeCastUpdatorService.CanFilebeAccessed(XlFile))
         {
             throw new Exception(XlFile + " Cannot be accessed or opened by another app");
         }
         File.Delete(XlFile);
     }
     catch (Exception e)
     {
         ///////////////////////////////////////////////
         ///
         /// Log the Exception
         ///
         System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
         CSyntaxErrorLog.AddLine(e.ToString());
         return;
     }
 }
        /// <summary>
        /// Insert data
        /// </summary>
        /// <param name="cmd"></param>


        public void InsertData(OracleCommand cmd)
        {
            try
            {
                cmd.Connection     = m_conn;
                cmd.CommandTimeout = 90;
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
                CSyntaxErrorLog.AddLine(e.ToString());
                Close();
                throw new CParserException(-100, e.ToString(), -1);
            }
        }
        /// <summary>
        ///    Backup File
        /// </summary>
        /// <param name="s"></param>

        public void BackupFile(ForeCastFileInfo s)
        {
            try
            {
                String DirName     = s.PathName + "\\" + "BACKUP\\";
                String XlFile      = s.XlsFile;
                int    nindex      = XlFile.LastIndexOf("\\");
                String filename    = XlFile.Substring(nindex + 1);
                String newfilename = DirName +
                                     DateAsStr(DateTime.Now) + "_" +
                                     filename;
                /////////////////////////////////////////////
                ///
                ///  IF Backup folder does not exist
                ///  Create a new one
                if (!Directory.Exists(DirName))
                {
                    Directory.CreateDirectory(DirName);
                }
                //////////////////////////////////////
                ///
                ///  Move to Backup folder
                ///
                ///

                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Copying File");
                if (!ForeCastUpdatorService.CanFilebeAccessed(XlFile))
                {
                    throw new Exception(XlFile + "Copy: Cannot be accessed or opened by another app");
                }
                File.Copy(XlFile, newfilename, true);
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Finished Copying File");
                if (!ForeCastUpdatorService.CanFilebeAccessed(XlFile))
                {
                    throw new Exception(XlFile + "Delete: Cannot be accessed or opened by another app");
                }
                File.Delete(XlFile);
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Finished Deleting File");
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
                CSyntaxErrorLog.AddLine(e.ToString());
                return;
            }
        }
 /// <summary>
 ///     Ctor
 ///     Takes the connection string as parameter
 ///     Opens a connection and starts transaction
 /// </summary>
 /// <param name="OrclConnstr"></param>
 public CBatchDBUpdator(String OrclConnstr)
 {
     try
     {
         m_OrclConnstr = OrclConnstr;
         m_conn        = new OracleConnection(m_OrclConnstr);
         m_conn.Open();
         GlobalSettings.oracle_connection_count++;
         m_Trans = m_conn.BeginTransaction(IsolationLevel.ReadCommitted);
     }
     catch (Exception e)
     {
         System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
         CSyntaxErrorLog.AddLine(e.ToString());
         throw e;
     }
 }
        /// <summary>
        ///    Select a Scalar value
        /// </summary>
        /// <param name="cmd"></param>

        public DataSet SelectScalar(OracleCommand cmd)
        {
            try
            {
                cmd.Connection     = m_conn;
                cmd.CommandTimeout = 90;
                DataSet           ds = new DataSet();
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                da.Fill(ds, "Results");
                return(ds);
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
                CSyntaxErrorLog.AddLine(e.ToString());
                Close();
                throw new CParserException(-100, e.ToString(), -1);
            }
        }
        /// <summary>
        ///    Check for Null
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="arr"></param>
        /// <returns></returns>
        public bool HasNull(String sheet, ArrayList arr)
        {
            int nCount = arr.Count;

            if (nCount == 0)
            {
                return(false);
            }

            DataTable            t    = GetDataTable(sheet);
            DataColumnCollection cols = t.Columns;


            try
            {
                int nItems = t.Rows.Count;
                int index  = 0;

                while (index < nItems)
                {
                    DataRow row = t.Rows[index];

                    for (int k = 0; k < arr.Count; ++k)
                    {
                        if (row[arr[k].ToString()].GetType() == Type.GetType("System.DBNull"))
                        {
                            CSemanticErrorLog.AddLine("Null or No data in Column = " + arr[k]);
                            return(true);
                        }
                    }

                    index++;
                }
                return(false);
            }
            catch (Exception e)
            {
                CSyntaxErrorLog.AddLine(e.ToString());
                throw e;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Sql"></param>
        /// <returns></returns>
        public DataSet GetDataSet(string Sql)
        {
            try
            {
                OracleCommand tmpcommand = new OracleCommand(Sql, conn_oracle);

                tmpcommand.CommandTimeout = 90;
                DataSet           ds = new DataSet();
                OracleDataAdapter da = new OracleDataAdapter(tmpcommand);

                da.Fill(ds);

                return(ds);
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
                CSyntaxErrorLog.AddLine(e.ToString());
                Close();
                throw new CParserException(-100, e.ToString(), -1);
            }
        }
        ////////////////////////////////////////////////////////
        ///
        ///  Here is the actual workhorse
        ///
        ///
        public static void ScanForForeCastData()
        {
            try
            {
                while (true)
                {
                    ////////////////////////////////
                    ///
                    ///  Clean up all the data
                    ///
                    CSyntaxErrorLog.Cleanup();
                    CSemanticErrorLog.Cleanup();
                    GlobalSettings.Cleanup();
                    ///////////////////
                    ///
                    ///  Do Processing
                    ///

                    ScanAndProcess();
                    /////////////////////////////////////////
                    ///
                    ///  Sleep the Thread for 2 minutes.
                    ///  in the production build , it should run
                    ///  in an interval of at least 10 minutes
                    ///
                    ///
                    System.GC.Collect();
                    System.Threading.Thread.Sleep(60000 * 5);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Exception thrown by the Thread");
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
            }

            return;
        }
        /// <summary>
        ///    Check for Duplicate in a Sheet
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="arr"></param>
        /// <returns></returns>
        public bool CheckDuplicate(String sheet, ArrayList arr)
        {
            int nCount = arr.Count;

            if (nCount == 0)
            {
                return(false);
            }

            DataTable            t    = GetDataTable(sheet);
            DataColumnCollection cols = t.Columns;


            try
            {
                int nItems = t.Rows.Count;
                int index  = 0;

                while (index < nItems)
                {
                    DataRow row = t.Rows[index];
                    if (CompareRecord(t, row, arr, index) == false)
                    {
                        return(false);
                    }
                    index++;
                }

                return(true);
            }
            catch (Exception e)
            {
                CSyntaxErrorLog.AddLine(e.ToString());
                throw e;
            }
        }
Example #15
0
        /// <summary>
        ///    Update All the data from the spread sheet
        /// </summary>
        /// <returns></returns>
        ///
        public bool UpdateAll()
        {
            String country;
            String segment;
            String currency;
            double ordc;                     // order cancel factor
            String forecast_name;

            try
            {
                batch_upd = new CBatchDBUpdator(m_OrclConnstr);
                country   = m_xlsreader.GetCellValue("CONTROL", "B2");
                currency  = m_xlsreader.GetCellValue("CONTROL", "B5");
                segment   = m_xlsreader.GetCellValue("CONTROL", "B3");
                String ordcstr        = m_xlsreader.GetCellValue("CONTROL", "B6");
                string time_zone_code = m_xlsreader.GetCellValue("CONTROL", "B4");
                GetTimeZoneOffset(time_zone_code);


                ordcstr = ordcstr.Trim().ToUpper();

                int    index = 0;
                String temp  = "";

                while (char.IsDigit(ordcstr[index]))
                {
                    temp = temp + ordcstr[index];
                    index++;
                }

                if (ordcstr[index] == '.')
                {
                    index++;
                    temp = temp + ".";
                    while (char.IsDigit(ordcstr[index]))
                    {
                        temp = temp + ordcstr[index];
                        index++;
                    }
                }

                ordc = Convert.ToDouble(temp);

                forecast_name = m_xlsreader.GetCellValue("CONTROL", "B7");


                country       = country.Trim().ToUpper();
                segment       = segment.Trim().ToUpper();
                currency      = currency.Trim().ToUpper();
                forecast_name = forecast_name.Trim();


                if (country.Length == 0 || segment.Length == 0 ||
                    currency.Length == 0)
                {
                    throw new Exception("Country , Segment or Currency is zero length");
                }

                if (segment.Length > 10)
                {
                    segment = segment.Substring(0, 10);
                }

                if (forecast_name.Length > 20)
                {
                    forecast_name = forecast_name.Substring(0, 20);
                }



                upd_ob_revenue_units(country, segment, currency);
                update_click_stream(country, segment);
                update_ob_order_count(country, segment);
                update_odg_click_count(country, segment);
                update_odg_order_count_revenue(country, segment, currency);
                update_control_to_ei_cancel_factor(country, segment, forecast_name, ordc);
                batch_upd.Commit();
                batch_upd.Close();
                batch_upd = null;
                return(true);
            }
            catch (CParserException e)
            {
                CSyntaxErrorLog.AddLine(e.ToString());
                batch_upd.Abort();
                batch_upd.Close();
                batch_upd = null;
                return(false);
            }
            catch (Exception e)
            {
                CSyntaxErrorLog.AddLine(e.ToString());
                batch_upd.Abort();
                batch_upd.Close();
                batch_upd = null;
                return(false);
            }
        }
        /// <summary>
        ///    Update Routine
        ///    Loop as long as a valid file is found
        /// </summary>
        public bool Update()
        {
            bool bVal = true;

            while (true)
            {
                CDirectoryWalker x = new CDirectoryWalker();
                x.Visit(m_rootPath, "*.XLS", true);
                ArrayList r = x.GetAllXls();

                ///////////////////////////////
                ///  if no more file is found ...
                ///  stop this iteration
                ///
                if (r.Count == 0)
                {
                    break;
                }

                foreach (ForeCastFileInfo s in r)
                {
                    ////////////////////////////////////////////////////
                    ///
                    ///  Stop processing , if thread has been requested to stop processing
                    ///
                    ///
                    if (GlobalSettings.request_processing_thread_abort == true)
                    {
                        return(bVal);
                    }
                    ///////////////////////////////
                    /// Clean up the Error Logs before
                    /// we go for fresh processing
                    ///	CSemanticErrorLog.Cleanup();
                    CSyntaxErrorLog.Cleanup();
                    CSemanticErrorLog.Cleanup();

                    ////////////////////////////////////////
                    ///
                    ///  Try to Validate the file
                    ///
                    GlobalSettings.oracle_connection_count = 0;
                    GlobalSettings.excel_connection_count  = 0;
                    if (ValidateFile(s))
                    {
                        System.GC.Collect();

                        ///////////////////////////////////////////////
                        ///
                        ///  Validation and updation is successful
                        ///  Check for the backup_sheets flag and
                        ///  Back up the File , if it is true
                        ///

                        if (GlobalSettings.oracle_connection_count != 0)
                        {
                            System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Oracle Connection" + Convert.ToString(GlobalSettings.oracle_connection_count));
                        }


                        if (GlobalSettings.excel_connection_count != 0)
                        {
                            System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Oracle Connection" + Convert.ToString(GlobalSettings.excel_connection_count));
                        }


                        if (GlobalSettings.backup_sheets == true)
                        {
                            BackupFile(s);
                        }
                    }
                    else
                    {
                        ///////////////////////////////////
                        /// At least one stuff failed in this iteration
                        /// left unused
                        ///
                        if (bVal)
                        {
                            bVal = false;
                        }

                        ///////////////////////////////////////////////////
                        ///
                        ///  Failure in updating ForeCast Data
                        ///  Try to Quarantine the file , if
                        ///  quarantine_sheets flag is true
                        ///

                        if (GlobalSettings.oracle_connection_count > 0)
                        {
                            System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Oracle Connection" + Convert.ToString(GlobalSettings.oracle_connection_count));
                        }


                        if (GlobalSettings.excel_connection_count > 0)
                        {
                            System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Oracle Connection" + Convert.ToString(GlobalSettings.excel_connection_count));
                        }
                        if (GlobalSettings.quarantine_sheets == true)
                        {
                            MoveToQuarantine(s);
                        }
                    }
                }

                break;
            }

            return(bVal);
        }
        /// <summary>
        ///   Clean up data in a sheet. This routine is written
        ///   to elimate those rows which are considered by excel
        ///   as record and will appear empty as humans.
        ///   Such rows should be in the tail of the cell.
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="arr"></param>
        /// <returns></returns>
        public bool CleanUpCells(String sheet, ArrayList arr)
        {
            //////////////////////////////////////////////////////
            ///  Retrieve table associated with sheet
            ///
            DataTable tab = (DataTable)m_Table[sheet + "$"];
            ////////////////////////////////////
            /// Retrieve meta data for the columns
            ///
            DataColumnCollection colls = tab.Columns;
            /////////////////////////////////////
            ///
            ///  # of Row
            ///
            int row_count = tab.Rows.Count;

            if (row_count == 0)
            {
                return(false);
            }
            //////////////////////////////////////
            ///  index used for iteration of celss
            ///
            int index = 0;
            /////////////////////////////////////////
            ///
            ///
            bool first_time = false;
            int  start_rec  = -1;

            while (index < row_count)
            {
                DataRow rw = tab.Rows[index];

                if (CompareOne(rw, colls, arr) == false)
                {
                    /////////////////////////////////////////
                    ///  An Empty Record
                    ///

                    if (first_time == false)
                    {
                        start_rec  = index;
                        first_time = true;
                    }
                }
                else
                {
                    ///////////////////////////////////////
                    ///  if already an empty record and found
                    ///  a genuine record after that , return
                    ///  failure. Sheet is invalid
                    ///
                    if (first_time == true)
                    {
                        return(false);
                    }
                }
                index++;
            }

            ////////////////////////////////
            ///
            ///  IF whitespace rows are found
            ///
            if (start_rec != -1)
            {
                ///////////////////////////////
                ///  # of records to be cleaned up
                ///
                int num_rec = row_count - start_rec;
                int i       = 0;

                while (i < num_rec)
                {
                    ///////////////////////////////////
                    /// Iterate the list and delete
                    /// note :- start_rec is not advanced
                    tab.Rows[start_rec++].Delete();
                    i++;
                }
                //////////////////////////////////////
                /// Accept the changes
                ///
                tab.AcceptChanges();

                if (tab.Rows.Count == 0)
                {
                    CSyntaxErrorLog.AddLine("All the record is invalid because of some missing fields");
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        ///    Call  the Excel content Validator
        /// </summary>
        /// <param name="s"></param>
        public bool ValidateFile(ForeCastFileInfo s)
        {
            CParser        prs = null;
            CExcelDBUpdate upd = null;

            try {
                if (!ForeCastUpdatorService.CanFilebeAccessed(s.XlsFile))
                {
                    throw new Exception(s.XlsFile + " Cannot be accessed or opened by another app");
                }

                String m_Country = this.GetCountryFromPath(s.XlsFile);
                String m_Segment = this.GetSegmentFromPath(s.XlsFile);


                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Processing File ...." + s.XlsFile);
                String Prgs        = (String)GlobalSettings.GetEntry("VALIDATION_SCRIPT");
                String OrclConStr  = (String)GlobalSettings.GetEntry("ORACLE_CONNECTION_STRING");
                String ExcelConStr = "Provider=" + (String)GlobalSettings.GetEntry("EXCEL_PROVIDER");
                ExcelConStr += "Data Source=" + s.XlsFile + ";";
                ExcelConStr += (String)GlobalSettings.GetEntry("EXCEL_PROPERTIES");
                CSemanticErrorLog.AddLine("Excel file = " + s.XlsFile);
                prs = new CParser(Prgs, m_Country, m_Segment);
                bool brs     = prs.CallParser(ExcelConStr, OrclConStr);
                bool ret_val = true;

                if (brs == true)
                {
                    upd     = new CExcelDBUpdate(OrclConStr, prs.GetExcelReader());
                    ret_val = upd.UpdateAll();

                    if (ret_val == false)
                    {
                        CSemanticErrorLog.AddLine("FATAL ERROR WHILE UPDATING FORECAST DATA  ");
                    }
                }



                if (ret_val == true && brs == true)
                {
                    if (GlobalSettings.allow_emails == true)
                    {
                        notify.TO   = prs.GetEmail();
                        notify.Body = "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog();
                        notify.SendToExcelEmail(0);
                    }

                    if (GlobalSettings.event_logging == true)
                    {
                        if (!System.Diagnostics.EventLog.SourceExists("ForeCastLog"))
                        {
                            System.Diagnostics.EventLog.CreateEventSource("ForeCastLog",
                                                                          "DoForeCastLog");
                        }

                        System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog() + prs.GetSyntaxLog());
                    }

                    if (upd != null)
                    {
                        upd.Cleanup();
                        upd = null;
                    }
                    if (prs != null)
                    {
                        prs.CloseAll();
                        prs = null;
                    }
                    return(ret_val);
                }
                else
                {
                    if (GlobalSettings.event_logging == true)
                    {
                        if (!System.Diagnostics.EventLog.SourceExists("ForeCastLog"))
                        {
                            System.Diagnostics.EventLog.CreateEventSource("ForeCastLog",
                                                                          "DoForeCastLog");
                        }

                        System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog() + prs.GetSyntaxLog());
                    }

                    if (GlobalSettings.allow_emails == true)
                    {
                        notify.TO   = prs.GetEmail();
                        notify.Body = "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog();
                        notify.SendToExcelEmail(1);

                        notify.Body = "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + prs.GetSemanticLog() + prs.GetSyntaxLog();
                        notify.Send(1);
                    }
                    if (upd != null)
                    {
                        upd.Cleanup();
                        upd = null;
                    }
                    if (prs != null)
                    {
                        prs.CloseAll();
                        prs = null;
                    }

                    return(false);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.EventLog.WriteEntry("ForeCastLog", e.ToString());
                CSemanticErrorLog.AddLine(e.ToString());
                if (GlobalSettings.event_logging == true)
                {
                    if (!System.Diagnostics.EventLog.SourceExists("ForeCastLog"))
                    {
                        System.Diagnostics.EventLog.CreateEventSource("ForeCastLog",
                                                                      "DoForeCastLog");
                    }


                    System.Diagnostics.EventLog.WriteEntry("ForeCastLog", "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + CSemanticErrorLog.GetLog() + CSyntaxErrorLog.GetLog());
                }

                if (GlobalSettings.allow_emails == true)
                {
                    notify.Body = "Hi" + "\r\n\r\n" + "ForeCast updation status " + "\r\n" + CSemanticErrorLog.GetLog() + CSyntaxErrorLog.GetLog();
                    notify.Send(1);
                }

                if (upd != null)
                {
                    upd.Cleanup();
                    upd = null;
                }
                if (prs != null)
                {
                    prs.CloseAll();
                    prs = null;
                }

                return(false);
            }
        }
        public bool ProcessForeCastPath(XmlNode node)
        {
            try
            {
                ////////////////////////////////////////
                ///  Retrieve the root directory
                ///
                String root_dir = node.InnerText;
                if (!Directory.Exists(root_dir))
                {
                    Directory.CreateDirectory(root_dir);
                }


#if false
                ////////////////////////////////////////////////
                ///
                ///  Retrieve the Country names
                ///
                XmlNode     nd      = node.SelectSingleNode("COUNTRY_LIST");
                XmlNodeList nd_list = nd.SelectNodes("COUNTRY");

                int i = 0;
                while (i < nd_list.Count)
                {
                    //////////////////////////////
                    /// Retrieve Country node
                    ///
                    XmlNode country_nd = nd_list.Item(i);

                    /////////////////////////////////////
                    ///  Retrieve country name
                    ///
                    String country_name = country_nd.SelectSingleNode("COUNTRY_NAME").InnerText;

                    ///////////////////////////////////////////////
                    ///  Try to create Folder for the country
                    ///
                    ///
                    if (!Directory.Exists(root_dir + "\\" + country_name))
                    {
                        Directory.CreateDirectory(root_dir + "\\" + country_name);
                    }

                    XmlNode Temp = country_nd.SelectSingleNode("SEGMENT_LIST");

                    XmlNodeList Temp_List = null;
                    if (Temp != null)
                    {
                        Temp_List = Temp.ChildNodes;
                    }


                    if (Temp_List != null)
                    {
                        if (Temp_List.Count > 0)
                        {
                            int j = 0;
                            while (j < Temp_List.Count)
                            {
                                String segment = Temp_List.Item(j).InnerText;
                                if (!Directory.Exists(root_dir + "\\" + country_name + "\\" + segment))
                                {
                                    Directory.CreateDirectory(root_dir + "\\" + country_name + "\\" + segment);
                                }
                                j++;
                            }
                        }
                    }

                    i++;
                }
#endif
            }
            catch (Exception e)
            {
                CSyntaxErrorLog.AddLine(e.ToString());
                throw e;
            }

            return(true);
        }
        /// <summary>
        ///    Read the Stuff from the initialization file
        /// </summary>
        private void Initialize()
        {
            try
            {
                XmlNode     scratch;
                XmlDocument doc = new System.Xml.XmlDocument();
                doc.Load(m_xmlfile);
                XmlNode config_nd = doc.SelectSingleNode("CONFIG");
                scratch = config_nd.SelectSingleNode("DECIMAL_ROUNDING");
                GlobalSettings.AddEntry("DECIMAL_ROUNDING", Convert.ToInt32(scratch.InnerText));
                scratch = config_nd.SelectSingleNode("ALLOW_EMAILS");
                GlobalSettings.AddEntry("ALLOW_EMAILS", scratch.InnerText);
                scratch = config_nd.SelectSingleNode("QUARANTINE_SHEETS");
                GlobalSettings.AddEntry("QUARANTINE_SHEETS", scratch.InnerText);
                scratch = config_nd.SelectSingleNode("BACKUP_SHEETS");
                GlobalSettings.AddEntry("BACKUP_SHEETS", scratch.InnerText);
                scratch = config_nd.SelectSingleNode("EVENT_LOGGING");
                GlobalSettings.AddEntry("EVENT_LOGGING", scratch.InnerText);


                //
                //  Retrieve notification parameters
                //
                //
                XmlNode notify_nd = config_nd.SelectSingleNode("NOTIFICATION");
                scratch = notify_nd.SelectSingleNode("EMAIL_LIST");

                XmlNodeList iter = scratch.ChildNodes;

                foreach (XmlNode rnode in iter)
                {
                    notify.AddEmail(rnode.InnerText);
                }

                scratch = notify_nd.SelectSingleNode("SUBJECT_SUCCESS");
                notify.SubjectSuccess = scratch.InnerText;

                scratch = notify_nd.SelectSingleNode("SUBJECT_FAILURE");
                notify.SubjectFailure = scratch.InnerText;

                scratch       = notify_nd.SelectSingleNode("SMTPSERVER");
                notify.Server = scratch.InnerText;

                scratch     = notify_nd.SelectSingleNode("SENDER");
                notify.From = scratch.InnerText;
                //
                //
                //  Retrieve oracle string
                //
                //
                XmlNode retr_node = config_nd.SelectSingleNode("ORACLE_CONNECTION_STRING");
                GlobalSettings.AddEntry("ORACLE_CONNECTION_STRING", retr_node.InnerText);
                retr_node = config_nd.SelectSingleNode("SCRIPT");
                GlobalSettings.AddEntry("VALIDATION_SCRIPT", retr_node.InnerText);
                retr_node = config_nd.SelectSingleNode("FORECAST_PATH");
                GlobalSettings.AddEntry("FORECAST_PATH", retr_node.InnerText);
                ProcessForeCastPath(retr_node);
                m_rootPath = retr_node.InnerText;
                retr_node  = config_nd.SelectSingleNode("EXCEL_CONNECTION_STRING");
                XmlNode temp_node = retr_node.SelectSingleNode("PROVIDER");
                GlobalSettings.AddEntry("EXCEL_PROVIDER", temp_node.InnerText);
                temp_node = retr_node.SelectSingleNode("PROPERTIES");
                GlobalSettings.AddEntry("EXCEL_PROPERTIES", temp_node.InnerText);
            }
            catch (Exception e)
            {
                CSyntaxErrorLog.AddLine(e.ToString());
                throw e;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="t"></param>
        /// <param name="rw"></param>
        /// <param name="arr"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public bool   CompareRecord(
            DataTable t,
            DataRow rw,
            ArrayList arr,
            int index)
        {
            DataColumnCollection colls = t.Columns;
            int st = t.Rows.Count;

            int   i      = 0;
            Stack pstack = new Stack();

            while (i < st)
            {
                if (i == index)
                {
                    i++;
                    continue;
                }
                DataRow rw1 = t.Rows[i];

                int  sn    = arr.Count;
                int  j     = 0;
                bool equal = true;

                while (j < sn)
                {
                    String s = (String)arr[j];
                    if (colls[s].DataType == Type.GetType("System.DateTime") &&
                        (rw[s].GetType() == rw1[s].GetType() && rw[s].GetType() != Type.GetType("System.DBNull")))
                    {
                        DateTime r  = Convert.ToDateTime(rw[s]);
                        DateTime r1 = Convert.ToDateTime(rw1[s]);

                        equal = equal && (r == r1);
                    }
                    else if (colls[s].DataType == Type.GetType("System.Double") &&
                             (rw[s].GetType() == rw1[s].GetType() && rw[s].GetType() != Type.GetType("System.DBNull")))
                    {
                        System.Double r  = Convert.ToDouble(rw[s]);
                        Double        r1 = Convert.ToDouble(rw1[s]);
                        equal = equal && (r == r1);
                    }
                    else if (colls[s].DataType == Type.GetType("System.Int32") &&
                             (rw[s].GetType() == rw1[s].GetType() && rw[s].GetType() != Type.GetType("System.DBNull")))
                    {
                        Int32 r  = Convert.ToInt32(rw[s]);
                        Int32 r1 = Convert.ToInt32(rw1[s]);
                        equal = equal && (r == r1);
                    }
                    else if (colls[s].DataType == Type.GetType("System.String") &&
                             (rw[s].GetType() == rw1[s].GetType() && rw[s].GetType() != Type.GetType("System.DBNull")))
                    {
                        String r  = Convert.ToString(rw[s]).ToUpper();
                        String r1 = Convert.ToString(rw1[s]).ToUpper();
                        equal = equal && (r == r1);
                    }
                    else if (colls[s].DataType == Type.GetType("System.String") &&
                             (rw[s].GetType() == rw1[s].GetType() && rw[s].GetType() != Type.GetType("System.DBNull")))
                    {
                        Decimal r  = Convert.ToDecimal(rw[s]);
                        Decimal r1 = Convert.ToDecimal(rw1[s]);
                        equal = equal && (r == r1);
                    }
                    else
                    {
                        String expression = "";
                        expression = "Invalid Type reference at row" + Convert.ToString(i);
                        CSyntaxErrorLog.AddLine(expression);
                        throw new CParserException(-100, expression, -1);
                    }


                    if (!equal)
                    {
                        break;
                    }

                    j++;
                }

                if (equal)
                {
                    return(false);
                }
                i++;
            }
            return(true);
        }