예제 #1
0
        /// <summary>
        /// <para>Validate the date/time items from the input ListItemCollection to have a correct format. The function
        /// returns boolean validation result (true - success, false - fail).</para>
        /// </summary>
        /// <param name="items">
        /// an instance of the ListItemCollection. It contains the date/time elements to be validated. Can not be null.
        /// Should not contain null elements. Can be empty collection. An empty string value is allowed for collection
        /// elements.
        /// </param>
        /// <returns>
        /// the result of validation. true value means the successful validation, false - validation failed.
        /// </returns>
        /// <exception cref="ArgumentNullException">If items is null.</exception>
        /// <exception cref="ArgumentException">If items has null elements</exception>
        public bool Validate(ListItemCollection items)
        {
            //Check for null
            Helper.ValidateNotNull(items, "items");

            //Validate
            return(ValidateUsingEnumerator(items.GetEnumerator(), "items"));
        }
예제 #2
0
        // TODO: Move to base library
        public static IEnumerable <ListItem> AsEnumerable(this ListItemCollection itemCollection)
        {
            var enumerator = itemCollection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                yield return((ListItem)enumerator.Current);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            ClientContext sourceCtx = new ClientContext(Properties.Resources.sourceWebUrl);
            ClientContext destCtx   = new ClientContext(Properties.Resources.destWebUrl);

            List sourceList = sourceCtx.Web.Lists.GetByTitle(Properties.Resources.sourceDocLibName);
            List destList   = destCtx.Web.Lists.GetByTitle(Properties.Resources.destDocLibName);

            View migratingItemsView = sourceList.Views.GetById(new Guid(Properties.Resources.sourceViewId));

            sourceCtx.Load(migratingItemsView);
            sourceCtx.ExecuteQuery();

            CamlQuery migratingItemsCaml = new CamlQuery();

            migratingItemsCaml.ViewXml = migratingItemsView.HtmlSchemaXml;

            ListItemCollection migratingItemsList = sourceList.GetItems(migratingItemsCaml);

            sourceCtx.Load(migratingItemsList);
            sourceCtx.ExecuteQuery();

            IEnumerator <ListItem> itemIter = migratingItemsList.GetEnumerator();

            while (itemIter.MoveNext())
            {
                ListItem itemToMigrate = itemIter.Current;
                if (itemToMigrate.FileSystemObjectType == FileSystemObjectType.Folder)
                {
                    string   libRelFolderUrl = GetNormalisedFileRef(itemToMigrate);
                    string   folderName      = itemToMigrate.FieldValues["FileLeafRef"] as string;
                    DateTime modifiedDate    = (DateTime)itemToMigrate.FieldValues["Modified"];
                    Console.WriteLine(modifiedDate + " Folder: " + libRelFolderUrl);
                    // Check if folder exists
                }
                else if (itemToMigrate.FileSystemObjectType == FileSystemObjectType.File)
                {
                    string   libRelFolderUrl = GetNormalisedFileRef(itemToMigrate);
                    string   fileName        = itemToMigrate.FieldValues["FileLeafRef"] as string;
                    int      fileNameIndex   = libRelFolderUrl.LastIndexOf(fileName);
                    string   sourceFolder    = libRelFolderUrl.Remove(fileNameIndex - 1, fileName.Length + 1);
                    string   author          = (itemToMigrate.FieldValues["Author"] as FieldUserValue).LookupValue;
                    string   modifier        = (itemToMigrate.FieldValues["Editor"] as FieldUserValue).LookupValue;
                    DateTime modified        = (DateTime)itemToMigrate.FieldValues["Modified"];
                    DateTime created         = (DateTime)itemToMigrate.FieldValues["Created"];

                    Console.WriteLine(modified + " \"" + fileName + "\" in \"" + sourceFolder + "\"");

                    // check if file already exists
                }
            }
            Console.ReadLine();
        }
예제 #4
0
    protected void AddNewSubIndicator(object sender, EventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("Add new");
        cleanItems();
        QueryManager qm = new QueryManager();

        try
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>
            {
                { "@ID", indCode.Text }
            };
            SqlDataReader reader = qm.executeReader("SELECT TOP 1 Subindicator_Code FROM Subindicator " +
                                                    "WHERE Indicator_Code IN (@ID) ORDER BY Subindicator_Code DESC; ", parameters);
            string newSubId = "";
            try
            {
                string subindicatorCode = "";
                while (reader.Read())
                {
                    subindicatorCode = Convert.ToString(reader["Subindicator_Code"]).Trim();
                }

                int intCode = 0;
                if (subindicatorCode != null && subindicatorCode.Trim().Length > 0)
                {
                    int.TryParse(subindicatorCode.Substring(subindicatorCode.LastIndexOf("_") + 1), out intCode);
                }

                intCode++;
                newSubId = ((intCode > 9) ? indCode.Text.Trim() + "_" + intCode : indCode.Text.Trim() + "_0" + intCode++);
                System.Diagnostics.Debug.WriteLine("New Subindicator_Code " + newSubId);
            }
            catch
            {
                refreshSubindicators(qm, 2);
            }
            finally
            {
                reader.Close();
                qm.closeConnection();
            }

            string             dimensions = "";
            ListItemCollection items      = newDimensions.Items;
            IEnumerator        it         = items.GetEnumerator();
            while (it.MoveNext())
            {
                ListItem li = (ListItem)it.Current;
                dimensions += li.Selected ? "1" : "0";
            }

            qm = new QueryManager();
            Dictionary <string, object> actionParam = new Dictionary <string, object>
            {
                { "@IND_CODE", indCode.Text },
                { "@SUB_CODE", newSubId },
                { "@SERIES", newSubSeries.Value },
                { "@UNIT_MEASURE", newUnitMeasure.SelectedValue },
                { "@UNIT_MULT", newUnitMultiplier.SelectedValue },
                { "@OBS_STATUS", newObsStatus.SelectedValue },
                { "@DESC_EN", newSubDescEN.Value },
                { "@DESC_AR", newSubDescAR.Value },
                { "@DIM", dimensions }
            };

            qm.executeNonQuery(
                "INSERT INTO" +
                " Subindicator " +
                "(SERIES, Subindicator_DescEn, Subindicator_DescAr, Indicator_Code, Subindicator_Code, Dimensions, UNIT_MEASURE, UNIT_MULT, OBS_STATUS)" +
                "VALUES (@SERIES, @DESC_EN, @DESC_AR, @IND_CODE, @SUB_CODE, @DIM, @UNIT_MEASURE, @UNIT_MULT, @OBS_STATUS)", actionParam);

            refreshSubindicators(qm, 1);
        }
        catch
        {
            refreshSubindicators(qm, 2);
        }
        finally
        {
            qm.closeConnection();
        }
    }