public void LoadTemplate(FileInfo template) { //redundant condition checking if (template.Exists == false) { return; } // template doesn't exist do nothing.. if (_templateFile != null) { return; } //template already set, don't reload if (_fileHasTemplate == true) { return; } _templateFile = template; //insert meta data containing location of template file _database.WriteGlobalValue("CSM", "TemplatePath", template.FullName); try { _templateDatabase = new DAL(template.FullName); //only load FIX and PNT Cruise methods for Recon cruises CruiseMethods = _templateDatabase.GetCruiseMethods(this.Sale.Purpose == "Recon"); this.StartAsynCopyTemplate(_templateDatabase); } catch (Exception) { MessageBox.Show("Error: Couldn't open template"); } finally { if (_templateDatabase != null) { _templateDatabase.Dispose(); _templateDatabase = null; } } }
protected void CreateComponent(DAL masterDAL, int compNum, ComponentDO compInfo, String compPath) { //copy master to create component file masterDAL.CopyTo(compPath); var compDB = new DAL(compPath); try { compDB.BeginTransaction(); compDB.Execute("DELETE FROM CountTree WHERE Component_CN IS NOT NULL;"); compDB.Execute(SQL.CLEAR_FIELD_DATA); string command = string.Format("UPDATE CountTree Set Component_CN = {0};", compInfo.Component_CN); compDB.Execute(command); //Set the starting rowID for each component compDB.SetTableAutoIncrementStart("Tree", GetComponentRowIDStart(compNum)); compDB.SetTableAutoIncrementStart("Log", GetComponentRowIDStart(compNum)); compDB.SetTableAutoIncrementStart("TreeEstimate", GetComponentRowIDStart(compNum)); compDB.SetTableAutoIncrementStart("Stem", GetComponentRowIDStart(compNum)); compDB.SetTableAutoIncrementStart("Plot", compNum * PLOT_ROW_SPACING); compDB.Execute("DELETE FROM Globals WHERE Block = 'Comp' AND Key = 'ChildComponents';"); compDB.Execute("DELETE FROM Globals WHERE Block = 'Comp' AND Key = 'LastMerge';"); compDB.CommitTransaction(); } catch (Exception) { compDB.RollbackTransaction(); try { //component is probably jacked up, so delete it System.IO.File.Delete(compDB.Path); } catch { } //may throw exception if file doesn't exist, but we can ignore that } finally { compDB.Dispose(); } }