private void SaveTallyBySampleGroup() { //this.Database.BeginTransaction(); try { if (!IsTallyModeLocked) { //remove any possible tally by species records string command = "DELETE FROM CountTree WHERE SampleGroup_CN = ? AND ifnull(TreeDefaultValue_CN, 0) != 0;"; DAL.Execute(command, SampleGroup_CN); string user = DAL.User; String makeCountsCommand = String.Format(@"INSERT OR Ignore INTO CountTree (CuttingUnit_CN, SampleGroup_CN, CreatedBy) Select CuttingUnitStratum.CuttingUnit_CN, SampleGroup.SampleGroup_CN, '{0}' AS CreatedBy From SampleGroup INNER JOIN CuttingUnitStratum ON SampleGroup.Stratum_CN = CuttingUnitStratum.Stratum_CN WHERE SampleGroup.SampleGroup_CN = {1};", user, SampleGroup_CN); DAL.Execute(makeCountsCommand); } TallyVM tally = DAL.From<TallyVM>() .Where("Description = ? AND HotKey = ?") .Query(SgTallie.Description, SgTallie.Hotkey) .FirstOrDefault(); if (tally == null) { tally = new TallyVM(DAL) { Description = SgTallie.Description , Hotkey = SgTallie.Hotkey }; //tally = sgVM.SgTallie; tally.Save(); } String setTallyCommand = String.Format("UPDATE CountTree Set Tally_CN = {0} WHERE SampleGroup_CN = {1};", tally.Tally_CN, SampleGroup_CN); DAL.Execute(setTallyCommand); //this.Database.EndTransaction(); } catch (Exception) { //this.Database.CancelTransaction(); throw; } }
private void SaveTallyBySpecies() { //this.Database.BeginTransaction(); try { if (!IsTallyModeLocked) { //remove any preexisting tally by sg entries string command = "DELETE FROM CountTree WHERE SampleGroup_CN = ? AND ifnull(TreeDefaultValue_CN, 0) = 0;"; DAL.Execute(command, SampleGroup_CN); string user = DAL.User; String makeCountsCommand = String.Format(@"INSERT OR IGNORE INTO CountTree (CuttingUnit_CN, SampleGroup_CN, TreeDefaultValue_CN, CreatedBy) Select CuttingUnitStratum.CuttingUnit_CN, SampleGroup.SampleGroup_CN, SampleGroupTreeDefaultValue.TreeDefaultValue_CN, '{0}' AS CreatedBy From SampleGroup INNER JOIN CuttingUnitStratum ON SampleGroup.Stratum_CN = CuttingUnitStratum.Stratum_CN INNER JOIN SampleGroupTreeDefaultValue ON SampleGroupTreeDefaultValue.SampleGroup_CN = SampleGroup.SampleGroup_CN WHERE SampleGroup.SampleGroup_CN = {1};", user, SampleGroup_CN); DAL.Execute(makeCountsCommand); } foreach (KeyValuePair<TreeDefaultValueDO, TallyVM> pair in Tallies) { TallyVM tally = DAL.From<TallyVM>() .Where("Description = ? AND HotKey = ?") .Query(pair.Value.Description, pair.Value.Hotkey) .FirstOrDefault(); if (tally == null) { tally = new TallyVM(DAL) { Description = pair.Value.Description, Hotkey = pair.Value.Hotkey }; //tally = pair.Value; //tally.DAL = Controller.Database; tally.Save(); } string setTallyCommand = String.Format("UPDATE CountTree Set Tally_CN = {0} WHERE SampleGroup_CN = {1} AND TreeDefaultValue_CN = {2}", tally.Tally_CN, SampleGroup_CN, pair.Key.TreeDefaultValue_CN); DAL.Execute(setTallyCommand); } //this.Database.EndTransaction(); } catch (Exception) { //this.Database.CancelTransaction(); throw; } }
private void SaveTallyBySampleGroup(TallySetupSampleGroup sgVM) { if ((sgVM.TallyMethod & TallyMode.Locked) != TallyMode.Locked) { //remove any possible tally by species records string command = "DELETE FROM CountTree WHERE SampleGroup_CN = ? AND ifnull(TreeDefaultValue_CN, 0) != 0;"; this.Database.Execute(command, sgVM.SampleGroup_CN); string user = this.Database.User; String makeCountsCommand = String.Format(@"INSERT OR Ignore INTO CountTree (CuttingUnit_CN, SampleGroup_CN, CreatedBy) Select CuttingUnitStratum.CuttingUnit_CN, SampleGroup.SampleGroup_CN, '{0}' AS CreatedBy From SampleGroup INNER JOIN CuttingUnitStratum ON SampleGroup.Stratum_CN = CuttingUnitStratum.Stratum_CN WHERE SampleGroup.SampleGroup_CN = {1};", user, sgVM.SampleGroup_CN); this.Database.Execute(makeCountsCommand); } TallyVM tally = this.Database.From<TallyVM>() .Where("Description = ? AND HotKey = ?") .Query(sgVM.SgTallie.Description, sgVM.SgTallie.Hotkey).FirstOrDefault(); if (tally == null) { tally = new TallyVM(this.Database) { Description = sgVM.SgTallie.Description, Hotkey = sgVM.SgTallie.Hotkey }; //tally = sgVM.SgTallie; tally.Save(); } String setTallyCommand = String.Format("UPDATE CountTree Set Tally_CN = {0} WHERE SampleGroup_CN = {1};", tally.Tally_CN, sgVM.SampleGroup_CN); this.Database.Execute(setTallyCommand); }