Exemplo n.º 1
0
        public DbCommand GetQuery(String strQueryCommand)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(strQueryCommand))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }
            try
            {
                return(db.GetSqlStringCommand(strQueryCommand));
            }
            catch (Exception ex)
            {
                ABCHelper.ABCMessageBox.Show("Have some mistakes with Database connection.");
            }
            return(null);
        }
Exemplo n.º 2
0
        // not caching Command
        public DataSet RunQuery(String strQueryCommand)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(strQueryCommand))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            if (DataQueryProvider.IsSQLConnection(db) == false)
            {
                strQueryCommand = SQLiteDatabaseHelper.RepairSelectSQLite(strQueryCommand);
                strQueryCommand = strQueryCommand.Replace("N'", "'");
            }
            DbCommand cmd = GetQuery(strQueryCommand);

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

            return(RunCommand(cmd));
        }
Exemplo n.º 3
0
        public DbCommand GetScriptCommand(String strScriptQuery)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(strScriptQuery))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            DbCommand cmd = null;

            if (ScriptCommandList.TryGetValue(strScriptQuery, out cmd))
            {
                return(cmd);
            }

            cmd             = db.GetSqlStringCommand(strScriptQuery);
            cmd.CommandType = CommandType.Text;

            ScriptCommandList.Add(strScriptQuery, cmd);
            return(cmd);
        }
Exemplo n.º 4
0
        public static AccrossStructInfo GetAccrossStructInfo(String strTableName, String strFieldString)
        {
            AccrossStructInfo result = new AccrossStructInfo();

            result.FieldName = strFieldString;
            result.TableName = strTableName;

            String[] strArr = strFieldString.Split(':');
            if (strArr.Length <= 1)
            {
                return(result);
            }

            result.FieldName = strArr[0];
            result.TableName = strTableName;

            for (int i = 1; i < strArr.Length; i++)
            {
                if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName) == false)
                {
                    break;
                }

                result.TableName = DataStructureProvider.GetTableNameOfForeignKey(result.TableName, result.FieldName);
                result.FieldName = strArr[i];
            }

            if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName))
            {
                result.TableName = DataStructureProvider.GetTableNameOfForeignKey(result.TableName, result.FieldName);
                result.FieldName = DataStructureProvider.GetDisplayColumn(result.TableName);
            }

            return(result);
        }
Exemplo n.º 5
0
        public virtual bool ReCalculate(BusinessObject obj, Dictionary <String, IEnumerable <BusinessObject> > lstObjecItems, bool isCalcMainOnly, String strAfterValidateFieldName, bool isSave)
        {
            if (obj == null || obj.GetID() == Guid.Empty)
            {
                return(false);
            }

            if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colLockStatus))
            {
                if (ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colLockStatus).ToString() == ABCCommon.ABCConstString.LockStatusLocked)
                {
                    return(false);
                }
            }

            if (!BeforeReCalculate(obj, lstObjecItems, isCalcMainOnly, strAfterValidateFieldName))
            {
                return(false);
            }

            if (!DoReCalculate(obj, lstObjecItems, isCalcMainOnly, strAfterValidateFieldName, isSave))
            {
                return(false);
            }

            AfterReCalculate(obj, lstObjecItems, isCalcMainOnly, strAfterValidateFieldName);
            return(true);
        }
Exemplo n.º 6
0
        public virtual bool ReCalculate(BusinessObject obj, bool isSave)
        {
            if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colLockStatus))
            {
                if (ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colLockStatus).ToString() == ABCCommon.ABCConstString.LockStatusLocked)
                {
                    return(false);
                }
            }

            if (obj.GetID() != Guid.Empty)
            {
                Dictionary <String, IEnumerable <BusinessObject> > lstObjecItems = new Dictionary <string, IEnumerable <BusinessObject> >();
                foreach (GEVoucherItemsInfo configItem in ConfigItems)
                {
                    if (!DataStructureProvider.IsForeignKey(configItem.ItemTableName, configItem.ItemFKField))
                    {
                        continue;
                    }

                    BusinessObjectController itemCtrl = BusinessControllerFactory.GetBusinessController(configItem.ItemTableName);

                    if (!lstObjecItems.ContainsKey(configItem.ItemTableName))
                    {
                        lstObjecItems.Add(configItem.ItemTableName, (IEnumerable <BusinessObject>)itemCtrl.GetListByForeignKey(configItem.ItemFKField, obj.GetID()));
                    }
                }

                return(ReCalculate(obj, lstObjecItems, false, String.Empty, isSave));
            }

            return(ReCalculate(obj, null, false, String.Empty, isSave));
        }
Exemplo n.º 7
0
        public DbCommand GetSPCommand(String strSPName)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(strSPName))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            DbCommand cmd = null;

            if (SPCommandList.TryGetValue(strSPName, out cmd))
            {
                return(cmd);
            }

            cmd = db.GetStoredProcCommand(strSPName);
            SPCommandList.Add(strSPName, cmd);
            return(cmd);
        }
Exemplo n.º 8
0
        public DataSet RunCommand(DbCommand cmd)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(cmd.CommandText))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            try
            {
                return(db.ExecuteDataSet(cmd));
            }
            catch (System.Exception ex)
            {
                if (ex is System.Data.SqlClient.SqlException)
                {
                    if (((System.Data.SqlClient.SqlException)ex).ErrorCode == -2146232060 && ex.Message.Contains("TCP Provider"))
                    {
                        ShowDisconnectWaitingDialog();
                        return(null);
                    }
                }
                //ABCHelper.ABCMessageBox.Show( ex.Message , "Message" , MessageBoxButtons.OK , MessageBoxIcon.Stop );
                return(null);
            }
        }
Exemplo n.º 9
0
 public static GECompanyUnitsInfo GetCompanyUnit(String strRealTableName, Guid realCompanyUnitID)
 {
     if (DataStructureProvider.IsExistedTable(strRealTableName))
     {
         BusinessObject obj = BusinessControllerFactory.GetBusinessController(strRealTableName).GetObjectByID(realCompanyUnitID);
         return(GetCompanyUnit(obj));
     }
     return(null);
 }
Exemplo n.º 10
0
        public static bool GenerateCurrencyValue(BusinessObject obj)
        {
            bool isModified = false;

            String strFK_GECurrencyID = DataStructureProvider.GetForeignKeyOfTableName(obj.AATableName, "GECurrencys");

            if (!String.IsNullOrWhiteSpace(strFK_GECurrencyID))
            {
                if (AppCurrencyID == Guid.Empty)
                {
                    String strQuery = @"SELECT FK_GECurrencyID FROM GEAppConfigs";
                    AppCurrencyID = ABCHelper.DataConverter.ConvertToGuid(BusinessObjectController.GetData(strQuery));
                }
                ABCDynamicInvoker.SetValue(obj, strFK_GECurrencyID, AppCurrencyID);
                if (AppCurrencyID != Guid.Empty && DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colExchangeRate))
                {
                    object objDate    = DateTime.MinValue;
                    String strDateCol = String.Empty;
                    if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colCreateTime))
                    {
                        strDateCol = ABCCommon.ABCConstString.colCreateTime;
                    }
                    if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colDocumentDate))
                    {
                        strDateCol = ABCCommon.ABCConstString.colDocumentDate;
                    }

                    if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colVoucherDate))
                    {
                        strDateCol = ABCCommon.ABCConstString.colVoucherDate;
                    }

                    if (!String.IsNullOrWhiteSpace(strDateCol))
                    {
                        objDate = ABCDynamicInvoker.GetValue(obj, strDateCol);

                        object objOldValue = ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colExchangeRate);

                        if (objDate != null && objDate is DateTime)
                        {
                            object objNewValue = CurrencyProvider.GetExchangeRate(AppCurrencyID, Convert.ToDateTime(objDate));
                            ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colExchangeRate, objNewValue);
                            isModified = isModified || (objOldValue != objNewValue);
                        }
                        else if (objDate != null && objDate is Nullable <DateTime> )
                        {
                            object objNewValue = CurrencyProvider.GetExchangeRate(AppCurrencyID, (objDate as Nullable <DateTime>).Value);
                            ABCDynamicInvoker.SetValue(obj, ABCCommon.ABCConstString.colExchangeRate, objNewValue);
                            isModified = isModified || (objOldValue != objNewValue);
                        }
                    }
                }
            }

            return(isModified);
        }
