public static void GeneratePeriods( ) { GEPeriodsController periodCtrl = new GEPeriodsController(); for (int year = ABCApp.ABCDataGlobal.WorkingDate.Year; year <= ABCApp.ABCDataGlobal.WorkingDate.Year + 1; year++) { String strQuery = String.Format(@"SELECT COUNT(*) FROM GEPeriods WHERE Year = {0}", year); object objAmt = BusinessObjectController.GetData(strQuery); if (objAmt == null || objAmt == DBNull.Value || Convert.ToInt32(objAmt) != 12) { strQuery = String.Format(@"DELETE FROM GEPeriods WHERE Year = {0}", year); BusinessObjectController.RunQuery(strQuery); for (int i = 1; i <= 12; i++) { GEPeriodsInfo period = new GEPeriodsInfo(); period.Month = i; period.Year = year; period.Period = new DateTime(period.Year.Value, period.Month.Value, 1); if (i >= 10) { period.No = String.Format("Tháng {0}/{1}", period.Month.Value, period.Year.Value); } else { period.No = String.Format("Tháng 0{0}/{1}", period.Month.Value, period.Year.Value); } period.Closed = false; periodCtrl.CreateObject(period); } } } }
public static void StartOnlineTimer( ) { object obj = BusinessObjectController.GetData(String.Format(@"SELECT COUNT(*) FROM ADUserStatuss WHERE FK_ADUserID ='{0}' ", CurrentUser.ADUserID)); if (obj != null && obj != DBNull.Value) { int iCount = Convert.ToInt32(obj); if (iCount <= 0) { String strQuery = String.Format(@"INSERT INTO ADUserStatuss ( ADUserStatusID,CreateTime,UpdateTime,FK_ADUserID , UserName , EmployeeName , LastOnlineTime , IsOnline ,OnlineStatus) VALUES (NEWID(),GETDATE(),GETDATE(),'{0}',N'{1}' ,N'{2}',GetDate(),1,'')", CurrentUser.ADUserID, CurrentUser.No.Replace("'", "''"), ABCUserProvider.CurrentEmployeeName.Replace("'", "''")); if (DataQueryProvider.IsCompanySQLConnection == false) { strQuery = String.Format(@"INSERT INTO ADUserStatuss ( ADUserStatusID,CreateTime,UpdateTime,FK_ADUserID , UserName , EmployeeName , LastOnlineTime , IsOnline ,OnlineStatus) VALUES (NEWID(),GETDATE(),GETDATE(),'{0}',N'{1}' ,N'{2}',DATETIME('now', 'localtime'),1,'')", CurrentUser.ADUserID, CurrentUser.No.Replace("'", "''"), ABCUserProvider.CurrentEmployeeName.Replace("'", "''")); } BusinessObjectController.RunQuery(strQuery); } } OnlineUpdate(true); if (OnlineTimer == null) { OnlineTimer = new System.Timers.Timer(); OnlineTimer.Interval = 60000; OnlineTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnlineTimer_Elapsed); OnlineTimer.Start(); } }
public static Boolean IsNeedAlert(Guid alertID) { if (AlertList == null) { GetAlertConfigs(ABCUserProvider.CurrentUser.ADUserID); } if (AlertList.ContainsKey(alertID) == false) { return(false); } GEAlertsInfo alertInfo = AlertList[alertID]; if (alertInfo == null || alertInfo.GetID() == null) { return(false); } String strQuery = QueryGenerator.GenSelect(alertInfo.TableName, "COUNT(*)", false); strQuery = QueryGenerator.AddCondition(strQuery, alertInfo.ConditionString); object obj = BusinessObjectController.GetData(strQuery); if (obj != null && obj != DBNull.Value) { return(Convert.ToInt32(obj) > 0); } return(false); }
public static void CreateNewNotify(String strToUser, String strToEmployee, String strNotifyTitle, String strNotifyContent, String strTableName, Guid iID, String strPriorityLevel) { if (strToUser == ABCUserProvider.CurrentUserName) { return; } strToUser = strToUser.Replace("'", "''"); strToEmployee = strToEmployee.Replace("'", "''"); strNotifyTitle = strNotifyTitle.Replace("'", "''"); strNotifyContent = strNotifyContent.Replace("'", "''"); strTableName = strTableName.Replace("'", "''"); strPriorityLevel = strPriorityLevel.Replace("'", "''"); object obj = BusinessObjectController.GetData(String.Format(@"SELECT GENotifyID FROM GENotifys WHERE ToUser=N'{0}' AND TableName ='{1}' AND ID ='{2}'", strToUser, strTableName, iID)); Guid iNofityID = ABCHelper.DataConverter.ConvertToGuid(obj); String strQuery = String.Empty; if (iNofityID == Guid.Empty) { strQuery = String.Format(@"INSERT INTO GENotifys ( GENotifyID,LastTime , ToUser , ToEmployee , NotifyTitle , NotifyContent ,Viewed,TableName,ID,PriorityLevel ) VALUES ('{0}',GetDate() ,N'{1}' ,N'{2}' ,N'{3}',N'{4}',0,'{5}','{6}',N'{7}')", Guid.NewGuid(), strToUser, strToEmployee, strNotifyTitle, strNotifyContent, strTableName, iID, strPriorityLevel); } else { strQuery = String.Format(@"UPDATE GENotifys SET LastTime = GetDate() , NotifyTitle =N'{0}' , NotifyContent =N'{1}', Viewed =0, PriorityLevel =N'{2}' WHERE GENotifyID ='{3}' ", strNotifyTitle, strNotifyContent, strPriorityLevel, iNofityID); } BusinessObjectController.RunQuery(strQuery); }
public static bool IsMainObject(String strTableName) { if (String.IsNullOrWhiteSpace(strTableName)) { return(false); } bool isOK = false; if (IsMainObjectCachingList.TryGetValue(strTableName, out isOK)) { return(isOK); } if (String.IsNullOrWhiteSpace(strTableName) == false) { object objCount = BusinessObjectController.GetData(String.Format("SELECT COUNT(*) FROM STViews WHERE [MainTableName] = '{0}' ", strTableName)); if (objCount != null && objCount != DBNull.Value) { if (Convert.ToDouble(objCount) > 0) { isOK = true; } } } IsMainObjectCachingList.Add(strTableName, isOK); return(isOK); }
public static double GetJournalAmount(List <String> lstDebitAccounts, List <String> lstCreditAccounts, DateTime?startDate, DateTime?endDate, String strConditionQuery, bool isIncludeChildren) { List <GLAccountsInfo> lstDebits = GetAccounts(lstDebitAccounts, isIncludeChildren); List <GLAccountsInfo> lstCredits = GetAccounts(lstCreditAccounts, isIncludeChildren); String strDebit = String.Empty; foreach (GLAccountsInfo acc in lstDebits) { if (String.IsNullOrEmpty(strDebit) == false) { strDebit += " OR "; } strDebit += String.Format(@" FK_GLAccountID_Debit='{0}' ", acc.GLAccountID); } strDebit = "(" + strDebit + ")"; String stCredit = String.Empty; foreach (GLAccountsInfo acc in lstCredits) { if (String.IsNullOrEmpty(stCredit) == false) { stCredit += " OR "; } stCredit += String.Format(@" FK_GLAccountID_Credit='{0}' ", acc.GLAccountID); } stCredit = "(" + stCredit + ")"; double dbResult = 0; String strQuery = String.Format(@"SELECT SUM(AmtTot) FROM GLJournalEntrys WHERE ApprovalStatus='{0}' AND {1} AND {2} ", ABCCommon.ABCConstString.ApprovalTypeApproved, strDebit, stCredit); if (startDate.HasValue) { strQuery += String.Format(@" AND {0}", TimeProvider.GenCompareDateTime("JournalDate", ">=", startDate.Value)); } if (endDate.HasValue) { strQuery += String.Format(@" AND {0} ", TimeProvider.GenCompareDateTime("JournalDate", "<=", endDate.Value)); } if (String.IsNullOrWhiteSpace(strConditionQuery) == false) { strQuery += String.Format(@" AND {0} ", strConditionQuery); } object objAmt = BusinessObjectController.GetData(strQuery); if (objAmt != null && objAmt != DBNull.Value) { dbResult += Convert.ToDouble(objAmt); } return(dbResult); }
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); }
public static bool IsNeedValuationCalculate(String strTableName) { object iCount = BusinessObjectController.GetData(String.Format("SELECT COUNT(*) FROM ICInventoryConfigs WHERE VoucherTableName = '{0}' AND COGSEffective='TRUE' ", strTableName)); if (iCount == null || iCount.GetType() != typeof(int)) { return(false); } return(Convert.ToInt32(iCount) > 0); }
public static bool IsNeedCalculateCredit(String strTableName) { object iCount = BusinessObjectController.GetData(String.Format("SELECT COUNT(*) FROM CRCreditConfigs WHERE TableName = '{0}'", strTableName)); if (iCount == null || iCount.GetType() != typeof(int)) { return(false); } return(Convert.ToInt32(iCount) > 0); }
public static double GetDebitAmount(GLAccountsInfo accInfo, DateTime?startDate, DateTime?endDate, String strConditionQuery, bool isIncludeChildren) { double dbResult = 0; String strQuery = String.Format(@"SELECT SUM(AmtTot) FROM GLJournalEntrys WHERE ApprovalStatus='{0}' AND FK_GLAccountID_Debit={1} ", ABCCommon.ABCConstString.ApprovalTypeApproved, accInfo.GLAccountID); if (startDate.HasValue) { strQuery += String.Format(@" AND {0}", TimeProvider.GenCompareDateTime("JournalDate", ">=", startDate.Value)); } if (endDate.HasValue) { strQuery += String.Format(@" AND {0} ", TimeProvider.GenCompareDateTime("JournalDate", "<=", endDate.Value)); } if (String.IsNullOrWhiteSpace(strConditionQuery) == false) { strQuery += String.Format(@" AND {0} ", strConditionQuery); } object objAmt = BusinessObjectController.GetData(strQuery); if (objAmt != null && objAmt != DBNull.Value) { dbResult += Convert.ToDouble(objAmt); } if (isIncludeChildren) { List <BusinessObject> lstChildren = new GLAccountsController().GetListByForeignKey("FK_GLAccountID", accInfo.GLAccountID); foreach (GLAccountsInfo accChildInfo in lstChildren) { dbResult += GetDebitAmount(accChildInfo, startDate, endDate, strConditionQuery, true); } if (lstChildren.Count <= 0) { if (startDate.HasValue == false || (startDate.HasValue && startDate.Value <= SystemProvider.AppConfig.StartDate.Value)) { dbResult += accInfo.DebitBeginBalance; } } } else { if (startDate.HasValue == false || (startDate.HasValue && startDate.Value <= SystemProvider.AppConfig.StartDate.Value)) { dbResult += accInfo.DebitBeginBalance; } } return(dbResult); }
private void CheckPlaySound( ) { String strQuery = String.Format(@"SELECT COUNT(*) FROM GEChatContents WHERE (ToUser =N'{0}' AND FromUser =N'{1}') AND Viewed =0 AND {2}" , User1, User2, TimeProvider.GenCompareDateTime("CreateTime", ">", lastUpdate)); object objQty = BusinessObjectController.GetData(strQuery); if (objQty != null && objQty != DBNull.Value && Convert.ToInt32(objQty) > 0) { IsViewed = false; if ((this.ChatBox.ChatScreen.Visible == false || this.ChatBox.ChatScreen.WindowState == FormWindowState.Minimized) && this.ChatBox.ChatScreen.SoundOn) { new System.Media.SoundPlayer(@"SoundChat.wav").Play(); } } }
public static void CreateNewNotify(String strToUser, String strNotifyTitle, String strNotifyContent, String strTableName, Guid iID, String strPriorityLevel) { if (strToUser == ABCUserProvider.CurrentUserName) { return; } object obj = BusinessObjectController.GetData(String.Format(@"SELECT HREmployees.Name FROM ADUsers,HREmployees WHERE ADUsers.ABCStatus ='Alive' AND ADUsers.Active =1 AND FK_HREmployeeID =HREmployeeID AND ADUsers.No =N'{0}'", strToUser)); if (obj != null && obj != DBNull.Value) { CreateNewNotify(strToUser, obj.ToString(), strNotifyTitle, strNotifyContent, strTableName, iID, strPriorityLevel); } }
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, ""); } }
public static double GetJournalAmount(GLAccountsInfo debitAccount, GLAccountsInfo creditAccount, DateTime?startDate, DateTime?endDate, String strConditionQuery, bool isIncludeChildren) { double dbResult = 0; String strQuery = String.Format(@"SELECT SUM(AmtTot) FROM GLJournalEntrys WHERE ApprovalStatus='{0}' AND FK_GLAccountID_Debit='{1}' AND FK_GLAccountID_Credit='{2}' ", ABCCommon.ABCConstString.ApprovalTypeApproved, debitAccount.GLAccountID, creditAccount.GLAccountID); if (startDate.HasValue) { strQuery += String.Format(@" AND {0}", TimeProvider.GenCompareDateTime("JournalDate", ">=", startDate.Value)); } if (endDate.HasValue) { strQuery += String.Format(@" AND {0} ", TimeProvider.GenCompareDateTime("JournalDate", "<=", endDate.Value)); } if (String.IsNullOrWhiteSpace(strConditionQuery) == false) { strQuery += String.Format(@" AND {0} ", strConditionQuery); } object objAmt = BusinessObjectController.GetData(strQuery); if (objAmt != null && objAmt != DBNull.Value) { dbResult += Convert.ToDouble(objAmt); } if (isIncludeChildren) { List <BusinessObject> lstChildren = new GLAccountsController().GetListByForeignKey("FK_GLAccountID", creditAccount.GLAccountID); foreach (GLAccountsInfo creditChild in lstChildren) { dbResult += GetJournalAmount(debitAccount, creditChild, startDate, endDate, strConditionQuery, true); } lstChildren = new GLAccountsController().GetListByForeignKey("FK_GLAccountID", debitAccount.GLAccountID); foreach (GLAccountsInfo debitChild in lstChildren) { dbResult += GetJournalAmount(debitChild, creditAccount, startDate, endDate, strConditionQuery, true); } } return(dbResult); }
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); }
public void ReloadNotifies(bool isFirstLoad) { bool isHasNew = false; String strQuery = String.Format(@"SELECT COUNT(*) FROM GENotifys WHERE ToUser ='******' AND Viewed =0 AND {1}", ABCUserProvider.CurrentUserName, TimeProvider.GenCompareDateTime("LastTime", ">", lastUpdate)); object objQty = BusinessObjectController.GetData(strQuery); if (objQty != null && objQty != DBNull.Value && Convert.ToInt32(objQty) > 0) { isHasNew = true; if (this.SoundOn) { new System.Media.SoundPlayer(@"SoundMail.wav").Play(); } } if (isFirstLoad || NotifiesTable == null || isHasNew) { DataSet ds = BusinessObjectController.RunQuery(String.Format(@"SELECT * FROM GENotifys WHERE ToUser ='******' ORDER BY LastTime DESC", ABCUserProvider.CurrentUserName)); if (ds != null && ds.Tables.Count > 0) { if (NotifiesTable != null) { NotifiesTable.Dispose(); } NotifiesTable = ds.Tables[0]; } } if (NotifiesTable != null && NotifiesTable.Rows.Count > 0) { object obj = NotifiesTable.Rows[0]["LastTime"]; if (obj != null && obj != DBNull.Value) { lastUpdate = Convert.ToDateTime(obj); } } RefreshDataSource(); StartTimer(); }
public static Numbering GetNumberingConfig(BusinessObject obj) { if (NumberingConfigs == null || NumberingTypes == null) { InitializeNumberings(); } foreach (Numbering config in NumberingConfigs) { if (config.TableName != obj.AATableName) { continue; } if (!String.IsNullOrWhiteSpace(config.FieldCondition) && !String.IsNullOrWhiteSpace(config.FieldValue)) { object fileValue = ABCDynamicInvoker.GetValue(obj, config.FieldCondition); if (fileValue == null || fileValue == DBNull.Value || fileValue.ToString() != config.FieldValue) { continue; } } if (!String.IsNullOrWhiteSpace(config.ConditionString)) { String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false); strQuery = QueryGenerator.AddCondition(strQuery, config.ConditionString); strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@"{0}='{1}'", DataStructureProvider.GetPrimaryKeyColumn(obj.AATableName), obj.GetID())); object objCount = BusinessObjectController.GetData(strQuery); if (objCount == null || objCount == DBNull.Value || Convert.ToInt32(objCount.ToString()) <= 0) { continue; } } return(config); } return(null); }
public static bool CalculateMainOnly(BaseVoucher voucher, BusinessObject obj, Dictionary <String, IEnumerable <BusinessObject> > lstObjecItems, String strAferValidateFieldName, bool isSave) { if (FormulasList == null) { InitFormulas(); } if (!FormulasList.ContainsKey(obj.AATableName)) { return(false); } bool isCalculated = false; Dictionary <String, double> lstVariables = new Dictionary <string, double>(); bool isContinue = false; foreach (GEFormulaItemsInfo formula in FormulasList[obj.AATableName].Values) { if (String.IsNullOrWhiteSpace(formula.FormulaName)) { continue; } #region isNeedCalc bool isNeedCalc = isContinue; if (!isNeedCalc) { if (formula.IsVariable) { isNeedCalc = true; } else { if (String.IsNullOrWhiteSpace(strAferValidateFieldName)) { isNeedCalc = true; } else { if (FormulasList[obj.AATableName].Values.Count(t => t.FormulaName == strAferValidateFieldName) > 0) { if (formula.FormulaName == strAferValidateFieldName) { isContinue = true; continue; } } else { if (DataConfigProvider.GetFieldSortOrder(obj.AATableName, strAferValidateFieldName) <= DataConfigProvider.GetFieldSortOrder(obj.AATableName, formula.FormulaName)) { isContinue = true; isNeedCalc = true; } } } } } if (!isNeedCalc) { continue; } #endregion object objAmt = null; if (formula.IsUseQuery && !String.IsNullOrWhiteSpace(formula.QueryString)) { #region Query String strQuery = formula.QueryString.Replace("{TableName}", obj.AATableName); if (obj.GetID() != Guid.Empty) { strQuery = strQuery.Replace("{ID}", obj.GetID().ToString()); } foreach (String strProperty in DataStructureProvider.DataTablesList[obj.AATableName].ColumnsList.Keys) { if (strQuery.Contains("{" + strProperty + "}")) { object objValue = ABCDynamicInvoker.GetValue(obj, strProperty); if (objValue == null || objValue == DBNull.Value) { strQuery = strQuery.Replace("{" + strProperty + "}", "NULL"); } else { strQuery = strQuery.Replace("{" + strProperty + "}", objValue.ToString()); } } } foreach (String strVariableName in lstVariables.Keys) { if (strQuery.Contains("{" + strVariableName + "}")) { strQuery = strQuery.Replace("{" + strVariableName + "}", lstVariables[strVariableName].ToString()); } } #endregion objAmt = BusinessObjectController.GetData(strQuery); } else if (formula.IsUseFormula && !String.IsNullOrWhiteSpace(formula.Formula)) { String strExpression = formula.Formula; #region Formula foreach (String strProperty in DataStructureProvider.DataTablesList[obj.AATableName].ColumnsList.Keys) { strExpression = strExpression.Replace("{" + strProperty + "}", "[" + strProperty + "]"); } foreach (String strVariableName in lstVariables.Keys) { strExpression = strExpression.Replace("{" + strVariableName + "}", "[" + strVariableName + "]"); } Expression e = new Expression(strExpression); foreach (String strProperty in DataStructureProvider.DataTablesList[obj.AATableName].ColumnsList.Keys) { if (strExpression.Contains("[" + strProperty + "]")) { object objValue = ABCDynamicInvoker.GetValue(obj, strProperty); if (objValue == null) { continue; } double dbValue = 0; Double.TryParse(objValue.ToString(), out dbValue); e.Parameters[strProperty] = dbValue; } } foreach (String strVariableName in lstVariables.Keys) { if (strExpression.Contains("[" + strVariableName + "]")) { e.Parameters[strVariableName] = lstVariables[strVariableName]; } } #endregion objAmt = e.Evaluate(); } else if (formula.IsUseSumFromChild) { objAmt = 0; if (lstObjecItems.ContainsKey(formula.SumChildTableName) && DataStructureProvider.IsTableColumn(formula.SumChildTableName, formula.SumChildFieldName)) { objAmt = lstObjecItems[formula.SumChildTableName].Sum(t => Convert.ToDouble(ABCDynamicInvoker.GetValue((BusinessObject)t, formula.SumChildFieldName))); } } if (formula.IsVariable && lstVariables.ContainsKey(formula.FormulaName) == false) { lstVariables.Add(formula.FormulaName, Math.Round(Convert.ToDouble(objAmt), 3)); } bool isCalculatedWithCurrentFormula = false; if (!formula.IsVariable && DataStructureProvider.IsTableColumn(obj.AATableName, formula.FormulaName)) { if (objAmt != null) { if (objAmt is double) { objAmt = Math.Round(Convert.ToDouble(objAmt), 3); } if (ABCDynamicInvoker.GetValue(obj, formula.FormulaName).ToString() != objAmt.ToString()) { ABCDynamicInvoker.SetValue(obj, formula.FormulaName, objAmt); isCalculatedWithCurrentFormula = true; } } } if (voucher != null && formula.IsCustomByCode) { isCalculatedWithCurrentFormula = voucher.CustomFormulaCalc(obj, lstObjecItems, formula); } isCalculated = isCalculated | isCalculatedWithCurrentFormula; if (isCalculatedWithCurrentFormula && !string.IsNullOrWhiteSpace(formula.FieldRelations)) { foreach (String strRelation in formula.FieldRelations.Split(';').ToList()) { if (FormulasList[obj.AATableName].Values.Count(t => t.FormulaName == strRelation) > 0) { int?iIndex = FormulasList[obj.AATableName].Values.Where(t => t.FormulaName == strRelation).Select(t => t.CalcIndex).First(); if (!iIndex.HasValue) { continue; } if (FormulasList[obj.AATableName].Values.Count(t => t.CalcIndex == iIndex.Value - 1) > 0) { iIndex = FormulasList[obj.AATableName].Values.Where(t => t.CalcIndex == iIndex.Value - 1).Select(t => t.CalcIndex).First(); if (!iIndex.HasValue) { continue; } CalculateMainOnly(voucher, obj, lstObjecItems, strRelation, isSave); } } } } } if (isCalculated && obj.GetID() != null && isSave) { BusinessControllerFactory.GetBusinessController(obj.AATableName).UpdateObject(obj); if (!CalculateQueue.ContainsKey(obj.AATableName)) { CalculateQueue.Add(obj.AATableName, new List <Guid>()); } if (!CalculateQueue[obj.AATableName].Contains(obj.GetID())) { CalculateQueue[obj.AATableName].Add(obj.GetID()); if (DataStructureProvider.DataTablesList.ContainsKey(obj.AATableName)) { foreach (String strFkCol in DataStructureProvider.DataTablesList[obj.AATableName].ForeignColumnsList.Keys) { Guid fkID = ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(obj, strFkCol)); if (fkID == Guid.Empty) { continue; } BusinessObjectController FKCtrl = BusinessControllerFactory.GetBusinessController(DataStructureProvider.GetTableNameOfForeignKey(obj.AATableName, strFkCol)); if (FKCtrl != null) { BusinessObject fkObj = FKCtrl.GetObjectByID(fkID); if (fkObj != null) { Calculate(fkObj, true); } } } } if (!CalculateQueue.ContainsKey(obj.AATableName)) { CalculateQueue.Add(obj.AATableName, new List <Guid>()); } if (!CalculateQueue[obj.AATableName].Contains(obj.GetID())) { CalculateQueue[obj.AATableName].Remove(obj.GetID()); } } } return(isCalculated); }
public static void BenifitCalculate( ) { object objTime = BusinessObjectController.GetData(String.Format(@"SELECT MAX(JournalDate) FROM GLJournalEntrys WHERE ABCStatus ='Alive' AND (EntryType IS NULL OR EntryType != '{0}')", ABCCommon.ABCConstString.EntryTypePeriodEnding)); DateTime currentPeriod = Convert.ToDateTime(objTime.ToString()); if (currentPeriod == null || currentPeriod.Year <= 1000) { return; } AccountForReCalcList.Clear(); GLBenifitCalcsController benifitCalcCtrl = new GLBenifitCalcsController(); List <BusinessObject> lstPeriods = new GEPeriodsController().GetListAllObjects(); foreach (GEPeriodsInfo period in lstPeriods) { if (period.Period.HasValue == false || period.Closed) { continue; } GLBenifitCalcsInfo benifitInfo = benifitCalcCtrl.GetObjectByColumn("FK_GEPeriodID", period.GEPeriodID) as GLBenifitCalcsInfo; if (benifitInfo == null) { DateTime dtStart = new DateTime(SystemProvider.AppConfig.StartDate.Value.Year, SystemProvider.AppConfig.StartDate.Value.Month, 1); if (dtStart <= period.Period.Value && period.Period.Value <= currentPeriod) { benifitInfo = new GLBenifitCalcsInfo(); benifitInfo.FK_GEPeriodID = period.GEPeriodID; benifitInfo.Month = period.Month; benifitInfo.Year = period.Year; benifitInfo.Period = period.Period; benifitInfo.ApprovalStatus = ABCCommon.ABCConstString.ApprovalTypeNew; benifitCalcCtrl.CreateObject(benifitInfo); if (BenifitCalculationOfPeriod(benifitInfo)) { if (period.Period.Value.Year != currentPeriod.Year || period.Period.Value.Month != currentPeriod.Month) { PostBenifitCalculation(benifitInfo); } } } } else { if (period.Period.Value.Year == currentPeriod.Year && period.Period.Value.Month == currentPeriod.Month) { BenifitCalculationOfPeriod(benifitInfo); } else { if (period.Period.Value.AddMonths(1).Year == currentPeriod.Year && period.Period.Value.AddMonths(1).Month == currentPeriod.Month) { if (BenifitCalculationOfPeriod(benifitInfo) || benifitInfo.ApprovalStatus != ABCCommon.ABCConstString.ApprovalTypeApproved) { PostBenifitCalculation(benifitInfo); } } } } } foreach (Guid iAccountID in AccountForReCalcList) { AccountingProvider.CalculateAccount(iAccountID); } DataCachingProvider.RefreshLookupTable("GLJournalVouchers"); }
public static void CreateNewNotifyFromComment(String strTableName, Guid iID) { if (DataStructureProvider.IsExistedTable(strTableName) == false) { return; } String strIDCol = DataStructureProvider.GetPrimaryKeyColumn(strTableName); #region Get Users List <String> lstUsers = new List <string>(); DataSet ds = BusinessObjectController.RunQuery(String.Format(@"SELECT CreateUser FROM GEComments WHERE TableName ='{0}' AND ID = '{1}' GROUP BY CreateUser", strTableName, iID)); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { if (lstUsers.Contains(dr[0].ToString()) == false) { lstUsers.Add(dr[0].ToString()); } } } ds = BusinessObjectController.RunQuery(String.Format(@"SELECT TagString FROM GEComments WHERE TableName ='{0}' AND ID = '{1}' AND TagString IS NOT NULL AND TagString NOT LIKE '' GROUP BY TagString", strTableName, iID)); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { if (dr[0] != null && dr[0] != DBNull.Value && String.IsNullOrWhiteSpace(dr[0].ToString()) == false) { string[] arr = { "::" }; arr = dr[0].ToString().Split(arr, StringSplitOptions.None); for (int i = 0; i < arr.Length; i++) { if (lstUsers.Contains(arr[i]) == false) { lstUsers.Add(arr[i]); } } } } } if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colCreateUser)) { ds = BusinessObjectController.RunQuery(String.Format(@"SELECT {0} FROM {1} WHERE {2} ='{3}'", ABCCommon.ABCConstString.colCreateUser, strTableName, strIDCol, iID)); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { object objCreateUser = ds.Tables[0].Rows[0][0]; if (objCreateUser != null && objCreateUser != DBNull.Value && lstUsers.Contains(objCreateUser.ToString()) == false) { lstUsers.Add(objCreateUser.ToString()); } } } if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colUpdateUser)) { ds = BusinessObjectController.RunQuery(String.Format(@"SELECT {0} FROM {1} WHERE {2} ='{3}'", ABCCommon.ABCConstString.colUpdateUser, strTableName, strIDCol, iID)); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { object objUpdateUser = ds.Tables[0].Rows[0][0]; if (objUpdateUser != null && objUpdateUser != DBNull.Value && lstUsers.Contains(objUpdateUser.ToString()) == false) { lstUsers.Add(objUpdateUser.ToString()); } } } #endregion String strTitle = DataConfigProvider.GetTableCaption(strTableName); String strDisplayCol = DataStructureProvider.GetDisplayColumn(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(); } foreach (String strUser in lstUsers) { if (strUser != ABCUserProvider.CurrentUserName) { CreateNewNotify(strUser, strTitle, "", strTableName, iID, ""); } } }
public static String GenerateNo(BusinessObject obj) { if (obj.GetID() == Guid.Empty) { obj.SetNoValue(String.Empty); return(String.Empty); } String strNoValue = String.Empty; Numbering numbering = GetNumberingConfig(obj); if (numbering != null) { if (!numbering.IsUsePattern) { #region Not UsePattern if (numbering.MiddleConfigs.Count > 0) { #region Have Parts List <String> lstParts = new List <string>(); foreach (NumberingType numberType in numbering.MiddleConfigs) { #region Others if (numberType.IsByUser) { } if (numberType.IsByUserGroup) { } if (numberType.IsByEmployee) { } if (numberType.IsByCompanyUnit) { } #endregion if ((numberType.IsYYMMCount || numberType.IsYYMMDDCount || numberType.IsMMDDCount)) { 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 (!String.IsNullOrWhiteSpace(strDateCol)) { object objValue = ABCDynamicInvoker.GetValue(obj, strDateCol); if (objValue != null && (objValue is DateTime || (objValue is Nullable <DateTime> && (objValue as Nullable <DateTime>).HasValue))) { #region With DateTime DateTime createTime = DateTime.MinValue; if (objValue is Nullable <DateTime> ) { createTime = (objValue as Nullable <DateTime>).Value; } else { createTime = Convert.ToDateTime(objValue); } if (numberType.IsYYMMCount) { String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false); strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND {0} < {3}", strDateCol, createTime.Year, createTime.Month, TimeProvider.GenDateTimeString(createTime))); int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery)); if (iCount <= 0) { iCount = 0; } iCount++; int iCountSpace = numberType.CountingSpace; if (iCountSpace < iCount.ToString().Length) { iCountSpace = iCount.ToString().Length + 2; } String strTemp = createTime.ToString("yyMM") + String.Format("{0:D" + iCountSpace + "}", iCount); lstParts.Add(strTemp); } if (numberType.IsYYMMDDCount) { String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false); strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND DAY({0}) = {3} AND {0} < {4}", strDateCol, createTime.Year, createTime.Month, createTime.Day, TimeProvider.GenDateTimeString(createTime))); int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery)); if (iCount <= 0) { iCount = 0; } iCount++; int iCountSpace = numberType.CountingSpace; if (iCountSpace < iCount.ToString().Length) { iCountSpace = iCount.ToString().Length + 2; } String strTemp = createTime.ToString("yyMMdd") + String.Format("{0:D" + iCountSpace + "}", iCount); lstParts.Add(strTemp); } if (numberType.IsMMDDCount) { String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false); strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND DAY({0}) = {3} AND {0} < {4}", strDateCol, createTime.Year, createTime.Month, createTime.Day, TimeProvider.GenDateTimeString(createTime))); int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery)); if (iCount <= 0) { iCount = 0; } iCount++; int iCountSpace = numberType.CountingSpace; if (iCountSpace < iCount.ToString().Length) { iCountSpace = iCount.ToString().Length + 2; } String strTemp = createTime.ToString("MMdd") + String.Format("{0:D" + iCountSpace + "}", iCount); lstParts.Add(strTemp); } #endregion } } } #region By Field if (numberType.IsByField && !String.IsNullOrWhiteSpace(numberType.FieldName)) { if (DataStructureProvider.IsTableColumn(obj.AATableName, numberType.FieldName)) { object objValue = ABCDynamicInvoker.GetValue(obj, numberType.FieldName); if (objValue != null) { if (DataStructureProvider.IsForeignKey(obj.AATableName, numberType.FieldName)) { String strFieldName = numberType.FieldName + ":" + DataStructureProvider.GetDisplayColumn(obj.AATableName); objValue = DataCachingProvider.GetCachingObjectAccrossTable(obj, ABCHelper.DataConverter.ConvertToGuid(objValue), strFieldName); } lstParts.Add(objValue.ToString()); } } } #endregion } strNoValue = numbering.Prefix + String.Join(numbering.SeperateChar, lstParts) + numbering.Suffix; #endregion } else { 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 (!String.IsNullOrWhiteSpace(strDateCol)) { object objValue = ABCDynamicInvoker.GetValue(obj, strDateCol); if (objValue != null && (objValue is DateTime || (objValue is Nullable <DateTime> && (objValue as Nullable <DateTime>).HasValue))) { #region With DateTime DateTime createTime = DateTime.MinValue; if (objValue is Nullable <DateTime> ) { createTime = (objValue as Nullable <DateTime>).Value; } else { createTime = Convert.ToDateTime(objValue); } String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false); strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND {0} < {3}", strDateCol, createTime.Year, createTime.Month, TimeProvider.GenDateTimeString(createTime))); int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery)); if (iCount <= 0) { iCount = 0; } iCount++; int iCountSpace = 3; if (iCountSpace < iCount.ToString().Length) { iCountSpace = iCount.ToString().Length + 2; } strNoValue = numbering.Prefix + createTime.ToString("yyMM") + String.Format("{0:D" + iCountSpace + "}", iCount) + numbering.Suffix; #endregion } } else if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colNoIndex)) { int iNoIndex = Convert.ToInt32(ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colNoIndex)); int iCountSpace = 4; if (iNoIndex >= 10000) { iCountSpace = iNoIndex.ToString().Length + 2; } strNoValue = numbering.Prefix + String.Format("{0:D" + iCountSpace + "}", iNoIndex) + numbering.Suffix; } } #endregion } else { #region UsePattern #endregion } } else { #region Have No Config if (!String.IsNullOrWhiteSpace(DataConfigProvider.TableConfigList[obj.AATableName].PrefixNo)) { strNoValue = DataConfigProvider.TableConfigList[obj.AATableName].PrefixNo; } else { strNoValue = new Regex("[^A-Z]+").Replace(DataConfigProvider.GetTableCaption(obj.AATableName), ""); } 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 (!String.IsNullOrWhiteSpace(strDateCol)) { object objValue = ABCDynamicInvoker.GetValue(obj, strDateCol); if (objValue != null && (objValue is DateTime || (objValue is Nullable <DateTime> && (objValue as Nullable <DateTime>).HasValue))) { #region With DateTime DateTime createTime = DateTime.MinValue; if (objValue is Nullable <DateTime> ) { createTime = (objValue as Nullable <DateTime>).Value; } else { createTime = Convert.ToDateTime(objValue); } String strQuery = QueryGenerator.GenSelect(obj.AATableName, "COUNT(*)", false, false); strQuery = QueryGenerator.AddCondition(strQuery, String.Format(@" YEAR({0}) = {1} AND MONTH({0}) = {2} AND {0} < {3}", strDateCol, createTime.Year, createTime.Month, TimeProvider.GenDateTimeString(createTime))); int iCount = Convert.ToInt32(BusinessObjectController.GetData(strQuery)); if (iCount <= 0) { iCount = 0; } iCount++; int iCountSpace = 3; if (iCountSpace < iCount.ToString().Length) { iCountSpace = iCount.ToString().Length + 2; } strNoValue += createTime.ToString("yyMM") + String.Format("{0:D" + iCountSpace + "}", iCount); #endregion } } else if (DataStructureProvider.IsTableColumn(obj.AATableName, ABCCommon.ABCConstString.colNoIndex)) { int iNoIndex = Convert.ToInt32(ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colNoIndex)); int iCountSpace = 4; if (iNoIndex >= 10000) { iCountSpace = iNoIndex.ToString().Length + 2; } strNoValue += String.Format("{0:D" + iCountSpace + "}", iNoIndex); } #endregion } obj.SetNoValue(strNoValue); return(strNoValue); }