Exemplo n.º 1
0
        // UNPACK ENVELOPES AND UPLOAD INTO DB :
        private void ProcessEnvelopes()
        {
            string methodName = MethodInfo.GetCurrentMethod().Name;
            try
            {
                string todayUploadedLog = DateTime.Now.ToString("yyyyMMdd") + "_Uploaded.log";

                // POSSIBLE A NEW DAY STARTED & NEW LOG FILE NEEDED :

                if (!File.Exists(todayUploadedLog))
                {
                    File.Create(todayUploadedLog);
                    textBox_4_Tests_Only.Text = textBoxClearHeader;
                    dataPicker.SelectedDate = DateTime.Now;
                }
                else
                {
                    string dbLogin = passwordBoxLogin.Password.Trim();
                    string dbPassw = passwordBoxPassw.Password.Trim();

                    if (dbLogin.Length < 1 || dbPassw.Length < 1)
                    {
                        MessageBox.Show("Set Login & Password Before!");
                    }
                    else
                    {
                        WorkWithDB_2015 workWithDB = new WorkWithDB_2015(_DATABASE, dbLogin, dbPassw);

                        labelForTimer.Content = "Run Every " + timerMinutes + " min. Next Autorun at " +
                                        DateTime.Now.AddMinutes(timerMinutes).ToString("HH:mm:ss");
                        // "Next Autorun at - " + DateTime.Now.AddMinutes(15).ToShortTimeString();

                        // GET TODAY ENVELOPES FROM TODAY-FOLDER (OR ANOTHER SELECTED DATE) :

                        FileInfo[] todayEnvelopes = GetEnvelopesListForDate(dataPicker.SelectedDate.Value);

                        if (todayEnvelopes != null && todayEnvelopes.Length > 0)
                        {
                            for (int i = 0; i < todayEnvelopes.Length; i++)
                            {
                                // CREATE ENVELOPE USING EVERY ENVELOPE-FILE PARAMS :

                                Envelope env = new Envelope(todayEnvelopes[i]);
                                // TODO:  SOMETHING WRONG...
                                // TODO:  SOMETHING WRONG...
                                // TODO:  SOMETHING WRONG...
                                env.fileLocation = "FILE NOT FOUND !!!";

                                // CHECK IN LOG FILE IF NOT UPLOADED YET :

                                if (!File.ReadAllText(todayUploadedLog).Contains(env.envelopeName))
                                {
                                    // GET UNPACKED FILES (LOOKING IN ALL POSSIBLE FOLDERS) :

                                    foreach (string possiblePath in possibleOutputDirs)
                                    {
                                        string outputFilePath = NbuRootDir + possiblePath + env.fileName;

                                        if (File.Exists(outputFilePath))
                                        {
                                            env.fileLocation = outputFilePath;
                                            break;
                                        }
                                    }

                                    // START UPLOAD INTO DB HERE !!! :
                                    UploadEnvelope upload = new UploadEnvelope();

                                    string connString = "Server=" + _SERVER + "; Database=" + _DATABASE + "; Uid=" + dbLogin + "; Pwd=" + dbPassw + "";

                                    if (upload.EnvelopeUpload(_ENVELOPE_TBL, env, connString) != 0)
                                    // if (workWithDB.EnvelopeUpload(_ENVELOPE_TBL, env) != 0)  // OLD 2015 VERSION;
                                    {
                                        // IT MEANS - UPLOADED SUCCESSFULLY !

                                        File.AppendAllText(todayUploadedLog, env.envelopeName + " - " + env.fileName + Environment.NewLine);

                                        nLogger.Trace("{0}() - {1}", env.envelopeName, env.fileName);

                                        textBox_4_Tests_Only.Text += Environment.NewLine + DateTime.Now + " - " + env.envelopeName + " - " + env.fileName;
                                    }
                                }
                            }
                        }
                        nLogger.Trace("Job finished successfully.");

                        textBox_4_Tests_Only.Text += Environment.NewLine + DateTime.Now + " - Ok.";
                    }
                }
            }
            catch (Exception e)
            {
                nLogger.Error("{0}() - {1}", methodName, e.Message);
            }
        }
