Ejemplo n.º 1
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            string customerStart = string.IsNullOrEmpty(this.buttonEditCustomerStart.Text) ? null : this.buttonEditCustomerStart.Text;


            string customerEnd = string.IsNullOrEmpty(this.buttonEditCustomerEnd.Text) ? null : this.buttonEditCustomerEnd.Text;

            string mpsStart = this.comboBoxEditMpsStart.EditValue==null ? null : this.comboBoxEditMpsStart.EditValue.ToString();
            string mpsEnd = this.comboBoxEditMpsEnd.EditValue==null ? null : this.comboBoxEditMpsEnd.EditValue.ToString();

            DateTime dateStart = this.dateEditStart.DateTime.Year < 1500 ? Convert.ToDateTime("1900-01-01") : this.dateEditStart.DateTime;
            DateTime dateEnd = this.dateEditEnd.DateTime.Year < 1500 ? Convert.ToDateTime("3000-01-01") : this.dateEditEnd.DateTime;
            string productId = null;
            //if (this.newChooseProduct.EditValue != null)
            //{
            //    productId = this.newChooseProduct.EditValue.ToString();
            //}

            IList<Model.MPSdetails> mpsDetails = new BL.MPSdetailsManager().Select(customerStart, customerEnd, mpsStart, mpsEnd, dateStart, dateEnd, productId);
            
            if (mpsDetails.Count == 0)
            {
                MessageBox.Show("在此區間無進貨記錄"); return;
            }
            RO2 f = new RO2(mpsDetails, dateStart, dateEnd);
            f.ShowPreview();
        }
        /// <summary>
        /// Insert a ProduceOtherCompact.
        /// </summary>
        public void Insert(Model.ProduceOtherCompact produceOtherCompact)
        {
            //
            // todo:add other logic here
            //

            produceOtherCompact.InsertTime = DateTime.Now;
            produceOtherCompact.UpdateTime = DateTime.Now;
            Validate(produceOtherCompact);
            TiGuiExists(produceOtherCompact);
            try
            {
                if (this.ExistsPrimary(produceOtherCompact.ProduceOtherCompactId))
                {
                    produceOtherCompact.ProduceOtherCompactId = this.GetId();
                }

                BL.V.BeginTransaction();
                string invoiceKind = this.GetInvoiceKind().ToLower();
                //string sequencekey_y = string.Format("{0}-y-{1}", invoiceKind, produceOtherCompact.InsertTime.Value.Year);
                //string sequencekey_m = string.Format("{0}-m-{1}-{2}", invoiceKind, produceOtherCompact.InsertTime.Value.Year, produceOtherCompact.InsertTime.Value.Month);
                string sequencekey_d = string.Format("{0}-d-{1}", invoiceKind, produceOtherCompact.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);
                produceOtherCompact.InvoiceStatus = 1;
                accessor.Insert(produceOtherCompact);

                foreach (Model.ProduceOtherCompactDetail produceOtherCompactDetail in produceOtherCompact.Details)
                {
                    if (produceOtherCompactDetail.Product == null || string.IsNullOrEmpty(produceOtherCompactDetail.ProductId))
                    {
                        throw new Exception("貨品不為空");
                    }
                    if (produceOtherCompactDetail.OtherCompactCount < 0)
                    {
                        continue;
                    }
                    produceOtherCompactDetail.ProduceOtherCompactId = produceOtherCompact.ProduceOtherCompactId;
                    Model.MPSdetails mpsDal = new BL.MPSdetailsManager().Get(produceOtherCompactDetail.MPSDetailId);
                    //double Sum = new PronotedetailsManager().GetByMPSdetail(produceOtherCompactDetail.MPSDetailId);
                    if (mpsDal != null)
                    {
                        mpsDal.MPSHasSingleSum += produceOtherCompactDetail.OtherCompactCount;
                        if (mpsDal.MPSHasSingleSum == mpsDal.MPSdetailssum)
                        {
                            mpsDal.MPSEndState = true;
                        }
                        new BL.MPSdetailsManager().Update(mpsDal);
                    }
                    ProduceOtherCompactDetailAccessor.Insert(produceOtherCompactDetail);
                }
                foreach (Model.ProduceOtherCompactMaterial detailMaterial in produceOtherCompact.DetailMaterial)
                {
                    if (string.IsNullOrEmpty(detailMaterial.ProductId))
                    {
                        continue;
                    }
                    detailMaterial.ProduceOtherCompactId = produceOtherCompact.ProduceOtherCompactId;
                    //Model.MPSdetails mpsDal = new BL.MPSdetailsManager().Get(produceOtherCompactDetail.MPSDetailId);
                    ////double Sum = new PronotedetailsManager().GetByMPSdetail(produceOtherCompactDetail.MPSDetailId);
                    //if (mpsDal != null)
                    //{
                    //    mpsDal.MPSHasSingleSum += produceOtherCompactDetail.OtherCompactCount;
                    //    if (mpsDal.MPSHasSingleSum == mpsDal.MPSdetailssum)
                    //    {
                    //        mpsDal.MPSEndState = true;
                    //    }
                    //    new BL.MPSdetailsManager().Update(mpsDal);
                    //}
                    ProduceOtherCompactMaterialAccessor.Insert(detailMaterial);
                }



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