Exemplo n.º 11
0
        public static bool IsSQLConnection(String strTableName)
        {
            if ((DataStructureProvider.IsSystemTable(strTableName) && DataQueryProvider.IsSystemSQLConnection) ||
                (DataStructureProvider.IsSystemTable(strTableName) == false && DataQueryProvider.IsCompanySQLConnection))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 12
0
        public static object GetCachingObjectAccrossTable(String strTableName, Guid iFieldValue, String strFieldString, String strIDTableName)
        {
            AccrossStructInfo info = GetAccrossStructInfo(strTableName, iFieldValue, strFieldString, strIDTableName);

            if (info != null && DataStructureProvider.IsTableColumn(info.TableName, info.FieldName))
            {
                BusinessObject objResult = GetCachedBusinessObject(info.TableName, info.TableID);
                return(ABCBusinessEntities.ABCDynamicInvoker.GetValue(objResult, info.FieldName));
            }

            return(null);
        }
Exemplo n.º 13
0
        public object RunStoredProcedure(string strSPName, BusinessObject obj)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(strSPName))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            if (String.IsNullOrWhiteSpace(strSPName))
            {
                return(null);
            }
            try
            {
                DbCommand cmd = GetSPCommand(strSPName);
                AddParameterForObject(obj, cmd);

                db.ExecuteNonQuery(cmd);
                String strIDCol = DataStructureProvider.GetPrimaryKeyColumn(obj.AATableName);
                if (!String.IsNullOrWhiteSpace(strIDCol))
                {
                    Guid ret = ABCHelper.DataConverter.ConvertToGuid(db.GetParameterValue(cmd, strIDCol));
                    return(ret);
                }
                return(null);
            }
            catch (System.Exception ex)
            {
                if (ex is System.Data.SqlClient.SqlException)
                {
                    if (((System.Data.SqlClient.SqlException)ex).ErrorCode == -2146232060 && ex.Message.Contains("TCP Provider"))
                    {
                        ShowDisconnectWaitingDialog();
                        return(0);
                    }
                }

                ABCHelper.ABCMessageBox.Show(ex.Source + ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(0);
            }
        }
Exemplo n.º 14
0
        public static void SynchronizeTablePermission( )
        {
            GEPermissionTablesController permissionCtrl = new GEPermissionTablesController();
            String strQuery = String.Format(@"DELETE FROM GEPermissionTables WHERE FK_GEPermissionID NOT IN (SELECT GEPermissionID FROM GEPermissions)");

            BusinessObjectController.RunQuery(strQuery);

            foreach (GEPermissionsInfo permission in new GEPermissionsController().GetListAllObjects())
            {
                #region Table
                Dictionary <String, GEPermissionTablesInfo> lstTables = new Dictionary <string, GEPermissionTablesInfo>();

                foreach (GEPermissionTablesInfo tableInfo in permissionCtrl.GetListByForeignKey("FK_GEPermissionID", permission.GEPermissionID).Cast <GEPermissionTablesInfo>().ToList())
                {
                    if (lstTables.ContainsKey(tableInfo.TableName) == false)
                    {
                        if (DataStructureProvider.IsExistedTable(tableInfo.TableName))
                        {
                            lstTables.Add(tableInfo.TableName, tableInfo);
                        }
                        else
                        {
                            permissionCtrl.DeleteObject(tableInfo);
                        }
                    }
                }


                foreach (String strTableName in DataStructureProvider.DataTablesList.Keys)
                {
                    if (lstTables.ContainsKey(strTableName) == false)
                    {
                        GEPermissionTablesInfo tableInfo = new GEPermissionTablesInfo();
                        tableInfo.FK_STTableConfigID = DataConfigProvider.TableConfigList[strTableName].ConfigID;
                        tableInfo.TableName          = strTableName;
                        tableInfo.FK_GEPermissionID  = permission.GEPermissionID;
                        tableInfo.AllowView          = true;
                        tableInfo.AllowNew           = true;
                        tableInfo.AllowEdit          = true;
                        tableInfo.AllowDelete        = true;

                        permissionCtrl.CreateObject(tableInfo);
                        lstTables.Add(tableInfo.TableName, tableInfo);
                    }
                }
                #endregion
            }
        }
Exemplo n.º 15
0
        public static void CreateNewNotifyFromComment(String strUser, String strTableName, Guid iID)
        {
            if (strUser != ABCUserProvider.CurrentUserName)
            {
                String strTitle      = DataConfigProvider.GetTableCaption(strTableName);
                String strDisplayCol = DataStructureProvider.GetDisplayColumn(strTableName);
                String strIDCol      = DataStructureProvider.GetPrimaryKeyColumn(strTableName);

                object obj = BusinessObjectController.GetData(String.Format(@"SELECT {0} FROM {1} WHERE {2} ='{3}' ", strDisplayCol, strTableName, strIDCol, iID));
                if (obj != null && obj != DBNull.Value)
                {
                    strTitle = strTitle + " : " + obj.ToString();
                }
                CreateNewNotify(strUser, strTitle, "", strTableName, iID, "");
            }
        }
Exemplo n.º 16
0
        public int GetMaxNoIndex(string tableName)
        {
            if (DataStructureProvider.IsTableColumn(tableName, "NoIndex") == false)
            {
                return(-1);
            }

            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsSystemTable(tableName))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            DbCommand cmd = null;

            if (MaxIndexCommandList.TryGetValue(tableName, out cmd) == false)
            {
                String sqlCommand = String.Format("SELECT Max(NoIndex) FROM [{0}]", tableName);
                cmd = db.GetSqlStringCommand(sqlCommand);
                MaxIndexCommandList.Add(tableName, cmd);
            }

            DataSet ds = db.ExecuteDataSet(cmd);

            if (ds != null && ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows[0][0] == System.DBNull.Value)
                {
                    return(0);
                }
                else
                {
                    return(Convert.ToInt32(ds.Tables[0].Rows[0][0]));
                }
            }
            return(-1);
        }
Exemplo n.º 17
0
        public object RunScript(string strScriptQuery, BusinessObject obj)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(strScriptQuery))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            if (String.IsNullOrWhiteSpace(strScriptQuery))
            {
                return(null);
            }

            if (DataQueryProvider.IsSQLConnection(db) == false)
            {
                strScriptQuery = SQLiteDatabaseHelper.RepairSelectSQLite(strScriptQuery);
            }


            try
            {
                DbCommand cmd = GetScriptCommand(strScriptQuery);
                AddParameterForObject(obj, cmd);

                db.ExecuteNonQuery(cmd);
                Guid ret = ABCHelper.DataConverter.ConvertToGuid(db.GetParameterValue(cmd, DataStructureProvider.GetPrimaryKeyColumn(obj.AATableName)));
                return(ret);
            }
            catch (System.Exception ex)
            {
                ABCHelper.ABCMessageBox.Show(ex.Source + ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(0);
            }
        }
