Ejemplo n.º 1
0
 public bool IsValidForeignKeyProperty(String strForeignKeyColumn)
 {
     try
     {
         VinaDbUtil dbUtil = new VinaDbUtil();
         //String strMainObjectTableName = MainObject.GetType().Name.Substring(0, MainObject.GetType().Name.Length - 4);
         String strMainObjectTableName = VinaUtil.GetTableNameFromBusinessObject(MainObject);
         String strPrimaryTable        = ((IBaseModuleERP)Module).GetTreePrimaryTableWhichForeignColumnReferenceTo(strMainObjectTableName, strForeignKeyColumn);
         String strPrimaryColumn       = ((IBaseModuleERP)Module).GetTreePrimaryTableWhichForeignColumnReferenceTo(strMainObjectTableName, strForeignKeyColumn);
         BaseBusinessController objPrimaryTableObjectController = BusinessControllerFactory.GetBusinessController(strPrimaryTable + "Controller");
         int iForeignKeyColumnValue = Convert.ToInt32(dbUtil.GetPropertyValue(MainObject, strForeignKeyColumn));
         if (iForeignKeyColumnValue > 0)
         {
             return(objPrimaryTableObjectController.IsExist(iForeignKeyColumnValue));
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
        protected virtual bool IsValidObjectNo(string objectNo)
        {
            VinaDbUtil             dbUtil = new VinaDbUtil();
            BaseBusinessController objCurrentObjectController = BusinessControllerFactory.GetBusinessController(CurrentModuleEntity.MainObject.GetType().Name.Substring(0, CurrentModuleEntity.MainObject.GetType().Name.Length - 4) + "Controller");
            String mainTable = VinaUtil.GetTableNameFromBusinessObject(CurrentModuleEntity.MainObject);
            String mainTablePrimaryColumn = dbUtil.GetTablePrimaryColumn(mainTable);
            bool   isValid = true;

            if (!String.IsNullOrEmpty(objectNo))
            {
                if (this.Toolbar.ModuleAction == BaseToolbar.ModuleNew)
                {
                    if (objCurrentObjectController.IsExist(objectNo))
                    {
                        MessageBox.Show("Mã đã tồn tại trong hệ thống vui lòng nhập mã khác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        isValid = false;
                    }
                }
                else if (this.Toolbar.ModuleAction == BaseToolbar.ModuleEdit)
                {
                    BusinessObject objMainObject = (BusinessObject)objCurrentObjectController.GetObjectByNo(objectNo);
                    if (objMainObject != null)
                    {
                        int iMainObjectID = Convert.ToInt32(dbUtil.GetPropertyValue(objMainObject, mainTablePrimaryColumn));
                        if (iMainObjectID != Toolbar.CurrentObjectID)
                        {
                            MessageBox.Show("Mã đã tồn tại trong hệ thống vui lòng nhập mã khác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            isValid = false;
                        }
                    }
                }
            }
            return(isValid);
        }
Ejemplo n.º 3
0
        public virtual String GetMainObjectNo(ref int numberingStart)
        {
            String strMainObjectNo = String.Empty;
            GENumberingsController objGENumberingController = new GENumberingsController();
            GENumberingsInfo       objGENumberingInfo       = (GENumberingsInfo)objGENumberingController.GetObjectByName(Module.CurrentModuleName);

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

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

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

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

                        strMainObjectNo = string.Join(".", subMainObjectNoList.ToArray());
                        numberingStart  = objGENumberingInfo.GENumberingNumber;
                    }
                }
            }
            return(strMainObjectNo);
        }