Пример #1
0
        public virtual void ActionInvalidate(int objectID)
        {
            VinaDbUtil dbUtil     = new VinaDbUtil();
            string     tableName  = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject);
            string     primaryKey = dbUtil.GetTablePrimaryColumn(tableName);

            if (Toolbar.ObjectCollection != null)
            {
                for (int i = 0; i < Toolbar.ObjectCollection.Tables[0].Rows.Count; i++)
                {
                    if (objectID == Convert.ToInt32(Toolbar.ObjectCollection.Tables[0].Rows[i][primaryKey]))
                    {
                        Toolbar.CurrentIndex = i;
                        //FocusRowOfGridSearchResultByToolbarCurrentIndex();
                        return;
                    }
                }
            }

            //If can't find the object in toolbar's collection
            BaseBusinessController controller = BusinessControllerFactory.GetBusinessController(tableName + "Controller");

            if (controller != null)
            {
                DataSet ds = controller.GetDataSetByID(objectID);
                Toolbar.SetToolbar(ds);
                //InvalidateAfterSearch(null, String.Empty);
            }
        }
Пример #2
0
        public virtual void Invalidate(DataTable table)
        {
            this.Clear();
            OriginalList.Clear();
            BaseBusinessController objItemController = BusinessControllerFactory.GetBusinessController(ItemTableName + "Controller");

            //Invalidate lookup edit columns to reflect all changes of lookup table
            //if (GridControl != null)
            //    GridControl.InvalidateLookupEditColumns();

            foreach (DataRow row in table.Rows)
            {
                T objT = (T)objItemController.GetObjectFromDataRow(row);
                this.Add(objT);
                OriginalList.Add((T)objT.Clone());
            }
            if (GridControl != null)
            {
                GridControl.RefreshDataSource();
                if (this.Count > 0)
                {
                    if (CurrentIndex >= 0 && CurrentIndex < Count)
                    {
                        GridViewFocusRow(CurrentIndex);
                    }
                    else
                    {
                        GridViewFocusRow(0);
                    }
                }
            }
        }
Пример #3
0
        protected virtual bool IsValidObjectNo(string objectNo)
        {
            VinaDbUtil             dbUtil = new VinaDbUtil();
            BaseBusinessController objCurrentObjectController = BusinessControllerFactory.GetBusinessController(CurrentModuleEntity.MainObject.GetType().Name.Substring(0, CurrentModuleEntity.MainObject.GetType().Name.Length - 4) + "Controller");
            String mainTable = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject);
            String mainTablePrimaryColumn = dbUtil.GetTablePrimaryColumn(mainTable);
            bool   isValid = true;

            if (!String.IsNullOrEmpty(objectNo))
            {
                if (this.Toolbar.ModuleAction == BaseToolbar.ModuleNew)
                {
                    if (objCurrentObjectController.IsExist(objectNo))
                    {
                        MessageBox.Show("Mã đã tồn tại trong hệ thống vui lòng nhập mã khác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        isValid = false;
                    }
                }
                else if (this.Toolbar.ModuleAction == BaseToolbar.ModuleEdit)
                {
                    BusinessObject objMainObject = (BusinessObject)objCurrentObjectController.GetObjectByNo(objectNo);
                    if (objMainObject != null)
                    {
                        int iMainObjectID = Convert.ToInt32(dbUtil.GetPropertyValue(objMainObject, mainTablePrimaryColumn));
                        if (iMainObjectID != Toolbar.CurrentObjectID)
                        {
                            MessageBox.Show("Mã đã tồn tại trong hệ thống vui lòng nhập mã khác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            isValid = false;
                        }
                    }
                }
            }
            return(isValid);
        }
Пример #4
0
        public virtual void Invalidate(int iObjectID)
        {
            //Invalidate lookup edit columns to reflect all changes of lookup table
            //if (GridControl != null)
            //    GridControl.InvalidateLookupEditColumns();

            VinaDbUtil             dbUtil            = new VinaDbUtil();
            BaseBusinessController objItemController = BusinessControllerFactory.GetBusinessController(ItemTableName + "Controller");
            DataSet ds = new DataSet();

            if (Relation.Equals(cstRelationForeign))
            {
                ds = objItemController.GetAllDataByForeignColumn(ItemTableForeignKey, iObjectID);
            }
            else if (Relation.Equals(cstRelationParent))
            {
                ds = objItemController.GetAllObjectsByObjectParentID(iObjectID);
            }
            else if (Relation.Equals(cstRelationNone))
            {
                ds = objItemController.GetAllObjects();
            }
            DataView view = ds.Tables[0].DefaultView;
            string   ID   = ItemTableName.Substring(0, ItemTableName.Length - 1) + "ID";

            view.Sort = ID + " ASC";
            DataTable sortIDData = view.ToTable();

            ds.Clear();
            ds.Merge(sortIDData);
            Invalidate(ds);
        }
Пример #5
0
 public bool IsValidForeignKeyProperty(String strForeignKeyColumn)
 {
     try
     {
         VinaDbUtil dbUtil = new VinaDbUtil();
         //String strMainObjectTableName = MainObject.GetType().Name.Substring(0, MainObject.GetType().Name.Length - 4);
         String strMainObjectTableName = VinaUtil.GetTableNameFromBusinessObject(MainObject);
         String strPrimaryTable        = ((IBaseModuleERP)Module).GetTreePrimaryTableWhichForeignColumnReferenceTo(strMainObjectTableName, strForeignKeyColumn);
         String strPrimaryColumn       = ((IBaseModuleERP)Module).GetTreePrimaryTableWhichForeignColumnReferenceTo(strMainObjectTableName, strForeignKeyColumn);
         BaseBusinessController objPrimaryTableObjectController = BusinessControllerFactory.GetBusinessController(strPrimaryTable + "Controller");
         int iForeignKeyColumnValue = Convert.ToInt32(dbUtil.GetPropertyValue(MainObject, strForeignKeyColumn));
         if (iForeignKeyColumnValue > 0)
         {
             return(objPrimaryTableObjectController.IsExist(iForeignKeyColumnValue));
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #6
0
        protected virtual DataSet GetSearchData()
        {
            String mainObjectTableName = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject);
            BaseBusinessController objCurrentObjectController = BusinessControllerFactory.GetBusinessController(mainObjectTableName + "Controller");

            return(objCurrentObjectController.GetAllObjects());
        }
Пример #7
0
        public virtual void InvalidateMainObject(int iObjectID)
        {
            Type typMainObjectType = MainObject.GetType();
            BaseBusinessController objMainObjectController = new BaseBusinessController(typMainObjectType);

            MainObject = (BusinessObject)objMainObjectController.GetObjectByID(iObjectID);
            UpdateMainObjectBindingSource();
        }
Пример #8
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);
        }
Пример #9
0
        public static DataSet GetLookupTableData(string lookupTableName)
        {
            BaseBusinessController objBusinessController = BusinessControllerFactory.GetBusinessController(lookupTableName + "Controller");
            DataSet ds = new DataSet();

            if (objBusinessController != null)
            {
                ds = objBusinessController.GetAllObjects();
            }
            return(ds);
        }
Пример #10
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);
        }
Пример #11
0
        public virtual void Invalidate(int iObjectID)
        {
            string strTableName = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject);
            BaseBusinessController objBaseBusinessController = BusinessControllerFactory.GetBusinessController(strTableName + "Controller");
            BusinessObject         mainObject = (BusinessObject)objBaseBusinessController.GetObjectByID(iObjectID);

            if (mainObject != null)
            {
                CurrentModuleEntity.Invalidate(iObjectID);

                CurrentModuleEntity.MainObject.OldObject = (BusinessObject)CurrentModuleEntity.MainObject.Clone();

                InvalidateToolbar();
            }
            InvalidateEmployee();
        }
Пример #12
0
 public virtual BusinessObject GetBusinessObject(int pRowHandle, BaseBusinessController objCtrl)
 {
     if (pRowHandle < 0)
     {
         return(null);
     }
     if (string.IsNullOrWhiteSpace(VinaDataSource))
     {
         if (objCtrl != null)
         {
             return((BusinessObject)objCtrl.GetObjectFromDataRow((MainView as DevExpress.XtraGrid.Views.Grid.GridView).GetDataRow(pRowHandle)));
         }
         return(null);
     }
     return((BusinessObject)(MainView as DevExpress.XtraGrid.Views.Grid.GridView).GetRow(pRowHandle));
 }
Пример #13
0
        public Dictionary <List <STGridColumnsInfo>, DataSet> GetScreenEmployeeOffWork(string sModuleName, int iObjectID)
        {
            DataSet dsScreen = GetScreenByModuleNameAndUserGroupName(sModuleName, "ADMIN");

            if (dsScreen == null || dsScreen.Tables.Count == 0 && dsScreen.Tables[0].Rows.Count == 0)
            {
                return(null);
            }
            STScreensInfo  objScreen = new STScreensController().GetObjectFromDataRow(dsScreen.Tables[0].Rows[0]) as STScreensInfo;
            List <DataRow> dr        = GetLocalDataSet("*", "STFields", string.Format(@"STScreenID = {0} AND STFieldType = 'GMCGridControl' 
                                    AND STFieldGroup <> 'HiddenWeb'", objScreen.STScreenID));

            if (dr.Count == 0)
            {
                return(null);
            }
            STFieldsInfo objField = (STFieldsInfo) new STFieldsController().GetObjectFromDataRow(dr[0]);

            if (objField == null)
            {
                return(null);
            }
            BaseBusinessController itemCtrl = BusinessControllerFactory.GetBusinessController(objField.STFieldDataSource + "Controller");
            DataSet ds = new DataSet();

            if (itemCtrl != null)
            {
                ds = itemCtrl.GetDataSetByID(iObjectID);
            }

            List <STGridColumnsInfo> lstGridColumns = new List <STGridColumnsInfo>();

            dr = GetLocalDataSet("*", "STGridColumns", string.Format("FK_STFieldID = {0}", objField.STFieldID));
            STGridColumnsController GridColCtrl = new STGridColumnsController();

            dr.Distinct().ToList().ForEach(x =>
            {
                STGridColumnsInfo colInfo = (STGridColumnsInfo)GridColCtrl.GetObjectFromDataRow(x);
                lstGridColumns.Add(colInfo);
            });
            return(new Dictionary <List <STGridColumnsInfo>, DataSet>()
            {
                { lstGridColumns, ds }
            });
        }
Пример #14
0
        public virtual String GetMainObjectNo(ref int numberingStart)
        {
            String strMainObjectNo = String.Empty;
            GENumberingsController objGENumberingController = new GENumberingsController();
            GENumberingsInfo       objGENumberingInfo       = (GENumberingsInfo)objGENumberingController.GetObjectByName(Module.CurrentModuleName);

            if (objGENumberingInfo != null)
            {
                String mainTableName = VinaUtil.GetTableNameFromBusinessObject(MainObject);
                BaseBusinessController objMainObjectController = BusinessControllerFactory.GetBusinessController(mainTableName + "Controller");
                if (objMainObjectController != null)
                {
                    VinaDbUtil    dbUtil              = new VinaDbUtil();
                    string        strPrefixHaveYear   = DateTime.Now.Year.ToString().Substring(2, 2);
                    List <string> subMainObjectNoList = new List <string>();
                    subMainObjectNoList.Add(objGENumberingInfo.GENumberingPrefix);
                    if (objGENumberingInfo.GENumberingPrefixHaveYear)
                    {
                        subMainObjectNoList.Add(strPrefixHaveYear);
                    }
                    subMainObjectNoList.Add(objGENumberingInfo.GENumberingNumber.ToString().PadLeft(objGENumberingInfo.GENumberingLength, '0'));

                    strMainObjectNo = string.Join(".", subMainObjectNoList.ToArray());

                    numberingStart = objGENumberingInfo.GENumberingNumber;
                    while (objMainObjectController.IsExist(strMainObjectNo))
                    {
                        objGENumberingInfo.GENumberingNumber++;

                        subMainObjectNoList.Clear();
                        subMainObjectNoList.Add(objGENumberingInfo.GENumberingPrefix);
                        if (objGENumberingInfo.GENumberingPrefixHaveYear)
                        {
                            subMainObjectNoList.Add(strPrefixHaveYear);
                        }
                        subMainObjectNoList.Add(objGENumberingInfo.GENumberingNumber.ToString().PadLeft(objGENumberingInfo.GENumberingLength, '0'));

                        strMainObjectNo = string.Join(".", subMainObjectNoList.ToArray());
                        numberingStart  = objGENumberingInfo.GENumberingNumber;
                    }
                }
            }
            return(strMainObjectNo);
        }
Пример #15
0
        public virtual void Search()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                String strMainObjectControllerName = VinaUtil.GetBusinessControllerNameFromBusinessObject(CurrentModuleEntity.MainObject);
                String strMainObjectTableName      = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject);
                BaseBusinessController objCurrentObjectController = BusinessControllerFactory.GetBusinessController(strMainObjectControllerName);
                Cursor.Current = Cursors.WaitCursor;

                string  searchQuery = string.Empty;
                DataSet ds          = GetSearchData();
                Toolbar.SetToolbar(ds);
                InvalidateAfterSearch(null, String.Empty);
                Cursor.Current = Cursors.Default;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return;
            }
        }
Пример #16
0
        public virtual void InvalidateSearchResultsControl(object sender, String strEventName)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                VinaDbUtil             dbUtil                  = new VinaDbUtil();
                String                 strMainTableName        = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject);
                string                 mainTablePrimaryColumn  = dbUtil.GetTablePrimaryColumn(strMainTableName);
                BaseBusinessController objMainObjectController = BusinessControllerFactory.GetBusinessController(strMainTableName + "Controller");

                //Invalidate toolbar collection
                PropertyInfo[] properties;
                DataRow        newRow;
                String         strMainObjectTableName = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject);
                int            iObjectID = Convert.ToInt32(dbUtil.GetPropertyValue(CurrentModuleEntity.MainObject, SqlDatabaseHelper.GetPrimaryKeyColumn(strMainObjectTableName)));

                if (Toolbar.ObjectCollection == null)
                {
                    DataSet ds = objMainObjectController.GetDataSetByID(iObjectID);
                    Toolbar.SetToolbar(ds);
                }
                else
                {
                    //if Toolbar.ModusAction is new, add new object to object collection of toolbar
                    if (Toolbar.ModuleAction == BaseToolbar.ModuleNew)
                    {
                        newRow = Toolbar.ObjectCollection.Tables[0].NewRow();
                        newRow = objMainObjectController.GetDataRowFromBusinessObject(newRow, CurrentModuleEntity.MainObject);
                        Toolbar.ObjectCollection.Tables[0].Rows.Add(newRow);
                        Toolbar.CurrentIndex = Toolbar.ObjectCollection.Tables[0].Rows.Count - 1;
                    }
                    else
                    {
                        //Update object in object collection of toolbar
                        properties = CurrentModuleEntity.MainObject.GetType().GetProperties();
                        int iCurrIndex = Toolbar.CurrentIndex;
                        for (int i = 0; i < properties.Length; i++)
                        {
                            if (Toolbar.ObjectCollection.Tables[0].Columns[properties[i].Name] != null)
                            {
                                Toolbar.ObjectCollection.Tables[0].Rows[iCurrIndex][properties[i].Name] = properties[i].GetValue(CurrentModuleEntity.MainObject, null);
                            }
                        }
                    }
                }


                //Invalidate search result control
                Control searchResultControl = null;
                foreach (Control ctrl in Controls.Values)
                {
                    if (ctrl.Tag == VinaScreen.SearchResultControl)
                    {
                        searchResultControl = ctrl;
                        break;
                    }
                }

                if (searchResultControl != null)
                {
                    if (searchResultControl is GridControl)
                    {
                        VinaSearchResultsGridControl gridControl = searchResultControl as VinaSearchResultsGridControl;
                        GridView gridView = gridControl.Views[0] as GridView;
                        if (gridControl.DataSource == null)
                        {
                            VinaSearchResultsGridControl.BindingSearchResultGridControl(gridControl, Toolbar.ObjectCollection);
                        }
                        //gridControl.InvalidateLookupEditColumns();
                        gridView.RefreshData();
                        gridView.FocusedRowHandle = gridView.GetRowHandle(Toolbar.CurrentIndex);
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Пример #17
0
        public Dictionary <List <STGridColumnsInfo>, DataSet> ShowModuleByJournal(String strSourceLeger, String strDocumentNo, ADInboxItemsInfo objInbox, STFieldsInfo objOldField)
        {
            STModulesController      ModuleCtrl      = new STModulesController();
            STModuleTablesController ModuleTableCtrl = new STModuleTablesController();

            int    iMainObjectID  = -1;
            String strTable       = String.Empty;
            String strTablePrefix = String.Empty;
            String strPrimaryKey  = String.Empty;
            Object MainObj        = null;

            int            iModuleID = 0;
            List <DataRow> dr        = GetLocalDataSet("STModuleID,STModuleName", "STModules", string.Format("STModuleName = '{0}'", strSourceLeger));

            if (dr.Count > 0)
            {
                iModuleID = Convert.ToInt32(dr.First()["STModuleID"]);
            }

            dr = GetLocalDataSet("STModuleTableID,STModuleTableName,STModuleID,STModuleTableLevelIndex", "STModuleTables", string.Format("STModuleID = {0} AND STModuleTableLevelIndex = 0", iModuleID));
            if (dr.Count > 0)
            {
                strTable = dr.First()["STModuleTableName"].ToString();
            }

            if (String.IsNullOrEmpty(strTable) == false)
            {
                strTablePrefix = strTable.Substring(0, strTable.Length - 1);
                strPrimaryKey  = strTablePrefix + "ID";
            }

            BaseBusinessController Ctrl = BusinessControllerFactory.GetBusinessController(strTable + "Controller");

            if (Ctrl != null)
            {
                MainObj = Ctrl.GetObjectByNo(strDocumentNo);
            }

            if (MainObj != null)
            {
                iMainObjectID = Convert.ToInt32(GMCDbUtil.GetPropertyValue(MainObj, strPrimaryKey));
                if (GMCDbUtil.GetPropertyValue(MainObj, "FK_HREmployeeID") != null)
                {
                    int iEmployeeID = Convert.ToInt32(GMCDbUtil.GetPropertyValue(MainObj, "FK_HREmployeeID"));
                    objInbox.FK_HRFromEmployeeID = iEmployeeID;
                }
                if (GMCDbUtil.GetPropertyValue(MainObj, strTable.TrimEnd('s') + "Desc") != null)
                {
                    //TextEdit txtRemark = (TextEdit)GetControlByName("fld_medADInboxItemRemark1");
                    //if (txtRemark != null)
                    //{
                    //    txtRemark.EditValue = GMCDbUtil.GetPropertyValue(MainObj, strTable.TrimEnd('s') + "Desc");
                    //}
                    objInbox.ADInboxItemMessage = Convert.ToString(GMCDbUtil.GetPropertyValue(MainObj, strTable.TrimEnd('s') + "Desc"));
                }
            }
            //ShowModuleByJournal(strSourceLeger, iMainObjectID, false);
            //Thang - edit 26/4/2016 hiển thị chi tiêt chứng từ

            ADUserGroupsInfo objUserGroup = AuthConfig.CurrenUserGroupInfo;

            dr = GetLocalDataSet("STScreenID,STScreenNumber,STModuleID,STUserGroupID,STScreenSortOrder", "STScreens", string.Format(@"STModuleID = {0} AND STUserGroupID = {1} 
                AND STScreenNumber like 'DM%' AND STScreenSortOrder > 0 AND STScreenSortOrder <= 1", iModuleID, objUserGroup.ADUserGroupID));
            int iScreenID = 0;

            if (dr.Count > 0)
            {
                iScreenID = Convert.ToInt32(dr.First()["STScreenID"]);
            }
            //Thang edit - 8/2/2017 Chỉnh sửa nếu 1 user group không có giao diện riêng thì sẽ lấy mặc định giao diện admin
            if (iScreenID == 0)
            {
                int iUserGroupDefaultID = new ADUserGroupsController().GetObjectIDByName("ADMIN");
                dr = GetLocalDataSet("STScreenID,STScreenNumber,STModuleID,STUserGroupID,STScreenSortOrder", "STScreens", string.Format(@"STModuleID = {0} AND STUserGroupID = {1} 
                AND STScreenNumber like 'DM%' AND STScreenSortOrder > 0 AND STScreenSortOrder <= 1", iModuleID, iUserGroupDefaultID));
                if (dr.Count > 0)
                {
                    iScreenID = Convert.ToInt32(dr.First()["STScreenID"]);
                }
            }

            dr = GetLocalDataSet("*", "STFields", string.Format(@"STScreenID = {0} AND STFieldType = 'GMCGridControl' 
                                        AND(STFieldDataSource like '%Items' OR STFieldDataSource like '%Details')
                                        AND STFieldGroup <> ''", iScreenID));
            if (dr.Count == 0)
            {
                return(null);
            }
            STFieldsInfo objField = (STFieldsInfo) new STFieldsController().GetObjectFromDataRow(dr[0]);

            if (objField == null)
            {
                return(null);
            }

            BaseBusinessController itemCtrl = BusinessControllerFactory.GetBusinessController(objField.STFieldDataSource + "Controller");
            DataSet ds = new DataSet();

            if (itemCtrl != null)
            {
                ds = itemCtrl.GetAllDataByForeignColumn("FK_" + strPrimaryKey, iMainObjectID);
            }

            List <STGridColumnsInfo> lstGridColumns = new List <STGridColumnsInfo>();

            if (objOldField == null || !objOldField.STFieldID.Equals(objField.STFieldID))
            {
                objOldField = objField;
                dr          = GetLocalDataSet("*", "STGridColumns", string.Format("FK_STFieldID = {0}", objField.STFieldID));
                STGridColumnsController GridColCtrl = new STGridColumnsController();
                dr.Distinct().ToList().ForEach(x =>
                {
                    STGridColumnsInfo colInfo = (STGridColumnsInfo)GridColCtrl.GetObjectFromDataRow(x);
                    lstGridColumns.Add(colInfo);
                });
            }
            return(new Dictionary <List <STGridColumnsInfo>, DataSet>()
            {
                { lstGridColumns, ds }
            });
        }
Пример #18
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);
            }
        }