Exemplo n.º 18
0
        private static void LoadLookupTable(String strTableName)
        {
            if (LookupTables.ContainsKey(strTableName) == false && LastUpdateTimes.ContainsKey(strTableName) == false)
            {
                BusinessObjectController Ctrl = BusinessControllerFactory.GetBusinessController(strTableName);
                if (Ctrl != null)
                {
                    DataSet ds = Ctrl.GetDataSetAllObjects();
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        LookupTables.Add(strTableName, ds.Tables[0]);

                        if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colUpdateTime))
                        {
                            LastUpdateTimes.Add(strTableName, TimeProvider.GetTableLastUpdateTime(strTableName));
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        public static object GetCachingObjectDisplayAccrossTable(String strTableName, Guid iFieldValue, String strFieldString, String strIDTableName)
        {
            AccrossStructInfo info = GetAccrossStructInfo(strTableName, iFieldValue, strFieldString, strIDTableName);

            if (info != null && DataStructureProvider.IsTableColumn(info.TableName, info.FieldName))
            {
                BusinessObject objResult = GetCachedBusinessObject(info.TableName, info.TableID);
                object         obj       = ABCBusinessEntities.ABCDynamicInvoker.GetValue(objResult, info.FieldName);

                String strEnum = DataConfigProvider.TableConfigList[info.TableName].FieldConfigList[info.FieldName].AssignedEnum;
                if (EnumProvider.EnumList.ContainsKey(strEnum) &&
                    EnumProvider.EnumList[strEnum].Items.ContainsKey(obj.ToString()))
                {
                    return(EnumProvider.EnumList[strEnum].Items[obj.ToString()].CaptionVN);
                }

                return(obj);
            }
            return(null);
        }
Exemplo n.º 20
0
        public static double GetCredit(Guid partnerID, CreditConfigType configType)
        {
            double amt = 0;

            foreach (CRCreditConfigsInfo config in GetCreditConfigs(configType))
            {
                String strFKPartnerIDCol = config.PartnerIDField;
                if (String.IsNullOrWhiteSpace(strFKPartnerIDCol))
                {
                    strFKPartnerIDCol = "FK_MAPartnerID";
                }

                String strQuery = QueryGenerator.GenSelect(config.TableName, String.Format("SUM({0})", config.AmtFCField), true);
                strQuery = QueryGenerator.AddCondition(strQuery, config.ConditionString);

                if (DataStructureProvider.IsTableColumn(config.TableName, strFKPartnerIDCol))
                {
                    strQuery = QueryGenerator.AddEqualCondition(strQuery, strFKPartnerIDCol, partnerID);
                }
                else
                {
                    if (DataStructureProvider.IsExistedTable(config.ParentTableName))
                    {
                        if (DataStructureProvider.IsTableColumn(config.ParentTableName, strFKPartnerIDCol))
                        {
                            String strFK     = DataStructureProvider.GetForeignKeyOfTableName(config.TableName, config.ParentTableName);
                            String strQuery2 = QueryGenerator.GenSelect(config.ParentTableName, DataStructureProvider.GetPrimaryKeyColumn(config.ParentTableName), true);
                            strQuery2 = QueryGenerator.AddEqualCondition(strQuery2, strFKPartnerIDCol, partnerID);
                            strQuery  = QueryGenerator.AddCondition(strQuery, String.Format("{0} IN ({1})", strFK, strQuery2));
                        }
                    }
                }

                object obj = BusinessObjectController.GetData(strQuery);
                if (obj != null && obj != DBNull.Value)
                {
                    amt += Convert.ToDouble(obj);
                }
            }
            return(amt);
        }
Exemplo n.º 21
0
        public DataSet RunStoredProcedure(string strSPName)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(strSPName))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            if (String.IsNullOrWhiteSpace(strSPName))
            {
                return(null);
            }

            try
            {
                DbCommand cmd = GetSPCommand(strSPName);
                return(db.ExecuteDataSet(cmd));
            }
            catch (System.Exception ex)
            {
                if (ex is System.Data.SqlClient.SqlException)
                {
                    if (((System.Data.SqlClient.SqlException)ex).ErrorCode == -2146232060 && ex.Message.Contains("TCP Provider"))
                    {
                        ShowDisconnectWaitingDialog();
                        return(null);
                    }
                }
                ABCHelper.ABCMessageBox.Show(ex.Message);
                return(null);
            }
        }