Exemplo n.º 2
0
        // MANUAL !!! UPLOAD "SPRUSNBU" INTO !!! OLD PROM !!! SQL FROM DBF:
        private void btnSprusnbuUpd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.DefaultExt = ".dbf";
                dlg.Filter = "DBF Files Only (*.dbf)|*.dbf";

                bool? dbfFileSelected = dlg.ShowDialog();

                if (dbfFileSelected == true)
                {
                    FileInfo dbfFile = new FileInfo(dlg.FileName);

                    string dbLogin = passwordBoxLogin.Password.Trim();
                    string dbPassw = passwordBoxPassw.Password.Trim();

                    if (dbLogin.Length < 1 || dbPassw.Length < 1)
                    {
                        MessageBox.Show("Set Login & Password Before!");
                    }
                    else
                    {
                        WorkWithDB_2015 workWithDB = new WorkWithDB_2015(_DATABASE, dbLogin, dbPassw);

                        MessageBox.Show(workWithDB.UpdateSprusnbuFromDbf(_SPRUSNBU_2014,
                            dbfFile.Directory.ToString(), dbfFile.Name));
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
Exemplo n.º 3
0
        // RUN TASKS USING SHCHEDULER :
        private void RunEveryFifteenMin(object sender, EventArgs e)
        {
            // DON'T RUN UNTIL 7 O'CLOCK FOR WAITHING ALL BACKUP TASKS HAS FINISHED :

            if (DateTime.Now.Hour > 7)
            {
                // TODO:  TEMPORARY AUTO SPRUSNBU UPLOADER !!!!!
                // TODO:  TEMPORARY AUTO SPRUSNBU UPLOADER !!!!!
                // TODO:  TEMPORARY AUTO SPRUSNBU UPLOADER !!!!!

                string dir4sprusnbu = "C:\\NBUMAIL\\SPRUSNBD4SQL\\";

                string log4sprusnbu = "NBU_Mailer_2016_Sprusnbu_Upload.log";

                string currentSprusFile = "SPRUSNBU.DBF";

                string todaySprusFilePath = dir4sprusnbu + DateTime.Now.ToString("yy-MM-dd") + ".SPRUSNBU.DBF";

                if ((DateTime.Now.Hour == 11 || DateTime.Now.Hour == 15) && DateTime.Now.Minute > 40)
                {
                    try
                    {
                        if (!Directory.Exists(dir4sprusnbu)) Directory.CreateDirectory(dir4sprusnbu);

                        bool currSprusAlreadyLoad = false;

                        FileInfo[] oldSprusFiles = new DirectoryInfo(dir4sprusnbu).GetFiles("*.dbf");

                        DateTime currSprusDate = new FileInfo("C:\\NBUMAIL\\" + currentSprusFile).LastWriteTime;

                        // MessageBox.Show(oldSprusFiles.Length + " files in " + dir4sprusnbu);

                        foreach (FileInfo file in oldSprusFiles)
                        {
                            if (file.LastWriteTime == currSprusDate)
                            {
                                currSprusAlreadyLoad = true;
                                break;
                            }
                        }

                        if (!currSprusAlreadyLoad)
                        {
                            // CREATE TEMPORARY FILE FOR ODBC UPLOADING :
                            File.Copy("C:\\NBUMAIL\\" + currentSprusFile, dir4sprusnbu + currentSprusFile);

                            string dbLogin = passwordBoxLogin.Password.Trim();
                            string dbPassw = passwordBoxPassw.Password.Trim();

                            // UPLOAD IN SQL - UPDATE 2016 !!!
                            // UPLOAD IN SQL - UPDATE 2016 !!!

                            string table = "SPRUSNBU_BANKS";

                            string connString = "Server=" + _SERVER + "; Database=" + _DATABASE + "; Uid=" + dbLogin + "; Pwd=" + dbPassw + "";

                            UploadDbfIntoSql uploadDbf = new UploadDbfIntoSql();


                            // UPLOAD 2 =SPRUSNBU= 4 NEW 2016 :

                            string uploadRez = uploadDbf.ReadDbfAndInsert(dir4sprusnbu + currentSprusFile, _DATABASE, table, connString);

                            File.AppendAllText(log4sprusnbu, "\r\n" + DateTime.Now + " - " + uploadRez);

                            // UPLOAD 2 =SPRUSNBU_BANKS= 4 OLD 2015

                            // UPLOAD IN SQL - OVERWRITE 2014 !!!
                            // UPLOAD IN SQL - OVERWRITE 2014 !!!

                            WorkWithDB_2015 workWithDB = new WorkWithDB_2015(_DATABASE, dbLogin, dbPassw);

                            string uploadRez2014 = workWithDB.UpdateSprusnbuFromDbf(_SPRUSNBU_2014, dir4sprusnbu, currentSprusFile);

                            File.AppendAllText(log4sprusnbu, "\r\n" + DateTime.Now + " - " + uploadRez2014);

                            System.Threading.Thread.Sleep(4000);

                            // STORE TEMPORARY FILE FOR NEXT TIME CHECKING :
                            File.Move(dir4sprusnbu + currentSprusFile, todaySprusFilePath);
                        }
                    }
                    catch (Exception exc)
                    {
                        File.AppendAllText(log4sprusnbu, "\r\n" + DateTime.Now + " - " + exc.Message);
                    }
                }
                ///////////////////////////////////////////////////////////
                ///////////////////////////////////////////////////////////

                ProcessEnvelopes();
            }
        }