Exemple #1
0
        public virtual int CreateMainObject()
        {
            VinaDbUtil dbUtil       = new VinaDbUtil();
            int        iObjectID    = 0;
            bool       editObjectNo = true;

            //Get Table which Business object Represent
            String strMainObjectTableName = VinaUtil.GetTableNameFromBusinessObject(MainObject);
            BaseBusinessController objMainObjectController = BusinessControllerFactory.GetBusinessController(strMainObjectTableName + "Controller");

            //Set Object No value
            String strPrimaryColumn = strMainObjectTableName.Substring(0, strMainObjectTableName.Length - 1) + "ID";
            String strColumnNo      = strMainObjectTableName.Substring(0, strMainObjectTableName.Length - 1) + "No";
            String strMainObjectNo  = dbUtil.GetPropertyStringValue(MainObject, strColumnNo);
            int    numberingStart   = 0;

            try
            {
                if (strMainObjectNo.Equals(NewObjectNoText))
                {
                    editObjectNo    = false;
                    strMainObjectNo = GetMainObjectNo(ref numberingStart);
                    dbUtil.SetPropertyValue(MainObject, strColumnNo, strMainObjectNo);
                }

                //Set Created User, Created Date
                dbUtil.SetPropertyValue(MainObject, AACreatedUser, VinaApp.CurrentUserName);
                dbUtil.SetPropertyValue(MainObject, AACreatedDate, DateTime.Now);


                iObjectID = dbUtil.GetPropertyIntValue(MainObject, strPrimaryColumn);
                if (iObjectID == 0)
                {
                    iObjectID = objMainObjectController.CreateObject(MainObject);
                }
                else
                {
                    objMainObjectController.CreateObject(MainObject, iObjectID);
                }
            }
            catch (Exception ex)
            {
                if (!editObjectNo)
                {
                    dbUtil.SetPropertyValue(MainObject, strColumnNo, NewObjectNoText);
                    dbUtil.SetPropertyValue(MainObject, strPrimaryColumn, 0);
                }

                iObjectID = 0;
                MessageBox.Show(ex.Message.ToString());
            }

            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);
            }
        }