Exemple #1
0
        public virtual int UpdateMainObject()
        {
            int    iObjectID = 0;
            String strMainObjectTableName = VinaUtil.GetTableNameFromBusinessObject(MainObject);
            BaseBusinessController objMainObjectController = BusinessControllerFactory.GetBusinessController(strMainObjectTableName + "Controller");

            VinaDbUtil dbUtil = new VinaDbUtil();

            dbUtil.SetPropertyValue(MainObject, AAUpdatedUser, VinaApp.CurrentUserName);
            dbUtil.SetPropertyValue(MainObject, AAUpdatedDate, DateTime.Now);

            iObjectID = objMainObjectController.UpdateObject(MainObject);
            return(iObjectID);
        }
Exemple #2
0
        public virtual void SaveItemObjects()
        {
            try
            {
                EndCurrentEdit();

                VinaDbUtil             dbUtil = new VinaDbUtil();
                String                 strItemTablePrimaryKey = dbUtil.GetTablePrimaryColumn(ItemTableName);
                BaseBusinessController objItemsController     = BusinessControllerFactory.GetBusinessController(ItemTableName + "Controller");
                int iParentObjectID = GetParentObjectID();

                //Create or update
                foreach (T objT in this)
                {
                    int iItemObjectID = (int)dbUtil.GetPropertyValue(objT, strItemTablePrimaryKey);

                    if (iItemObjectID == 0 && Relation == cstRelationForeign)
                    {
                        if (iParentObjectID > 0)
                        {
                            if (dbUtil.GetPropertyValue(objT, ItemTableForeignKey) != null)
                            {
                                dbUtil.SetPropertyValue(objT, ItemTableForeignKey, iParentObjectID);
                            }
                        }
                    }

                    bool isUpdate = iItemObjectID > 0;
                    if (isUpdate)
                    {
                        dbUtil.SetPropertyValue(objT, ERPModuleEntities.AAUpdatedUser, VinaApp.CurrentUserName);
                        dbUtil.SetPropertyValue(objT, ERPModuleEntities.AAUpdatedDate, DateTime.Now);
                        objItemsController.UpdateObject(objT);
                    }
                    else
                    {
                        dbUtil.SetPropertyValue(objT, ERPModuleEntities.AACreatedUser, VinaApp.CurrentUserName);
                        dbUtil.SetPropertyValue(objT, ERPModuleEntities.AACreatedDate, DateTime.Now);
                        iItemObjectID = objItemsController.CreateObject(objT);
                    }
                }

                //Delete items
                foreach (T obj in OriginalList)
                {
                    int iItemObjectID = (int)dbUtil.GetPropertyValue(obj, strItemTablePrimaryKey);
                    if (iItemObjectID > 0 && !this.Exists(strItemTablePrimaryKey, iItemObjectID))
                    {
                        objItemsController.DeleteObject(iItemObjectID);
                        //Entity.DeleteObjectRelations(ItemTableName, iItemObjectID);
                    }
                }
                //Invalidate original list
                OriginalList.Clear();
                foreach (T obj in this)
                {
                    OriginalList.Add((T)obj.Clone());
                }
            }
            catch (Exception e)
            {
                // MessageBox.Show(e.ToString(), CommonLocalizedResources.MessageBoxDefaultCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }