Ejemplo n.º 1
0
        public static void CopyObject(BusinessObject objFromObjectsInfo, BusinessObject objToObjectsInfo)
        {
            VinaDbUtil dbUtil = new VinaDbUtil();
            String     strToObjectTableName   = VinaUtil.GetTableNameFromBusinessObject(objToObjectsInfo);
            String     strFromObjectTableName = VinaUtil.GetTableNameFromBusinessObject(objFromObjectsInfo);

            if (objFromObjectsInfo.GetType().Name.Contains("ForView"))
            {
                strFromObjectTableName = objFromObjectsInfo.GetType().Name.Replace("ForView", "");
            }
            PropertyInfo[] properties = objToObjectsInfo.GetType().GetProperties();
            string         toObjectTablePrimaryKey = dbUtil.GetTablePrimaryColumn(strToObjectTableName);

            foreach (PropertyInfo prop in properties)
            {
                if (prop.Name != toObjectTablePrimaryKey && prop.Name != "IsTransferred" && !prop.Name.Contains("TransferredDate"))
                {
                    String strFromObjectPropertyName = string.Empty;
                    if (prop.Name.StartsWith(strToObjectTableName.Substring(0, strToObjectTableName.Length - 1)))
                    {
                        strFromObjectPropertyName = strFromObjectTableName.Substring(0, strFromObjectTableName.Length - 1) + prop.Name.Substring(strToObjectTableName.Length - 1);
                    }
                    PropertyInfo propFromObjectProperty = objFromObjectsInfo.GetType().GetProperty(strFromObjectPropertyName);
                    if (propFromObjectProperty != null)
                    {
                        object objValue = propFromObjectProperty.GetValue(objFromObjectsInfo, null);
                        prop.SetValue(objToObjectsInfo, objValue, null);
                    }
                    else
                    {
                        strFromObjectPropertyName = strFromObjectTableName.Substring(0, 2) + prop.Name.Substring(2);
                        propFromObjectProperty    = objFromObjectsInfo.GetType().GetProperty(strFromObjectPropertyName);
                        if (propFromObjectProperty != null)
                        {
                            object objValue = propFromObjectProperty.GetValue(objFromObjectsInfo, null);
                            prop.SetValue(objToObjectsInfo, objValue, null);
                        }
                        else
                        {
                            propFromObjectProperty = objFromObjectsInfo.GetType().GetProperty(prop.Name);
                            if (propFromObjectProperty != null)
                            {
                                object objValue = propFromObjectProperty.GetValue(objFromObjectsInfo, null);
                                prop.SetValue(objToObjectsInfo, objValue, null);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public static string GetBusinessControllerNameFromBusinessObject(BusinessObject objInfo)
 {
     return(VinaUtil.GetTableNameFromBusinessObject(objInfo) + "Controller");
 }