예제 #1
0
 public override DTO.EditFormData GetData(int id, out Library.DTO.Notification notification)
 {
     DTO.EditFormData editFormData = new DTO.EditFormData();
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (ProductionPriceMngEntities context = CreateContext())
         {
             ProductionPriceMng_ProductionPrice_View dbItem;
             dbItem            = context.ProductionPriceMng_ProductionPrice_View.FirstOrDefault(o => o.ProductionPriceID == id);
             editFormData.Data = converter.DB2DTO_ProductionPrice(dbItem);
             return(editFormData);
         }
     }
     catch (Exception ex)
     {
         Exception iEx = Library.Helper.GetInnerException(ex);
         notification.Type    = NotificationType.Error;
         notification.Message = iEx.Message;
         return(editFormData);
     }
 }
예제 #2
0
 public List <DTO.ReceiptByProductionItem> GetReceiptByProductionItem(int userId, int productionItemID, int month, int year, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         int?companyID = fw_factory.GetCompanyID(userId);
         using (ProductionPriceMngEntities context = CreateContext())
         {
             List <DTO.ReceiptByProductionItem> data = new List <DTO.ReceiptByProductionItem>();
             var x = context.ProductionPriceMng_function_GetReceiptByProductionItem(companyID, productionItemID, month, year).ToList();
             data = AutoMapper.Mapper.Map <List <ProductionPriceMng_ReceiptByProductionItem_View>, List <DTO.ReceiptByProductionItem> >(x);
             return(data);
         }
     }
     catch (Exception ex)
     {
         Exception iEx = Library.Helper.GetInnerException(ex);
         notification.Type    = NotificationType.Error;
         notification.Message = iEx.Message;
         return(null);
     }
 }
예제 #3
0
        public int?CalculateAvgPrice(int userId, int productionItemTypeID, int month, int year, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                DateTime currentDate  = new DateTime(year, month, 1);
                DateTime previousDate = currentDate.AddMonths(-1);

                using (ProductionPriceMngEntities context = CreateContext())
                {
                    int?companyID = fw_factory.GetCompanyID(userId);
                    List <DTO.AvgPriceDTO> data = new List <DTO.AvgPriceDTO>();
                    var x = context.ProductionPriceMng_function_CalculateAvgPrice(userId, companyID, productionItemTypeID, currentDate.Month, currentDate.Year, previousDate.Month, previousDate.Year).ToList();
                    return(x.FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                Exception iEx = Library.Helper.GetInnerException(ex);
                notification.Type    = NotificationType.Error;
                notification.Message = iEx.Message;
                return(null);
            }
        }
예제 #4
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.ProductionPriceDTO dtoProductionPrice = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ProductionPriceDTO>();
            try
            {
                int?companyID = fw_factory.GetCompanyID(userId);
                using (ProductionPriceMngEntities context = CreateContext())
                {
                    ProductionPrice dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ProductionPrice();
                        context.ProductionPrice.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ProductionPrice.Where(o => o.ProductionPriceID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //convert dto to db
                        converter.DTO2DB_ProductionPrice(dtoProductionPrice, ref dbItem, userId, companyID);
                        //remove orphan
                        context.ProductionPriceDetail.Local.Where(o => o.ProductionPrice == null).ToList().ForEach(o => context.ProductionPriceDetail.Remove(o));

                        //save data
                        context.SaveChanges();

                        // Run automatic update unit price
                        if (dtoProductionPrice.UpdateTypeID.HasValue && dtoProductionPrice.UpdateTypeID.Value == 2)
                        {
                            context.ProductionPriceMng_function_UpdatePriceReceivingNote(dbItem.ProductionPriceID);
                        }

                        //get return data
                        dtoItem = GetData(dbItem.ProductionPriceID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                Exception iEx = Library.Helper.GetInnerException(ex);
                notification.Type    = NotificationType.Error;
                notification.Message = iEx.Message;
                return(false);
            }
        }
예제 #5
0
 private bool SaveDataBeforeLock(int userId, int id, DTO.ProductionPriceDTO dtoProductionPrice, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         int?companyID = fw_factory.GetCompanyID(userId);
         using (ProductionPriceMngEntities context = CreateContext())
         {
             ProductionPrice dbItem = null;
             if (id == 0)
             {
                 dbItem = new ProductionPrice();
                 context.ProductionPrice.Add(dbItem);
             }
             else
             {
                 dbItem = context.ProductionPrice.Where(o => o.ProductionPriceID == id).FirstOrDefault();
             }
             if (dbItem == null)
             {
                 notification.Message = "data not found!";
                 return(false);
             }
             else
             {
                 //convert dto to db
                 converter.DTO2DB_ProductionPrice(dtoProductionPrice, ref dbItem, userId, companyID);
                 //remove orphan
                 context.ProductionPriceDetail.Local.Where(o => o.ProductionPrice == null).ToList().ForEach(o => context.ProductionPriceDetail.Remove(o));
                 //save data
                 context.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Exception iEx = Library.Helper.GetInnerException(ex);
         notification.Type    = NotificationType.Error;
         notification.Message = iEx.Message;
         return(false);
     }
 }
예제 #6
0
        public DTO.EditFormData GetData(int userId, int id, Hashtable param, out Library.DTO.Notification notification)
        {
            DTO.EditFormData editFormData = new DTO.EditFormData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ProductionPriceMngEntities context = CreateContext())
                {
                    int?companyID = fw_factory.GetCompanyID(userId);
                    if (id > 0)
                    {
                        ProductionPriceMng_ProductionPrice_View dbItem;
                        dbItem            = context.ProductionPriceMng_ProductionPrice_View.FirstOrDefault(o => o.ProductionPriceID == id);
                        editFormData.Data = converter.DB2DTO_ProductionPrice(dbItem);
                    }
                    else
                    {
                        //initialize item data base on selected workorder
                        int productionItemTypeID = Convert.ToInt32(param["productionItemTypeID"]);
                        int month = Convert.ToInt32(param["month"]);
                        int year  = Convert.ToInt32(param["year"]);

                        editFormData.Data.ProductionItemTypeID = productionItemTypeID;
                        editFormData.Data.Month = month;
                        editFormData.Data.Year  = year;
                        editFormData.Data.ProductionItemTypeNM = new Module.Support.DAL.DataFactory().GetProductionItemType().Where(o => o.ProductionItemTypeID == productionItemTypeID).FirstOrDefault().ProductionItemTypeNM;

                        //calculate average price of all receiving receipt
                        editFormData.Data.ProductionPriceID = this.CalculateAvgPrice(userId, productionItemTypeID, month, year, out notification);
                    }
                    return(editFormData);
                }
            }
            catch (Exception ex)
            {
                Exception iEx = Library.Helper.GetInnerException(ex);
                notification.Type    = NotificationType.Error;
                notification.Message = iEx.Message;
                return(editFormData);
            }
        }
예제 #7
0
 public int?ApplyPriceOnReceipt(int productionPriceID, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (ProductionPriceMngEntities context = CreateContext())
         {
             int result = context.ProductionPriceMng_function_UpdatePriceReceivingNote(productionPriceID);
             return(result);
         }
     }
     catch (Exception ex)
     {
         Exception iEx = Library.Helper.GetInnerException(ex);
         notification.Type    = NotificationType.Error;
         notification.Message = iEx.Message;
         return(null);
     }
 }
예제 #8
0
 public override bool DeleteData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (ProductionPriceMngEntities context = CreateContext())
         {
             var dbItem = context.ProductionPrice.Where(o => o.ProductionPriceID == id).FirstOrDefault();
             context.ProductionPrice.Remove(dbItem);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         Exception iEx = Library.Helper.GetInnerException(ex);
         notification.Type    = NotificationType.Error;
         notification.Message = iEx.Message;
         return(false);
     }
 }
