Exemplo n.º 1
0
        public static String GenerateNo(String strTableName, Guid ID)
        {
            BusinessObjectController ctrl = BusinessControllerFactory.GetBusinessController(strTableName);

            if (ctrl != null)
            {
                return(GenerateNo(ctrl.GetObjectByID(ID)));
            }
            return(String.Empty);
        }
Exemplo n.º 2
0
        public void RunLink(String strTableName, ViewMode mode, bool isShowDialog, Guid iMainID, ABCScreenAction action)
        {
            STViewsInfo       viewResult = null;
            STViewsController viewCtrl   = new STViewsController();

            String strViewNo = VoucherProvider.GetViewNo(strTableName, iMainID);

            if (!String.IsNullOrWhiteSpace(strViewNo))
            {
                viewResult = viewCtrl.GetObjectByNo(strViewNo) as STViewsInfo;
            }
            if (viewResult == null)
            {
                #region Without Voucher
                BusinessObjectController controller = BusinessControllerFactory.GetBusinessController(strTableName);
                if (controller == null)
                {
                    return;
                }

                BusinessObject obj = controller.GetObjectByID(iMainID);
                if (obj == null)
                {
                    return;
                }


                List <BusinessObject> lstViews = viewCtrl.GetListFromDataset(viewCtrl.GetDataSet(String.Format("SELECT * FROM STViews WHERE [MainTableName] = '{0}' ", strTableName)));
                foreach (STViewsInfo viewIfo in lstViews)
                {
                    if (String.IsNullOrWhiteSpace(viewIfo.MainFieldName) == false && DataStructureProvider.IsTableColumn(strTableName, viewIfo.MainFieldName))
                    {
                        object objValue = ABCBusinessEntities.ABCDynamicInvoker.GetValue(obj, viewIfo.MainFieldName);
                        if (objValue != null && objValue.ToString().ToUpper().Trim() == viewIfo.MainValue.ToUpper())
                        {
                            viewResult = viewIfo;
                            break;
                        }
                    }
                }

                if (viewResult == null && lstViews.Count > 0)
                {
                    viewResult = lstViews[0] as STViewsInfo;
                }

                #endregion
            }

            if (viewResult != null)
            {
                ABCScreenManager.Instance.RunLink(viewResult, mode, isShowDialog, iMainID, action);
            }
        }
Exemplo n.º 3
0
        public virtual bool ReCalculate(String strTableName, Guid ID, bool isSave)
        {
            BusinessObjectController ctrl = BusinessControllerFactory.GetBusinessController(strTableName);

            if (ctrl == null)
            {
                return(false);
            }

            return(ReCalculate(ctrl.GetObjectByID(ID), isSave));
        }
Exemplo n.º 4
0
        public void RefreshData(Boolean includeParent, Boolean includeChildren, Boolean defaultOnly)
        {
            #region Current Node
            if (InnerData != null)
            {
                BusinessObjectController ctrller = BusinessControllerFactory.GetBusinessController(InnerData.AATableName);
                String strPK = DataStructureProvider.GetPrimaryKeyColumn(InnerData.AATableName);
                Guid   iID   = ABCHelper.DataConverter.ConvertToGuid(ABCBusinessEntities.ABCDynamicInvoker.GetValue(InnerData, strPK));
                InnerData = ctrller.GetObjectByID(iID);
                if (InnerData == null)
                {
                    if (this.ParentNode != null)
                    {
                        this.ParentNode.ChildrenNodes.Remove(iID);
                        this.ParentNode = null;
                    }
                    Dictionary <Guid, ABCTreeListNode> innerList = null;
                    if (this.Manager.DataList.TryGetValue(this.ObjectName, out innerList))
                    {
                        if (innerList.ContainsKey(iID))
                        {
                            innerList.Remove(iID);
                        }
                    }
                }
            }
            #endregion

            List <ABCTreeListNode> lstTemps = new List <ABCTreeListNode>();
            foreach (ABCTreeListNode childNode in this.ChildrenNodes.Values)
            {
                lstTemps.Add(childNode);
            }

            if (includeChildren)
            {
                foreach (ABCTreeListNode childNode in lstTemps)
                {
                    childNode.RefreshData(false, includeChildren, defaultOnly);
                }
            }
            if (includeParent && this.ParentNode != null)
            {
                this.ParentNode.RefreshData(true, false, defaultOnly);
            }

            ExpandData(includeChildren, defaultOnly);
        }
Exemplo n.º 5
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.º 6
0
        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);
        }