Exemplo n.º 22
0
        public static string GetDisplayColumn(string strTableName)
        {
            String strResult = String.Empty;

            if (DataConfigProvider.TableConfigList.ContainsKey(strTableName))
            {
                foreach (DataConfigProvider.FieldConfig fieldConfig in DataConfigProvider.TableConfigList[strTableName].FieldConfigList.Values)
                {
                    if (fieldConfig.IsDisplayField)
                    {
                        strResult = fieldConfig.FieldName;
                        break;
                    }
                }
            }

            if (String.IsNullOrWhiteSpace(strResult))
            {
                strResult = DataStructureProvider.GetNAMEColumn(strTableName);
            }

            if (String.IsNullOrWhiteSpace(strResult))
            {
                strResult = DataStructureProvider.GetNOColumn(strTableName);
            }

            if (String.IsNullOrWhiteSpace(strResult))
            {
                if (DataStructureProvider.IsTableColumn(strTableName, "Remark"))
                {
                    strResult = "Remark";
                }
            }
            if (String.IsNullOrWhiteSpace(strResult))
            {
                strResult = DataStructureProvider.GetPrimaryKeyColumn(strTableName);
            }

            return(strResult);
        }
Exemplo n.º 23
0
        public static BusinessObject GetCachedBusinessObject(String strTableName, Guid iID)
        {
            if (String.IsNullOrWhiteSpace(strTableName))
            {
                return(null);
            }

            if (!DataStructureProvider.IsExistedTable(strTableName))
            {
                return(null);
            }

            DataView view = TryToGetDataView(strTableName, false);

            DataRow[] rows = view.Table.Select(String.Format("{0} = '{1}'", DataStructureProvider.GetPrimaryKeyColumn(strTableName), iID));
            if (rows.Length <= 0)
            {
                return(null);
            }

            return(BusinessControllerFactory.GetBusinessController(strTableName).GetObjectFromDataRow(rows[0]));
        }
Exemplo n.º 24
0
        public static void CalculateCredit(String strTableName, Guid ID)
        {
            List <Guid> lstPartnerIDs     = new List <Guid>();
            BusinessObjectController ctrl = BusinessControllerFactory.GetBusinessController(strTableName);

            if (ctrl != null)
            {
                BusinessObject obj = ctrl.GetObjectByID(ID);
                if (obj != null)
                {
                    String strPartnerFKCol = DataStructureProvider.GetForeignKeyOfTableName(strTableName, "MAPartners");
                    if (String.IsNullOrWhiteSpace(strPartnerFKCol) == false)
                    {
                        Guid partnerID = ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(obj, strPartnerFKCol));
                        if (partnerID != Guid.Empty && !lstPartnerIDs.Contains(partnerID))
                        {
                            lstPartnerIDs.Add(partnerID);
                        }
                    }

                    foreach (GEVoucherItemsInfo voucherItem in VoucherProvider.GetConfigItems(strTableName, ""))
                    {
                        strPartnerFKCol = DataStructureProvider.GetForeignKeyOfTableName(voucherItem.ItemTableName, "MAPartners");
                        if (String.IsNullOrWhiteSpace(strPartnerFKCol) == false)
                        {
                            Guid partnerID = ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(obj, strPartnerFKCol));
                            if (partnerID != Guid.Empty && !lstPartnerIDs.Contains(partnerID))
                            {
                                lstPartnerIDs.Add(partnerID);
                            }
                        }
                    }
                }
            }
            foreach (Guid partnerID in lstPartnerIDs)
            {
                CreditProvider.CalculateCredit(partnerID);
            }
        }
