Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Copping a Two Lists all time updated, and with no duplicates

$
0
0

Hellow i have a problem to copy two list one to anothere, but when is adding a new element's to the first list, another should be updated, and remove all duplicates. I made a Code, but all time it's putting me two duplicates when i have got two entrys to first column, from where I copied:

Please help me.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;

namespace wpisy_szczegoly.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            using (SPWeb witryna = SPContext.Current.Web){
            SPListItemCollection czasPracyWpisy = witryna.Lists["DR2013 Czas Pracy Wpisy"].Items;
            
                SPListItemCollection czasPracySzczegoly = witryna.Lists["DR2013 Czas Pracy Szczegóły"].Items;



                //czasPracySzczegoly.Count.ToString();

                //for (int i = 1927; i < 1947; i++)
                //{
                //    czasPracySzczegoly.DeleteItemById(i);
                //}

                int index;
                string hfzm1, hfzm2;


                foreach (SPListItem oCzasPracyKolejnyWpis in czasPracyWpisy)
                {
                    foreach (SPListItem oCzasPracyKolejnySzczegoly in czasPracySzczegoly)
                    {

                        Label1.Text = czasPracySzczegoly.Count.ToString();
                        Label2.Text = oCzasPracyKolejnyWpis["Pracownik"].ToString();
                        Label3.Text = oCzasPracyKolejnyWpis["Dzień Start"].ToString();
                        Label4.Text = oCzasPracyKolejnyWpis["Dzień Stop"].ToString();
                        index = oCzasPracyKolejnyWpis["Procent"].ToString().IndexOf("#");
                        Label5.Text = oCzasPracyKolejnyWpis["Procent"].ToString().Substring(index + 1);

                        // Dodawanie poszczególnych elementów

                        hfzm1 = oCzasPracyKolejnySzczegoly["Numer Kontraktu/Oferty/Szansy"].ToString();
                        HFzm1.Value = hfzm1;
                        hfzm2 = oCzasPracyKolejnyWpis["Numer Kontraktu/Oferty/Szansy"].ToString();
                        HFzm2.Value = hfzm2;

                        //dataStart= Convert.ToDateTime(oCzasPracyKolejnyWpis["Dzień Start"]).DayOfYear.ToString();
                        //Convert.ToInt32(dataStart);
                        //dataStop= Convert.ToDateTime(oCzasPracyKolejnyWpis["Dzień Stop"]).DayOfYear.ToString();
                        //Convert.ToInt32(dataStop);

                        // Dodawanie poszczególnych elementów

                        // (oCzasPracyKolejnyWpis["Dzień Start"].ToString() != oCzasPracyKolejnySzczegoly["Dzień"].ToString())||
                        //Convert.ToInt32(dataStart) >= Convert.ToInt32(dataStop)
                    }

                    if (
        (HFzm2.Value != HFzm1.Value))
                    {
                        SPListItem item = czasPracySzczegoly.Add();



                        item["Numer Kontraktu/Oferty/Szansy"] = oCzasPracyKolejnyWpis["Numer Kontraktu/Oferty/Szansy"].ToString();
                        item["Pracownik"] = oCzasPracyKolejnyWpis["Pracownik"].ToString();
                        item["Dzień"] = oCzasPracyKolejnyWpis["Dzień Start"].ToString();
                        index = oCzasPracyKolejnyWpis["Procent"].ToString().IndexOf("#");
                        item["Procent"] = oCzasPracyKolejnyWpis["Procent"].ToString().Substring(index + 1);
                        item.Update();
                    }
                    else
                    {
                        Label6.Text = "Mamy do czynienia ze zduplikowanymi wartościami";
                    }
                }
            }

        } // koniec bottom click

    }
}


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>