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
     };
     Module.Support.DAL.DataFactory support_factory = new Support.DAL.DataFactory();
     try
     {
         using (FactoryNormEntities context = CreateContext())
         {
             if (id > 0)
             {
                 FactoryNormMng_FactoryNorm_View dbItem;
                 dbItem            = context.FactoryNormMng_FactoryNorm_View.FirstOrDefault(o => o.FactoryNormID == id);
                 editFormData.Data = converter.DB2DTO_FactoryNorm(dbItem);
             }
             else
             {
                 editFormData.Data = new DTO.FactoryNorm();
                 editFormData.Data.FactoryFinishedProductNorms = new List <DTO.FactoryFinishedProductNorm>();
                 foreach (var item in editFormData.Data.FactoryFinishedProductNorms)
                 {
                     item.FactoryMaterialNorms = new List <DTO.FactoryMaterialNorm>();
                 }
             }
             //get support list
             //editFormData.Units = support_factory.GetUnit(1);
             editFormData.FactoryGoodsProcedures = support_factory.GetFactoryGoodsProcedure();
             editFormData.MaterialGroupTypes     = support_factory.GetMaterialGroupType();
             return(editFormData);
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         notification.DetailMessage.Add(ex.Message);
         if (ex.GetBaseException() != null)
         {
             notification.DetailMessage.Add(ex.GetBaseException().Message);
         }
         return(editFormData);
     }
 }
Exemple #2
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
            };
            Module.Support.DAL.DataFactory support_factory = new Support.DAL.DataFactory();
            try
            {
                using (FactoryOrderNormEntities context = CreateContext())
                {
                    FactoryOrderNormMng_FactoryOrderNorm_View dbItem;
                    dbItem            = context.FactoryOrderNormMng_FactoryOrderNorm_View.FirstOrDefault(o => o.FactoryOrderNormID == id);
                    editFormData.Data = converter.DB2DTO_FactoryOrderNorm(dbItem);

                    //support data
                    //editFormData.Units = support_factory.GetUnit(1);
                    editFormData.Seasons = support_factory.GetSeason();
                    editFormData.FactoryGoodsProcedures = support_factory.GetFactoryGoodsProcedure();
                    editFormData.MaterialGroupTypes     = support_factory.GetMaterialGroupType();
                    return(editFormData);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(editFormData);
            }
        }
        public DTO.EditFormData GetEditFormData(int id, int?clientID, int?productID, out Library.DTO.Notification notification)
        {
            DTO.EditFormData editFormData = new DTO.EditFormData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            Module.Support.DAL.DataFactory support_factory = new Support.DAL.DataFactory();
            try
            {
                using (FactoryMaterialOrderNormEntities context = CreateContext())
                {
                    if (id > 0)
                    {
                        FactoryMaterialOrderNormMng_FactoryMaterialOrderNorm_View dbItem;
                        dbItem            = context.FactoryMaterialOrderNormMng_FactoryMaterialOrderNorm_View.FirstOrDefault(o => o.FactoryMaterialOrderNormID == id);
                        editFormData.Data = converter.DB2DTO_FactoryMaterialOrderNorm(dbItem);
                    }
                    else
                    {
                        //get info client and product
                        var client        = context.FactoryMaterialOrderNormMng_Client_View.Where(o => o.ClientID == clientID).FirstOrDefault();
                        var clientProduct = context.FactoryMaterialOrderNormMng_ClientProduct_View.Where(o => o.ClientID == clientID && o.ProductID == productID).FirstOrDefault();
                        var defaultNorm   = context.FactoryMaterialOrderNormMng_DefaultNorm_View.Where(o => o.ProductID == productID).ToList();

                        //init edit form info
                        editFormData.Data             = new DTO.FactoryMaterialOrderNorm();
                        editFormData.Data.Season      = Library.Helper.GetCurrentSeason();
                        editFormData.Data.ClientID    = clientID;
                        editFormData.Data.ProductID   = productID;
                        editFormData.Data.ClientUD    = client.ClientUD;
                        editFormData.Data.ArticleCode = clientProduct.ArticleCode;
                        editFormData.Data.Description = clientProduct.Description;

                        //init default material norm
                        editFormData.Data.FactoryMaterialOrderNormDetails = new List <DTO.FactoryMaterialOrderNormDetail>();
                        DTO.FactoryMaterialOrderNormDetail orderMaterialNorm;

                        int i = -1;
                        foreach (var item in defaultNorm)
                        {
                            orderMaterialNorm = new DTO.FactoryMaterialOrderNormDetail();
                            orderMaterialNorm.FactoryMaterialOrderNormDetailID = i;
                            orderMaterialNorm.FactoryMaterialID       = item.FactoryMaterialID;
                            orderMaterialNorm.UnitID                  = item.UnitID;
                            orderMaterialNorm.NormValue               = item.NormValue;
                            orderMaterialNorm.FactoryGoodsProcedureID = item.FactoryGoodsProcedureID;
                            orderMaterialNorm.FactoryMaterialUD       = item.FactoryMaterialUD;
                            orderMaterialNorm.FactoryMaterialNM       = item.FactoryMaterialNM;
                            editFormData.Data.FactoryMaterialOrderNormDetails.Add(orderMaterialNorm);

                            i--;
                        }
                    }
                    //get support list
                    editFormData.Units   = support_factory.GetUnit(1);
                    editFormData.Seasons = support_factory.GetSeason();
                    editFormData.FactoryGoodsProcedures = support_factory.GetFactoryGoodsProcedure();
                    return(editFormData);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(editFormData);
            }
        }