Exemplo n.º 25
0
        public string ExecuteScript(String strScript)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(strScript))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            try
            {
                if (DataQueryProvider.IsSQLConnection(db) == false)
                {
                    strScript = SQLiteDatabaseHelper.RepairSelectSQLite(strScript);
                }

                db.ExecuteNonQuery(CommandType.Text, strScript);
                return("Command excute succesfully!");
            }
            catch (System.Exception ex)
            {
                if (ex is System.Data.SqlClient.SqlException)
                {
                    if (((System.Data.SqlClient.SqlException)ex).ErrorCode == -2146232060 && ex.Message.Contains("TCP Provider"))
                    {
                        ShowDisconnectWaitingDialog();
                    }
                }

                return(ex.Message);
            }
        }
Exemplo n.º 26
0
        // caching Command
        public DataSet RunScript(string strScriptQuery)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(strScriptQuery))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }

            if (String.IsNullOrWhiteSpace(strScriptQuery))
            {
                return(null);
            }

            if (DataQueryProvider.IsSQLConnection(db) == false)
            {
                strScriptQuery = SQLiteDatabaseHelper.RepairSelectSQLite(strScriptQuery);
            }


            try
            {
                DbCommand cmd = GetScriptCommand(strScriptQuery);
                return(db.ExecuteDataSet(cmd));
            }
            catch (System.Exception ex)
            {
                ABCHelper.ABCMessageBox.Show(ex.Message);
                return(null);
            }
        }
Exemplo n.º 27
0
        public static ABCFormatInfo GetFormatInfo(String strTableName, String strFieldString)
        {
            if (String.IsNullOrWhiteSpace(strFieldString) || String.IsNullOrWhiteSpace(strTableName))
            {
                return(null);
            }

            String TableName = strTableName;
            String FieldName = strFieldString;

            if (strFieldString.Contains(":"))
            {
                DataCachingProvider.AccrossStructInfo structInfo = DataCachingProvider.GetAccrossStructInfo(strTableName, strFieldString);
                if (structInfo != null)
                {
                    TableName = structInfo.TableName;
                    FieldName = structInfo.FieldName;
                }
            }

            if (DataStructureProvider.IsTableColumn(TableName, FieldName) == false)
            {
                return(null);
            }

            if (DataStructureProvider.IsForeignKey(TableName, FieldName))
            {
                TableName = DataStructureProvider.GetTableNameOfForeignKey(TableName, FieldName);
                FieldName = DataStructureProvider.GetDisplayColumn(TableName);
            }
            if (DataConfigProvider.TableConfigList.ContainsKey(TableName) &&
                DataConfigProvider.TableConfigList[TableName].FieldConfigList.ContainsKey(FieldName))
            {
                return(GetFormatInfo(DataConfigProvider.TableConfigList[TableName].FieldConfigList[FieldName].Format));
            }

            return(null);
        }
Exemplo n.º 28
0
        public object RunCommand(DbCommand cmd, string retVariable)
        {
            Database db = CurrentDatabase;

            if (CurrentDatabase == null)
            {
                if (DataStructureProvider.IsQuerySystemDB(cmd.CommandText))
                {
                    db = DataQueryProvider.SystemDatabase;
                }
                else
                {
                    db = DataQueryProvider.CompanyDatabase;
                }
            }


            try
            {
                db.ExecuteNonQuery(cmd);
                return((object)db.GetParameterValue(cmd, retVariable));
            }
            catch (System.Exception ex)
            {
                if (ex is System.Data.SqlClient.SqlException)
                {
                    if (((System.Data.SqlClient.SqlException)ex).ErrorCode == -2146232060 && ex.Message.Contains("TCP Provider"))
                    {
                        ShowDisconnectWaitingDialog();
                        return(null);
                    }
                }
                ABCHelper.ABCMessageBox.Show(ex.Message);
                return(null);
            }
        }
