コード例 #1
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);
            if (this.DialogResult == DialogResult.Cancel)
            {
                return;
            }
            else if (this.DialogResult == DialogResult.OK)
            {
                this._BS_Tally.EndEdit();
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    this.Controller.DataStore.BeginTransaction();
                    if ((this.SampleGroup.TallyMethod & CruiseDAL.Enums.TallyMode.BySampleGroup) == CruiseDAL.Enums.TallyMode.BySampleGroup)
                    {
                        if (this.Tally.IsPersisted == false)
                        {
                            TallyDO t = this.Controller.DataStore.From <TallyDO>()
                                        .Where("Description = ? and Hotkey = ?")
                                        .Read(this.Tally.Description
                                              , this.Tally.Hotkey).FirstOrDefault();
                            if (t != null)
                            {
                                this.Tally = t;
                            }
                            else
                            {
                                this.Tally.Save();
                            }
                        }

                        string createCountsCommand = 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};", this.Controller.DataStore.User, this.SampleGroup.SampleGroup_CN);
                        this.Controller.DataStore.Execute(createCountsCommand);
                        string setTallyRefCommand = String.Format("UPDATE CountTree SET Tally_CN = {0} WHERE SampleGroup_CN = {1} AND ifnull(TreeDefaultValue_CN, 0) = 0",
                                                                  this.Tally.Tally_CN, this.SampleGroup.SampleGroup_CN);
                        this.Controller.DataStore.Execute(setTallyRefCommand);
                    }
                    else if ((this.SampleGroup.TallyMethod & CruiseDAL.Enums.TallyMode.BySpecies) == CruiseDAL.Enums.TallyMode.BySpecies)
                    {
                        string creatCountsBySpeciesCommand = 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};", this.Controller.DataStore.User, this.SampleGroup.SampleGroup_CN);
                        this.Controller.DataStore.Execute(creatCountsBySpeciesCommand);

                        foreach (TreeDefaultValueDO tdv in this.SampleGroup.TreeDefaultValues)
                        {
                            TallyDO tally = tdv.Tag as TallyDO;
                            if (tally == null)
                            {
                                e.Cancel = true;
                                return;
                            }

                            if (tally.IsPersisted == false)
                            {
                                TallyDO t = this.Controller.DataStore.From <TallyDO>()
                                            .Where("Description = ? and Hotkey = ?")
                                            .Read(tally.Description, tally.Hotkey).FirstOrDefault();
                                if (t != null)
                                {
                                    tally = t;
                                }
                                else
                                {
                                    tally.Save();
                                }
                            }

                            string setTallyRefCommand = String.Format("UPDATE CountTree SET Tally_CN = {0} WHERE SampleGroup_CN = {1} AND TreeDefaultValue_CN = {2}",
                                                                      tally.Tally_CN, this.SampleGroup.SampleGroup_CN, tdv.TreeDefaultValue_CN);
                            this.Controller.DataStore.Execute(setTallyRefCommand);
                        }
                    }
                    this.Controller.DataStore.CommitTransaction();
                }
                catch (Exception ex)
                {
                    this.Controller.DataStore.RollbackTransaction();
                    this.Controller.HandleNonCriticalException(ex, "Some thing went wrong while saving");
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
        }
コード例 #2
0
        private CruiseDAL.DAL CreateDatastore(string cruiseMethod, int freqORkz, int insuranceFreq)
        {
            var ds = new CruiseDAL.DAL();

            try
            {
                var sale = new SaleDO()
                {
                    DAL               = ds,
                    SaleNumber        = "12345",
                    Region            = "1",
                    Forest            = "1",
                    District          = "1",
                    Purpose           = "something",
                    LogGradingEnabled = true
                };
                sale.Save();

                var stratum = new StratumDO()
                {
                    DAL    = ds,
                    Code   = "01",
                    Method = cruiseMethod
                };
                stratum.Save();

                var cuttingUnit = new CuttingUnitDO()
                {
                    DAL  = ds,
                    Code = "01"
                };
                cuttingUnit.Save();

                var cust = new CuttingUnitStratumDO()
                {
                    DAL         = ds,
                    CuttingUnit = cuttingUnit,
                    Stratum     = stratum
                };
                cust.Save();

                var sampleGroup = new SampleGroupDO()
                {
                    DAL                = ds,
                    Stratum            = stratum,
                    Code               = "01",
                    PrimaryProduct     = "01",
                    UOM                = "something",
                    CutLeave           = "something",
                    InsuranceFrequency = insuranceFreq
                };

                if (CruiseMethods.THREE_P_METHODS.Contains(cruiseMethod))
                {
                    sampleGroup.KZ = freqORkz;
                }
                else
                {
                    sampleGroup.SamplingFrequency = freqORkz;
                }

                sampleGroup.Save();

                var tally = new TallyDO()
                {
                    DAL         = ds,
                    Hotkey      = "A",
                    Description = "something"
                };
                tally.Save();

                var count = new CountTreeDO()
                {
                    DAL         = ds,
                    CuttingUnit = cuttingUnit,
                    SampleGroup = sampleGroup,
                    Tally       = tally
                };
                count.Save();

                return(ds);
            }
            catch
            {
                ds.Dispose();
                throw;
            }
        }