Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine(string.Join(',', args));

            try
            {
                if (args.Length > 0)
                {
                    var convertArg = args[0];
                    if (File.Exists(convertArg) == false)
                    {
                        throw new FileNotFoundException("invalid file path", convertArg);
                    }

                    var filePath  = Path.GetFullPath(convertArg);
                    var directory = Path.GetDirectoryName(filePath);
                    var fileName  = Path.GetFileNameWithoutExtension(filePath);
                    var extention = Path.GetExtension(filePath).ToLower();

                    if (extention == ".cruise" || extention == ".cut")
                    {
                        var v3Path = Path.Combine(directory, fileName + ".crz3");
                        Console.WriteLine($"Converting {filePath} --> {v3Path}");

                        using (var v2Db = new DAL(filePath))
                            using (var v3Db = new CruiseDatastore_V3())
                            {
                                new Migrator().MigrateFromV2ToV3(v2Db, v3Db, deviceID: "CruiseCLI");
                                v3Db.BackupDatabase(v3Path);
                            }
                    }
                    else if (extention == ".crz3")
                    {
                        var v2Path = Path.Combine(directory, fileName + ".cruise");
                        Console.WriteLine($"Converting {filePath} --> {v2Path}");

                        using (var v2Db = new DAL())
                            using (var v3Db = new CruiseDatastore_V3(filePath))
                            {
                                var cruiseIDs = v3Db.QueryScalar <string>("SELECT CruiseID FROM Cruise;").ToArray();

                                if (cruiseIDs.Length > 1)
                                {
                                    throw new InvalidOperationException("More than one cruise found");
                                }
                                var cruiseID = cruiseIDs.Single();

                                var downMigrator = new DownMigrator();

                                downMigrator.MigrateFromV3ToV2(cruiseID, v3Db, v2Db, createdBy: "CruiseCLI");
                                v2Db.BackupDatabase(v2Path);
                            }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.ReadLine();
            }
        }
Example #2
0
        }   //  end onEquations

        private void onFile(object sender, EventArgs e)
        {
            //  clear filename in case user wants to change files
            fileName = "";
            //  Create an instance of the open file dialog
            OpenFileDialog browseDialog = new OpenFileDialog();

            //  Set filter options and filter index
            browseDialog.Filter      = "Cruise Files - V2 |*.cruise|Cruise Files - V3|*.crz3|All Files|*.*";
            browseDialog.FilterIndex = 1;

            browseDialog.Multiselect = false;

            //  February 2017 -- nowhave the option to edit volume equations and selected reports
            //  on template files.  Need a flag indicating it is a template file so some
            //  tasks are skipped that would apply to just cruise files.
            templateFlag = 0;
            //  capture filename selected
            while (fileName == "" || fileName == null)
            {
                DialogResult dResult = browseDialog.ShowDialog();

                if (dResult == DialogResult.Cancel)
                {
                    return;
                }
                if (dResult == DialogResult.OK)
                {
                    fileName = browseDialog.FileName;
                    if (fileName.EndsWith(".cut") || fileName.EndsWith(".CUT"))
                    {
                        //  disable all buttons except equations and reports
                        menuButton2.BackgroundImage = Properties.Resources.button_image;
                        menuButton3.BackgroundImage = Properties.Resources.button_image;
                        processBtn.BackgroundImage  = Properties.Resources.disabled_button;
                        menuButton5.BackgroundImage = Properties.Resources.disabled_button;
                        menuButton2.Enabled         = true;
                        menuButton3.Enabled         = true;
                        processBtn.Enabled          = false;
                        menuButton5.Enabled         = false;

                        //  Have user enter a different file to preserve the regional tempalte file
                        DialogResult dr = MessageBox.Show("Do you want to use a different filename for any changes made?", "QUESTION", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (dr == DialogResult.Yes)
                        {
                            //  show dialog to captue new filanem
                            EnterNewFilename enf = new EnterNewFilename();
                            enf.ShowDialog();
                            //  copy original file to new filename
                            string pathName = Path.GetDirectoryName(fileName);
                            pathName       += "\\";
                            newTemplateFile = enf.templateFilename;
                            newTemplateFile = newTemplateFile.Insert(0, pathName);
                            File.Copy(fileName, newTemplateFile, true);
                            fileName     = newTemplateFile;
                            DAL          = new DAL(newTemplateFile);
                            templateFlag = 1;
                        }
                        else if (dr == DialogResult.No)
                        {
                            //fileName = fileName;
                            DAL = new DAL(fileName);
                            if (fileName.EndsWith(".CUT") || fileName.EndsWith(".cut"))
                            {
                                newTemplateFile = fileName;
                                templateFlag    = 1;
                            }
                            else
                            {
                                templateFlag = 0;
                            }
                        }   //  endif
                    }
                    else if (!fileName.EndsWith(".cruise") && !fileName.EndsWith(".CRUISE"))
                    {
                        if (!fileName.EndsWith(".crz3") && !fileName.EndsWith(".CRZ3"))
                        {
                            //  is it a cruise file?
                            MessageBox.Show("File selected is not a cruise file.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            DAL_V3 = new CruiseDatastore_V3(fileName);

                            string V2FileName = fileName.Replace(".crz3", "").Replace(".CRZ3", "");

                            //V2FileName = V2FileName + "WBTest.cruise";
                            V2FileName = V2FileName + ".process";

                            try
                            {
                                var cruiseIDs = DAL_V3.QueryScalar <string>("SELECT CruiseID FROM Cruise;").ToArray();
                                if (cruiseIDs.Length > 1)
                                {
                                    MessageBox.Show("File contains multiple cruises. \r\nOpening files with multiple cruises is not supported yet", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }

                                var cruiseID = cruiseIDs.First();

                                string cruiseV2Path = V2FileName;


                                CruiseDatastoreBuilder_V2 V2Builder = new CruiseDatastoreBuilder_V2();
                                Updater_V2 v2Updater = new Updater_V2();

                                CruiseDatastore myV2DAL = new DAL(cruiseV2Path, true);
                                //CruiseDatastore v2DB = new CruiseDatastore(cruiseV2Path, true, V2Builder, v2Updater);


                                DownMigrator myMyigrator = new DownMigrator();

                                string error_message = "";
                                if (myMyigrator.EnsureCanMigrate(cruiseID, DAL_V3, out error_message))
                                {
                                    //CONVERT LOGIC NEEDED HERE.
                                    myMyigrator.MigrateFromV3ToV2(cruiseID, DAL_V3, myV2DAL);
                                    fileName = V2FileName;
                                }//end if
                                else
                                {
                                    MessageBox.Show("This version 3 file has issues. \r\nError: " + error_message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }//end else
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("This version 3 file has issues. \r\n", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }   //  endif
                }
            }
            ;   //  end while

            if (templateFlag == 0)
            {
                //  check for fatal errors before doing anything else --  October 20145
                //fileName = fileName;
                DAL = new DAL(fileName);

                //open connection forces the connection to remain open not to close and open.  Might be good to re-work the process button click?
                DAL.OpenConnection();

                string[] errors;
                //               bool ithResult = bslyr.DAL.HasCruiseErrors(out errors);
                bool ithResult = false;
                if (ithResult)
                {
                    MessageBox.Show("This file has errors which affect processing.\nCannot continue until these are fixed in CruiseManager.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    menuButton2.BackgroundImage = Properties.Resources.disabled_button;
                    menuButton3.BackgroundImage = Properties.Resources.disabled_button;
                    processBtn.BackgroundImage  = Properties.Resources.disabled_button;
                    menuButton5.BackgroundImage = Properties.Resources.disabled_button;
                    menuButton2.Enabled         = false;
                    menuButton3.Enabled         = false;
                    processBtn.Enabled          = false;
                    menuButton5.Enabled         = false;
                    return;
                }   //  end check for fatal errors

                // if filename is not blank, enable remaining menu buttons
                if (fileName.Contains(".cruise") || fileName.Contains(".CRUISE") || fileName.Contains(".process") || fileName.Contains(".PROCESS"))
                {
                    menuButton2.BackgroundImage = Properties.Resources.button_image;
                    menuButton3.BackgroundImage = Properties.Resources.button_image;
                    processBtn.BackgroundImage  = Properties.Resources.button_image;
                    menuButton5.BackgroundImage = Properties.Resources.button_image;

                    menuButton2.Enabled = true;
                    menuButton3.Enabled = true;
                    processBtn.Enabled  = true;
                    menuButton5.Enabled = true;

                    //  need region number in order to hide volume button as well as region 9 button
                    List <SaleDO> saleList = new List <SaleDO>();
                    saleList      = DAL.From <SaleDO>().Read().ToList();
                    currentRegion = saleList[0].Region;
                } //  endif
            }     //  endif tempalteFlag
            //  add file name to title line at top
            if (fileName.Length > 35)
            {
                string tempName = "..." + fileName.Substring(fileName.Length - 35, 35);
                Text = tempName;
            } //  endif fileName
        }     //  end onFile