Exemplo n.º 29
0
        public static AccrossStructInfo GetAccrossStructInfo(String strTableName, Guid iFieldValue, String strFieldString, String strIDTableName)
        {
            if (String.IsNullOrWhiteSpace(strFieldString))
            {
                return(null);
            }

            String[] strArr = strFieldString.Split(':');

            if (DataStructureProvider.IsForeignKey(strTableName, strArr[0]) == false && strArr[0] != "ID")
            {
                return(null);
            }

            AccrossStructInfo result = new AccrossStructInfo();

            if (strArr[0] == "ID" && !String.IsNullOrWhiteSpace(strIDTableName))
            {
                result.TableName = strIDTableName;
            }
            else
            {
                result.TableName = DataStructureProvider.GetTableNameOfForeignKey(strTableName, strArr[0]);
            }

            result.TableID   = iFieldValue;
            result.FieldName = String.Empty;

            if (!DataStructureProvider.IsExistedTable(result.TableName))
            {
                return(null);
            }

            BusinessObject objTable = GetCachedBusinessObject(result.TableName, result.TableID);

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

            for (int i = 1; i < strArr.Length; i++)
            {
                result.FieldName = strArr[i];
                if (result.FieldName == "ID" && DataStructureProvider.IsTableColumn(result.TableName, "TableName"))
                {
                    object objTemp = ABCBusinessEntities.ABCDynamicInvoker.GetValue(objTable, "TableName");
                    if (objTemp == null)
                    {
                        break;
                    }
                    result.TableName = objTemp.ToString();

                    objTemp = ABCBusinessEntities.ABCDynamicInvoker.GetValue(objTable, result.FieldName);
                    if (objTemp == null)
                    {
                        break;
                    }
                    result.TableID = ABCHelper.DataConverter.ConvertToGuid(objTemp);
                }
                else
                {
                    if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName) == false)
                    {
                        break;
                    }

                    result.TableName = DataStructureProvider.GetTableNameOfForeignKey(result.TableName, result.FieldName);
                    object objValue = ABCBusinessEntities.ABCDynamicInvoker.GetValue(objTable, result.FieldName);
                    if (objValue == null)
                    {
                        break;
                    }

                    result.TableID = ABCHelper.DataConverter.ConvertToGuid(objValue);
                    objTable       = GetCachedBusinessObject(result.TableName, result.TableID);
                    if (objTable == null)
                    {
                        break;
                    }
                }
                result.FieldName = String.Empty;
            }

            if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName) || result.FieldName == String.Empty)
            {
                if (DataStructureProvider.IsForeignKey(result.TableName, result.FieldName))
                {
                    result.TableName = DataStructureProvider.GetTableNameOfForeignKey(result.TableName, result.FieldName);
                }

                result.FieldName = DataStructureProvider.GetDisplayColumn(result.TableName);
            }

            if (String.IsNullOrWhiteSpace(result.FieldName))
            {
                result.FieldName = DataStructureProvider.GetDisplayColumn(result.TableName);
            }
            if (String.IsNullOrWhiteSpace(result.FieldName))
            {
                result.FieldName = DataStructureProvider.GetPrimaryKeyColumn(result.TableName);
            }

            return(result);
        }
Exemplo n.º 30
0
 public static AccrossStructInfo GetAccrossStructInfo(BusinessObject baseObj, Guid iFieldValue, String strFieldString)
 {
     if (strFieldString.Contains(":") && strFieldString.Split(':')[0] == "ID" && DataStructureProvider.IsTableColumn(baseObj.AATableName, "TableName"))
     {
         object strIDTableName = ABCDynamicInvoker.GetValue(baseObj, "TableName");
         if (strIDTableName != null)
         {
             return(GetAccrossStructInfo(baseObj.AATableName, iFieldValue, strFieldString, strIDTableName.ToString()));
         }
     }
     return(GetAccrossStructInfo(baseObj.AATableName, iFieldValue, strFieldString));
 }