Beispiel #1
0
 protected override void AddNew()
 {
     Model.AcItem mac = new Book.Model.AcItem();
     mac.AcItemId   = Guid.NewGuid().ToString();
     mac.Id         = "01";
     mac.AcItemDate = DateTime.Now;
     mac.mState     = true;
     this._detail.Add(mac);
 }
Beispiel #2
0
        protected override void grid_keyDpwn()
        {
            //Model.Setting set = new Book.Model.Setting();
            //set.SettingId = Guid.NewGuid().ToString();
            //set.SettingTags = "PCISO";

            //this._detail.Add(set);
            //this.bindingSource1.Position = this.bindingSource1.IndexOf(set);
            //this.gridControl1.RefreshDataSource();
            Model.AcItem mac = new Book.Model.AcItem();
            mac.AcItemId   = Guid.NewGuid().ToString();
            mac.Id         = this._detail.Max(item => Convert.ToInt32(item.Id)).ToString();
            mac.AcItemDate = DateTime.Now;
            mac.mState     = true;
            this._detail.Add(mac);
            this.gridControl1.RefreshDataSource();
        }
        public void Insert(Model.AcOtherShouldPayment acOtherShouldPayment)
        {
            //
            // todo:add other logic here
            //
            Validate(acOtherShouldPayment);

            //获取数据库原有
            IList <Model.AcItem> dbAClist = AcItemaccessor.Select();

            try
            {
                acOtherShouldPayment.InsertTime = DateTime.Now;
                BL.V.BeginTransaction();
                string invoiceKind   = this.GetInvoiceKind().ToLower();
                string sequencekey_y = string.Format("{0}-y-{1}", invoiceKind, acOtherShouldPayment.InsertTime.Value.Year);
                string sequencekey_m = string.Format("{0}-m-{1}-{2}", invoiceKind, acOtherShouldPayment.InsertTime.Value.Year, acOtherShouldPayment.InsertTime.Value.Month);
                string sequencekey_d = string.Format("{0}-d-{1}", invoiceKind, acOtherShouldPayment.InsertTime.Value.ToString("yyyy-MM-dd"));
                string sequencekey   = string.Format(invoiceKind);

                SequenceManager.Increment(sequencekey_y);
                SequenceManager.Increment(sequencekey_m);
                SequenceManager.Increment(sequencekey_d);
                SequenceManager.Increment(sequencekey);


                accessor.Insert(acOtherShouldPayment);

                var Qgroup = from Model.AcOtherShouldPaymentDetail acspd in acOtherShouldPayment.Details
                             group acspd by acspd.LoanName;

                foreach (IGrouping <string, Model.AcOtherShouldPaymentDetail> item in Qgroup)
                {
                    if (!string.IsNullOrEmpty(item.Last <Model.AcOtherShouldPaymentDetail>().AcItemId))
                    {
                        Model.AcItem acitem = (from Model.AcItem ac in dbAClist
                                               where ac.AcItemId == item.Last().AcItemId
                                               select ac).First <Model.AcItem>();
                        acitem.ItemPrice = item.Last <Model.AcOtherShouldPaymentDetail>().AcItemPrice;
                        AcItemaccessor.Update(acitem);
                        continue;
                    }

                    if (dbAClist == null || dbAClist.Count == 0)
                    {
                        Model.AcItem acitem = new Book.Model.AcItem();
                        acitem.AcItemId   = Guid.NewGuid().ToString();
                        acitem.AcItemDate = DateTime.Now;
                        acitem.ItemName   = item.Last().LoanName;
                        acitem.ItemPrice  = item.Last().AcItemPrice;
                        AcItemaccessor.Insert(acitem);
                    }
                    else
                    {
                        IList <Model.AcItem> actQ = (from Model.AcItem ac in dbAClist
                                                     where ac.ItemName == item.Last().LoanName
                                                     select ac).ToList();

                        Model.AcItem act = null;
                        if (actQ != null && actQ.Count != 0)
                        {
                            act = actQ.First <Model.AcItem>();
                        }

                        if (act != null)
                        {
                            if (act.ItemPrice != item.Last().AcItemPrice)
                            {
                                act.ItemPrice = item.Last().AcItemPrice;
                                AcItemaccessor.Update(act);
                            }
                        }
                        else
                        {
                            Model.AcItem acitem = new Book.Model.AcItem();
                            acitem.AcItemId   = Guid.NewGuid().ToString();
                            acitem.AcItemDate = DateTime.Now;
                            acitem.ItemName   = item.Last().LoanName;
                            acitem.ItemPrice  = item.Last().AcItemPrice;
                            AcItemaccessor.Insert(acitem);
                        }
                    }
                }

                foreach (Model.AcOtherShouldPaymentDetail acOtherShouldPaymentDetail in acOtherShouldPayment.Details)
                {
                    acOtherShouldPaymentDetail.AcOtherShouldPaymentDetailId = Guid.NewGuid().ToString();
                    acOtherShouldPaymentDetail.AcOtherShouldPaymentId       = acOtherShouldPayment.AcOtherShouldPaymentId;

                    AcOtherShouldPaymentDetailAccessor.Insert(acOtherShouldPaymentDetail);
                }

                BL.V.CommitTransaction();
            }
            catch
            {
                BL.V.RollbackTransaction();
                throw;
            }
        }