Пример #1
0
        public bool ImportExcelData(int userId, ref object dtoItem, out Library.DTO.Notification notification)
        {
            List <DTO.ImportFactoryBreakdown> dtoFactoryBreakdowns = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <DTO.ImportFactoryBreakdown> >();

            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryBreakdownMngEntities context = CreateContext())
                {
                    foreach (DTO.ImportFactoryBreakdown dtoFactoryBreakdown in dtoFactoryBreakdowns.ToList())
                    {
                        FactoryBreakdown dbFactoryBreakdown;
                        dbFactoryBreakdown = context.FactoryBreakdown.FirstOrDefault(o => o.FactoryBreakdownID == dtoFactoryBreakdown.FactoryBreakdownID);
                        converter.DTO2DB_ImportFactoryBreakdown(dtoFactoryBreakdown, ref dbFactoryBreakdown, userId);
                    }

                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
Пример #2
0
        public override bool Approve(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryBreakdownMngEntities context = CreateContext())
                {
                    FactoryBreakdown dbItem = context.FactoryBreakdown.FirstOrDefault(o => o.FactoryBreakdownID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Factory breakdown not found!";
                        return(false);
                    }
                    else
                    {
                        // check data access permission
                        if (dbItem.SampleProductID.HasValue)
                        {
                            if (CheckSamplePermission(userId, dbItem.SampleProductID.Value) <= 0)
                            {
                                throw new Exception("Data access not authorized!");
                            }
                        }
                        //else
                        //{
                        //    throw new Exception("Invalid sample product data! (id null)");
                        //}

                        // validate data
                        if (!dbItem.IndicatedPrice.HasValue || dbItem.IndicatedPrice <= 0)
                        {
                            throw new Exception("Invalid indicated price!");
                        }
                        FactoryBreakdownDetail dbDetail = dbItem.FactoryBreakdownDetail.FirstOrDefault(o => o.FactoryBreakdownCategoryID == 11); // load ability
                        if (dbDetail == null || !dbDetail.Quantity.HasValue || dbDetail.Quantity <= 0)
                        {
                            throw new Exception("Invalid load ability!");
                        }

                        dbItem.IsConfirmed   = true;
                        dbItem.ConfirmedBy   = userId;
                        dbItem.ConfirmedDate = DateTime.Now;
                        context.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
Пример #3
0
 private int CheckSamplePermission(int userId, int sampleProductId)
 {
     using (FactoryBreakdownMngEntities context = CreateContext())
     {
         try
         {
             return(context.FactoryBreakdownMng_function_CheckSamplePermission(userId, sampleProductId).FirstOrDefault().Value);
         }
         catch { }
     }
     return(0);
 }
Пример #4
0
        public override bool Reset(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryBreakdownMngEntities context = CreateContext())
                {
                    FactoryBreakdown dbItem = context.FactoryBreakdown.FirstOrDefault(o => o.FactoryBreakdownID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Factory breakdown not found!";
                        return(false);
                    }
                    else
                    {
                        // check data access permission
                        if (dbItem.SampleProductID.HasValue)
                        {
                            if (CheckSamplePermission(userId, dbItem.SampleProductID.Value) <= 0)
                            {
                                throw new Exception("Data access not authorized!");
                            }
                        }
                        else
                        {
                            throw new Exception("Invalid sample product data! (id null)");
                        }

                        dbItem.IsConfirmed   = false;
                        dbItem.ConfirmedBy   = null;
                        dbItem.ConfirmedDate = null;
                        context.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
Пример #5
0
        //
        // CUSTOM FUNCTION HERE
        //

        public DTO.EditFormData GetData(int userId, int id, int?sampleProductID, int?modelID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.EditFormData data = new DTO.EditFormData();
            data.Data = new DTO.FactoryBreakdownDTO();
            data.Data.FactoryBreakdownDetailDTOs = new List <DTO.FactoryBreakdownDetailDTO>();

            //try to get data
            try
            {
                using (FactoryBreakdownMngEntities context = CreateContext())
                {
                    if (id > 0)
                    {
                        data.Data = converter.DB2DTO_FactoryBreakdownDTO(context.FactoryBreakdownMng_FactoryBreakdown_View
                                                                         .Include("FactoryBreakdownMng_FactoryBreakdownDetail_View")
                                                                         .FirstOrDefault(o => o.FactoryBreakdownID == id));
                    }
                    else
                    {
                        if (sampleProductID.HasValue)
                        {
                            // Auto create new Factory Breakdown.
                            context.FactoryBreakdownMng_function_AddNewSampleProduct();

                            // Load Factory Breakdown with SampleProductID.
                            data.Data = converter.DB2DTO_FactoryBreakdownDTO(context.FactoryBreakdownMng_FactoryBreakdown_View
                                                                             .Include("FactoryBreakdownMng_FactoryBreakdownDetail_View")
                                                                             .FirstOrDefault(o => o.SampleProductID == sampleProductID));
                        }
                        else
                        {
                            throw new Exception("Invalid data flow, data should be auto generated! (not <= 0)");
                        }
                    }
                    if (sampleProductID > 0)
                    {
                        // check data access permission
                        if (data.Data.SampleProductID.HasValue)
                        {
                            if (CheckSamplePermission(userId, data.Data.SampleProductID.Value) <= 0)
                            {
                                throw new Exception("Data access not authorized!");
                            }
                        }
                        else
                        {
                            throw new Exception("Invalid sample product data! (id null)");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
Пример #6
0
        public override DTO.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.SearchFormData data = new DTO.SearchFormData();
            data.Data = new List <DTO.FactoryBreakdownSearchResultDTO>();
            totalRows = 0;

            string ClientUD           = null;
            string SampleOrderUD      = null;
            string SampleProductUD    = null;
            string ArticleDescription = null;
            int    UserID             = 0;
            bool?  IsConfirmed        = null;
            string ModelUD            = null;
            string ModelNM            = null;
            string Season             = null;
            int    FactoryID          = 0;

            if (filters.ContainsKey("ClientUD") && !string.IsNullOrEmpty(filters["ClientUD"].ToString()))
            {
                ClientUD = filters["ClientUD"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("SampleOrderUD") && !string.IsNullOrEmpty(filters["SampleOrderUD"].ToString()))
            {
                SampleOrderUD = filters["SampleOrderUD"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("ArticleDescription") && !string.IsNullOrEmpty(filters["ArticleDescription"].ToString()))
            {
                ArticleDescription = filters["ArticleDescription"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("UserID") && filters["UserID"] != null && !string.IsNullOrEmpty(filters["UserID"].ToString()))
            {
                UserID = Convert.ToInt32(filters["UserID"].ToString());
            }
            if (filters.ContainsKey("IsConfirmed") && filters["IsConfirmed"] != null && !string.IsNullOrEmpty(filters["IsConfirmed"].ToString()))
            {
                IsConfirmed = Convert.ToBoolean(filters["IsConfirmed"].ToString());
            }
            if (filters.ContainsKey("SampleProductUD") && !string.IsNullOrEmpty(filters["SampleProductUD"].ToString()))
            {
                SampleProductUD = filters["SampleProductUD"].ToString().Replace("'", "''");
                ModelUD         = SampleProductUD;
            }
            if (filters.ContainsKey("ModelNM") && !string.IsNullOrEmpty(filters["ModelNM"].ToString()))
            {
                ModelNM = filters["ModelNM"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("Season") && filters["Season"] != null && !string.IsNullOrEmpty(filters["Season"].ToString()))
            {
                Season = filters["Season"].ToString().Replace("'", "''");
            }
            if (filters.ContainsKey("FactoryID") && filters["FactoryID"] != null && !string.IsNullOrEmpty(filters["FactoryID"].ToString()))
            {
                FactoryID = Convert.ToInt32(filters["FactoryID"].ToString());
            }
            //try to get data
            try
            {
                using (FactoryBreakdownMngEntities context = CreateContext())
                {
                    var resultSet = context.FactoryBreakdownMng_function_SearchFactoryBreakdown(IsConfirmed, ClientUD, SampleOrderUD, ArticleDescription, ModelUD, ModelNM, Season, UserID, SampleProductUD, FactoryID, orderBy, orderDirection).ToList();
                    totalRows = resultSet.Count();

                    var sampleProduct = context.Breakdown.Where(o => o.SampleProductID != null).Select(o => o.SampleProductID).ToList();

                    var statistic = resultSet.Where(o => o.IsConfirmed != true && !sampleProduct.Contains(o.SampleProductID)).GroupBy(o => o.FactoryID).Select(group => new DTO.FactoryBreakdownStatistic {
                        FactoryID = group.Key, CountFactory = group.Count()
                    }).ToList();
                    data.Statistic = statistic;
                    data.Data      = converter.DB2DTO_FactoryBreakdownSearchResultDTO(resultSet.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
Пример #7
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.FactoryBreakdownDTO dtoBreakdown = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryBreakdownDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                // check data access permission
                if (dtoBreakdown.SampleProductID.HasValue)
                {
                    if (CheckSamplePermission(userId, dtoBreakdown.SampleProductID.Value) <= 0)
                    {
                        throw new Exception("Data access not authorized!");
                    }
                }
                //else
                //{
                //    throw new Exception("Invalid sample product data! (id null)");
                //}

                using (FactoryBreakdownMngEntities context = CreateContext())
                {
                    FactoryBreakdown dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactoryBreakdown();
                        context.FactoryBreakdown.Add(dbItem);
                        dbItem.UpdatedBy   = userId;
                        dbItem.UpdatedDate = DateTime.Now;
                    }
                    else
                    {
                        dbItem = context.FactoryBreakdown.FirstOrDefault(o => o.FactoryBreakdownID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Factory breakdown not found!";
                        return(false);
                    }
                    else
                    {
                        dbItem.UpdatedBy   = userId;
                        dbItem.UpdatedDate = DateTime.Now;
                        converter.DTO2DB_FactoryBreakdown(dtoBreakdown, ref dbItem, userId);

                        context.FactoryBreakdownDetail.Local.Where(o => o.FactoryBreakdown == null).ToList().ForEach(o => context.FactoryBreakdownDetail.Remove(o));
                        context.FactoryBreakdownModel.Local.Where(o => o.FactoryBreakdown == null).ToList().ForEach(o => context.FactoryBreakdownModel.Remove(o));

                        context.SaveChanges();
                        dtoItem = GetData(userId, dbItem.FactoryBreakdownID, dbItem.SampleProductID, dbItem.ModelID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }