} // 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 (.cruise)|*.cruise|(.CRUIISE)|*.CRUISE|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) { DialogResult dnr = MessageBox.Show("No filename selected. Do you really want to cancel?", "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dnr == DialogResult.Yes) { 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; menuButton4.BackgroundImage = Properties.Resources.disabled_button; menuButton5.BackgroundImage = Properties.Resources.disabled_button; menuButton2.Enabled = true; menuButton3.Enabled = true; menuButton4.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); //Global.BL.fileName = newTemplateFile; Global.Init(new CPbusinessLayer(new CruiseDAL.DAL(newTemplateFile), newTemplateFile)); templateFlag = 1; } else if (dr == DialogResult.No) { Global.Init(new CPbusinessLayer(new CruiseDAL.DAL(newTemplateFile), newTemplateFile)); if (fileName.EndsWith(".CUT") || fileName.EndsWith(".cut")) { newTemplateFile = fileName; templateFlag = 1; } else { templateFlag = 0; } } // endif } else if (!fileName.EndsWith(".cruise") && !fileName.EndsWith(".CRUISE")) { // is it a cruise file? MessageBox.Show("File selected is not a cruise file.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // endif } } ; // end while if (templateFlag == 0) { // check for fatal errors before doing anything else -- October 2014 Global.Init(new CPbusinessLayer(new CruiseDAL.DAL(fileName), fileName)); string[] errors; // bool ithResult = Global.BL.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; menuButton4.BackgroundImage = Properties.Resources.disabled_button; menuButton5.BackgroundImage = Properties.Resources.disabled_button; menuButton2.Enabled = false; menuButton3.Enabled = false; menuButton4.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")) { menuButton2.BackgroundImage = Properties.Resources.button_image; menuButton3.BackgroundImage = Properties.Resources.button_image; menuButton4.BackgroundImage = Properties.Resources.button_image; menuButton5.BackgroundImage = Properties.Resources.button_image; menuButton2.Enabled = true; menuButton3.Enabled = true; menuButton4.Enabled = true; menuButton5.Enabled = true; // need region number in order to hide volume button as well as region 9 button currentRegion = Global.BL.getRegion(); } // 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
} // 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