Exemplo n.º 1
0
        public void SaveComponentMaterialAndExtension(Sender sender, SaveComponentMaterialArgs args)
        {
            try
            {
                using (ObjectProxy op = new ObjectProxy(true))
                {
                    if (args.ComponentMaterials != null)
                    {
                        foreach (ComponentMaterial Item in args.ComponentMaterials)
                        {
                            if (op.LoadComponentMaterial(Item) == 0)
                            {
                                Item.Created    = DateTime.Now;
                                Item.CreatedBy  = sender.UserCode + "." + sender.UserName;
                                Item.Modified   = DateTime.Now;
                                Item.ModifiedBy = sender.UserCode + "." + sender.UserName;
                                int componentMaterialID = op.AddComponentMaterial(Item);

                                Item.ExtensionModel.ComponentMaterialID = componentMaterialID;
                                Item.ExtensionModel.Created             = DateTime.Now;
                                Item.ExtensionModel.CreatedBy           = sender.UserCode + "." + sender.UserName;
                                op.InsertComponentMaterialExtension(Item.ExtensionModel);
                            }
                            else
                            {
                                Item.Modified   = DateTime.Now;
                                Item.ModifiedBy = sender.UserCode + "." + sender.UserName;
                                op.UpdateComponentMaterialByID(Item);
                            }
                        }
                    }

                    op.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                throw ex;
            }
        }