コード例 #1
0
        public DTO.QuotationMng.SearchFilterData GetFilterData(out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.QuotationMng.SearchFilterData data = new DTO.QuotationMng.SearchFilterData();
            data.Factories = new List <DTO.Support.Factory>();
            data.Seasons   = new List <DTO.Support.Season>();

            //try to get data
            try
            {
                // insert missing data for factory order
                using (QuotationMngEntities context = CreateContext())
                {
                    using (DbContextTransaction scope = context.Database.BeginTransaction())
                    {
                        context.Database.ExecuteSqlCommand("SELECT TOP 1 * FROM QuotationDetail WITH (TABLOCKX, HOLDLOCK)");
                        try
                        {
                            context.QuotationMng_function_InsertMissingFactoryOrderItem();
                            context.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            scope.Commit();
                        }
                    }
                }

                data.Factories = supportFactory.GetFactory().ToList();
                data.Seasons   = supportFactory.GetSeason().ToList();
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
コード例 #2
0
        public override bool UpdateData(int id, ref DTO.QuotationMng.Quotation dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (QuotationMngEntities context = CreateContext())
                {
                    Quotation dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new Quotation();
                        context.Quotation.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Quotation.FirstOrDefault(o => o.QuotationID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Quotation not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String)))
                        {
                            throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        converter.DTO2DB(dtoItem, ref dbItem);

                        // generate latest code - table locks required
                        if (id == 0)
                        {
                            using (DbContextTransaction scope = context.Database.BeginTransaction())
                            {
                                context.Database.ExecuteSqlCommand("SELECT TOP 1 * FROM Quotation WITH (TABLOCKX, HOLDLOCK)");
                                int    factoryID = dtoItem.FactoryID.Value;
                                string season    = dtoItem.Season;
                                try
                                {
                                    var quotations = context.Quotation.Where(o => o.FactoryID.HasValue && o.FactoryID.Value == factoryID && o.Season == season).ToList();
                                    int lastNumber = 1;
                                    if (quotations.Count > 0)
                                    {
                                        lastNumber = quotations.Max(o => Convert.ToInt32(o.QuotationUD.Substring(0, 3))) + 1;
                                    }
                                    dbItem.QuotationUD = Library.Common.Helper.formatIndex(lastNumber.ToString(), 3, "0") + "/" + dtoItem.FactoryUD.Substring(0, 3) + "/" + dtoItem.Season.Replace("/", "-");
                                    context.SaveChanges();
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                                finally
                                {
                                    scope.Commit();
                                }
                            }
                        }

                        context.QuotationDetail.Local.Where(o => o.Quotation == null).ToList().ForEach(o => context.QuotationDetail.Remove(o));
                        context.QuotationOffer.Local.Where(o => o.Quotation == null).ToList().ForEach(o => context.QuotationOffer.Remove(o));
                        context.QuotationOfferDetail.Local.Where(o => o.QuotationOffer == null || o.QuotationDetail == null).ToList().ForEach(o => context.QuotationOfferDetail.Remove(o));
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.QuotationID, 0, string.Empty, new List <int>(), 0, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = Library.Helper.GetInnerException(ex).Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }