示例#1
0
 /// <summary>
 /// Create a Table Layout.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="htmlhelper"></param>
 /// <param name="viewModel">Model with List to Show and Properties to Show.</param>
 /// <param name="withEdit">A boolean type for create a Table with Edit button</param>
 /// <param name="htmlAttributes"></param>
 /// <returns></returns>
 public static MvcHtmlString TableListFor <TModel, T>(this HtmlHelper <TModel> htmlhelper,
                                                      ITableList <T> viewModel,
                                                      bool withEdit         = false,
                                                      object htmlAttributes = null) where T : class
 {
     return(TableListForHtmlExtention.TableListFor(htmlhelper, viewModel, withEdit, false, false, htmlAttributes));
 }
示例#2
0
 public When_A_PropertiesToShow_Is()
 {
     mockTableList = new Mock <ITableList <Usuario> >();
     tableList     = mockTableList.Object;
 }
示例#3
0
        public void Copy(string provider1, string server1, string catalog1, string login1, string cred1, string provider2, string server2, string catalog2, string login2, string cred2, string table_cue_after, string single_table, bool no_utc)
        {
            string bintablename = new doc02Binary().TableName.ToLower();
            /* 0. define exclusions */
            var exclusions = new List <string>()
            {
                new sys02Installation().TableName,
                new doc02FT().TableName, /* [dlatikay 20110920] now the table name will resolve properly, was before: "doc02FT"; -!- until better solution, currently not included in schema! */
                new doc02Binary().TableName,
                new doc02BinaryL().TableName,
                new log02OrgSync().TableName,
                new log02OrgSyncItem().TableName,
                new msg02EventA().TableName,
                new nav02PickupStorage().TableName, /* it fails with a strange error in the RAW field (SessionID). we just omit it as it is transient and therefore not needed in systemcopy anyway */
                new nav02Menu().TableName,          /* [dlatikay 20101012] added */
                new nav02MenuL().TableName,         /* [dlatikay 20101012] added */
                new nav02MenuLocation().TableName,  /* [dlatikay 20151002] added */
                new nav02MenuLocationL().TableName, /* [dlatikay 20151002] added */
                new per02TaskA().TableName,
                new rpt02Link().TableName,
                new rpt02LinkL().TableName,
                new rpt02Destination().TableName, /* [dlatikay 20101012] added */
                new sys02Computer().TableName,
                new sys02GroupAccount().TableName,
                new sys02JobA().TableName,
                new sys02Useraccount().TableName,
                new tpi02CredentialStore().TableName,
                new tpi02FunclocImp().TableName,
                new tpi02HRImpAcceptor().TableName
            };

            /* except the single table from the exception */
            if (!String.IsNullOrWhiteSpace(single_table))
            {
                string exex = exclusions.Find((x) => { return(x.ToLower().Equals(single_table.ToLower())); }); /* [dlatikay 20090824] for genuine case insensitivity */
                if (!String.IsNullOrWhiteSpace(exex))
                {
                    exclusions.Remove(exex);
                }
            }
            /* 1. open both connections */
            ddl db1 = new ddlfactory((DbProvider)Enum.Parse(typeof(DbProvider), provider1)).Generate;
            ddl db2 = new ddlfactory((DbProvider)Enum.Parse(typeof(DbProvider), provider2)).Generate;

            try
            {
                db1.Connect(server1, catalog1, login1, cred1, null, no_utc);
                db2.Connect(server2, catalog2, login2, cred2, null, no_utc);
                /* 2. enumerate the tables in source and target */
                List <string> tables1 = db1.ListAllTables();
                List <string> tables2 = db2.ListAllTables();

                /* 3. for each table in the source, attempt to truncate
                 * the table in the destination and re-fill it using bulk insert
                 * approach */
                /* 3a. for each table */
                bool     keep_skipping           = (table_cue_after != null && table_cue_after.Length > 0) || (single_table != null && single_table.Length > 0);
                bool     stop_after_single_table = false;
                Assembly assy = Assembly.GetExecutingAssembly();
                foreach (string table in tables1)
                {
                    string tablename = table.ToLower();
                    if (single_table == null || single_table.Length <= 0)
                    {
                        log(864, tablename); /* Transferring table \"{0}\"... */
                    }
                    if (keep_skipping)
                    {
                        if (table_cue_after != null && table_cue_after.Length > 0)
                        {
                            log(1173, table_cue_after); /* --> skipped, precedes continuation point "{0}" */
                            keep_skipping = tablename != table_cue_after.ToLower();
                        }
                        else if (single_table != null && single_table.Length > 0)
                        {
                            keep_skipping = (!single_table.ToLower().Equals(tablename));
                            if (!keep_skipping)
                            {
                                log(864, tablename); /* Transferring table \"{0}\"... */
                                stop_after_single_table = true;
                            }
                        }
                    }
                    /* take this one? */
                    if (!keep_skipping)
                    {
                        /* must not be in the exclusion list. if the single table is in the exclusion list, we excluded it from the exclusion list already :) */
                        if (!exclusions.Exists(delegate(string x) { return(x.ToLower().Equals(tablename)); }))
                        {
                            /* must exist in source and target (otherwise installations do not match in schema version probably) */
                            if (tables2.Exists(delegate(string x) { return(x.ToLower().Equals(tablename)); }))
                            {
                                //if (tablename.StartsWith(bintablename))
                                //    /* the "doc02Binary" table gets special treatment because it contains huge binary chunks. so does the doc02BinaryL. */
                                //    CopyBinRowwise(db1, db2, tablename);
                                //else
                                //{
                                /* got the singular, need the plural */
                                TableDef   element = (TableDef)assy.CreateInstance("dal.schema." + tablename, true);
                                string     plural  = db1.ObtainPlural(assy, tablename);
                                ITableList list    = (ITableList)assy.CreateInstance("dal.schema." + plural, true);
                                /* generic-dynamically invoke the dbselectall statement on the source */
                                GenericInvoker invoker = clsDynamicGenerics.GenericMethodInvokerMethod(
                                    element.GetType(),
                                    "DbSelectAll",
                                    new Type[] { list.GetType(), element.GetType() },
                                    new Type[] { typeof(ddl) }
                                    );
                                list = invoker(element, db1) as ITableList;
                                /* truncate the target */
                                element.DbTruncate(db2);
                                if (list.Rowcount > 0)
                                {
                                    log(1157, list.Rowcount.ToString()); /* --> number of records to be transferred: {0} */
                                    /* now for the dbinsertall statement on the target - who's able to fully understand this, must be drugged */
                                    try
                                    {
                                        element.InsertAllGeneric(db2, list);
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new DALException(String.Format("Failed to copy table \"{0}\".", element.TableName), ex);
                                    }
                                    log(870, list.Rowcount.ToString()); /* --> number of records transferred: {0} */
                                }
                                else
                                {
                                    log(869); /* --> deletion only, no data in source table */
                                }
                            }
                            else
                            {
                                /* table does not exist in destination */
                                log(866); /* --> skipped because not existing in target database. */
                            }
                        }
                        else
                        {
                            /* table skipped because of exclusion rule */
                            log(865); /* --> skipped because in exclusion list. */
                        }
                    }
                    /* if we wanted only a single table we might now abort */
                    if (stop_after_single_table)
                    {
                        break;
                    }
                }
                /* succeeded */
            }
            finally
            {
                /* cleanup */
                if (db2 != null)
                {
                    db2.Disconnect();
                }
                if (db1 != null)
                {
                    db1.Disconnect();
                }
            }
        }
 public When_A_PropertiesToShow_Is()
 {
     mockTableList = new Mock<ITableList<Usuario>>();
     tableList = mockTableList.Object;
 }
示例#5
0
        /// <summary>
        /// Create a Table Layout.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="htmlhelper"></param>
        /// <param name="viewModel">Model with List to Show and Properties to Show.</param>
        /// <param name="withEdit">A boolean type for create a Table with Edit button</param>
        /// <param name="withRemove">A boolean type for create a Table with Remove button</param>
        /// <param name="withDetail">A boolean type for create a Table with Detail button</param>
        /// <param name="htmlAttributes"></param>
        /// <returns></returns>
        public static MvcHtmlString TableListFor <TModel, TEntity>(this HtmlHelper <TModel> htmlhelper,
                                                                   ITableList <TEntity> viewModel,
                                                                   bool withEdit         = false,
                                                                   bool withRemove       = false,
                                                                   bool withDetail       = false,
                                                                   object htmlAttributes = null) where TEntity : class
        {
            TagBuilder table = new TagBuilder("table");

            table.AddCssClass("table table-bordered table-hover table-responsive");

            TagBuilder tr = new TagBuilder("tr");

            foreach (var propertyToShow in viewModel.PropertiesToShow)
            {
                TagBuilder th = new TagBuilder("th");

                th.MergeAttribute("style", "cursor: default; ");

                th.InnerHtml = propertyToShow.DisplayProperty != null ? propertyToShow.DisplayProperty : propertyToShow.PropertyName;

                tr.InnerHtml += th.ToString();
            }

            if (withEdit)
            {
                tr.InnerHtml += HtmlExtentionsCommon.CreateTagBuilder("th", "Editar", new { style = "width: 5%; cursor: default;" }).ToString();
            }

            if (withDetail)
            {
                tr.InnerHtml += HtmlExtentionsCommon.CreateTagBuilder("th", "Detalhes", new { style = "width: 5%; cursor: default" }).ToString();
            }

            if (withRemove)
            {
                tr.InnerHtml += HtmlExtentionsCommon.CreateTagBuilder("th", "Remover", new { style = "width: 5%; cursor: default" }).ToString();
            }

            TagBuilder tHead = HtmlExtentionsCommon.CreateTagBuilder("thead", tr.ToString());


            TagBuilder tbody = new TagBuilder("tbody");

            foreach (var item in viewModel.List)
            {
                TagBuilder trItem = new TagBuilder("tr");
                var        propertiesFromTheItem = item.GetType().GetProperties();

                foreach (var property in propertiesFromTheItem)
                {
                    PropertyToShow showThisProperty = HtmlExtentionsCommon.ShowThisProperty(property, viewModel.PropertiesToShow, item);


                    if (showThisProperty != null)
                    {
                        string display = showThisProperty.DisplayProperty != null ? showThisProperty.DisplayProperty : showThisProperty.PropertyName;

                        TagBuilder td = new TagBuilder("td");
                        td.InnerHtml = item.GetType().GetProperty(property.Name).GetValue(item).ToString();
                        td.MergeAttribute("style", "padding-top: 15px");
                        trItem.InnerHtml += td.ToString();
                    }
                }

                if (withEdit)
                {
                    var button = HtmlExtentionsCommon.CreateTagBuilder("td",
                                                                       ButtonHtmlExtention.Button(
                                                                           htmlhelper, string.Empty,
                                                                           "btn-info col-lg-12",
                                                                           "glyphicon glyphicon-edit",
                                                                           string.Empty,
                                                                           HtmlButtonTypes.Button,
                                                                           new { data_action = "editar", data_actionId = item.GetType().GetProperty("Id").GetValue(item).ToString(), title = "Editar" }
                                                                           ).ToString());

                    trItem.InnerHtml += button.ToString();
                }

                if (withDetail)
                {
                    var button = HtmlExtentionsCommon.CreateTagBuilder("td",
                                                                       ButtonHtmlExtention.Button(
                                                                           htmlhelper, string.Empty,
                                                                           "btn-success col-lg-10 col-lg-offset-1",
                                                                           "glyphicon glyphicon-search",
                                                                           string.Empty,
                                                                           HtmlButtonTypes.Button,
                                                                           new { data_action = "editar", data_actionId = item.GetType().GetProperty("Id").GetValue(item).ToString(), title = "Detalhe" }
                                                                           ).ToString());
                    trItem.InnerHtml += button.ToString();
                }

                if (withRemove)
                {
                    var button = HtmlExtentionsCommon.CreateTagBuilder("td",
                                                                       ButtonHtmlExtention.Button(
                                                                           htmlhelper, string.Empty,
                                                                           "btn-danger col-lg-10 col-lg-offset-1",
                                                                           "glyphicon glyphicon-trash",
                                                                           string.Empty,
                                                                           HtmlButtonTypes.Button,
                                                                           new { data_action = "remover", data_actionId = item.GetType().GetProperty("Id").GetValue(item).ToString(), title = "Remover" }
                                                                           ).ToString());
                    trItem.InnerHtml += button.ToString();
                }

                tbody.InnerHtml += trItem.ToString();
            }
            table.InnerHtml  = tHead.ToString();
            table.InnerHtml += tbody.ToString();

            if (htmlAttributes != null)
            {
                var anonymousObject = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

                if (anonymousObject.Select(x => x.Value.ToString().Contains("margin")).FirstOrDefault())
                {
                    table.MergeAttributes(anonymousObject);
                }
                else
                {
                    anonymousObject.Add("style", "margin: 10px 0px");
                }
            }
            else if (htmlAttributes != null)
            {
                table.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(new { style = "margin: 10px 0px; form-group" }));
            }

            return(MvcHtmlString.Create(table.ToString()));
        }
示例#6
0
 public When_A_List_T_Is()
 {
     mockTableList = new Mock <ITableList <Usuario> >();
     tableList     = mockTableList.Object;
 }