예제 #9
0
        public DTO.SearchFormData GetDataWithFilter(int userId, Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            DTO.SearchFormData searchFormData = new DTO.SearchFormData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            totalRows = 0;
            try
            {
                int? companyID            = fw_factory.GetCompanyID(userId);
                int? productionItemTypeID = null;
                int? month    = null;
                int? year     = null;
                bool?isLocked = null;

                if (filters.ContainsKey("productionItemTypeID") && filters["productionItemTypeID"] != null)
                {
                    productionItemTypeID = Convert.ToInt32(filters["productionItemTypeID"]);
                }
                if (filters.ContainsKey("month") && filters["month"] != null)
                {
                    month = Convert.ToInt32(filters["month"]);
                }
                if (filters.ContainsKey("year") && filters["year"] != null)
                {
                    year = Convert.ToInt32(filters["year"]);
                }
                if (filters.ContainsKey("isLocked") && filters["isLocked"] != null && !string.IsNullOrEmpty(filters["isLocked"].ToString()))
                {
                    switch (filters["isLocked"].ToString().ToLower())
                    {
                    case "true":
                        isLocked = true;
                        break;

                    case "false":
                        isLocked = false;
                        break;

                    default:
                        isLocked = null;
                        break;
                    }
                }
                using (ProductionPriceMngEntities context = CreateContext())
                {
                    totalRows = context.ProductionPriceMng_function_SearchProductionPrice(orderBy, orderDirection, companyID, productionItemTypeID, month, year, isLocked).Count();
                    var result = context.ProductionPriceMng_function_SearchProductionPrice(orderBy, orderDirection, companyID, productionItemTypeID, month, year, isLocked);
                    searchFormData.Data = converter.DB2DTO_ProductionPriceSearch(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
                return(searchFormData);
            }
            catch (Exception ex)
            {
                Exception iEx = Library.Helper.GetInnerException(ex);
                notification.Type    = NotificationType.Error;
                notification.Message = iEx.Message;
                return(searchFormData);
            }
        }