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(); } }
protected void MakeComponents(DAL parentDB, int numComponents) { //start up the progress bar int totalSteps = numComponents + 4; View.InitializeAndShowProgress(totalSteps); if (!_doesMasterExist) { //initialize a master component file //create a master component by creating a copy of the parent parentDB.CopyTo(_masterPath); MasterDAL = new DAL(_masterPath); ////clean the master file, any field data from the original file will be removed //ClearFieldData(masterDAL); } View.StepProgressBar();///////////////////////////////////////////////// //insert component records into the master file List<ComponentDO> componentInfo = BuildMasterComponentTable(MasterDAL, numComponents); View.StepProgressBar();///////////////////////////////////////////////// int curCompNum = 1; String saveDir = GetSaveDir(MasterDAL.Path); foreach (ComponentDO comp in componentInfo) { String compPath = string.Format("{0}\\{1}", saveDir, comp.FileName);//extrapolate the path of the comp file if (!File.Exists(compPath)) { CreateComponent(MasterDAL, curCompNum++, comp, compPath); } View.StepProgressBar();////////////////////////////////////////////// } //create count record copies in the master for each component MasterDAL.Execute(SQL.MAKE_COUNTS_FOR_COMPONENTS); View.StepProgressBar();///////////////////////////////////////////////// //add some meta data to the master GlobalsDO lastMergeEntry = new GlobalsDO(MasterDAL) { Block = "Comp", Key = "LastMerge", Value = string.Empty }; lastMergeEntry.Save(OnConflictOption.Ignore); GlobalsDO numCompEntry = new GlobalsDO(MasterDAL) { Block = "Comp", Key = "ChildComponents", Value = numComponents.ToString() }; numCompEntry.Save(OnConflictOption.Replace); View.StepProgressBar();///////////////////////////////////////////////// View.HideProgressBar(); }