I want to update some changes in one list from another. The second list should have details of first list.
First list has got elements:
Contract | Worker | Day Start | Day Stop | Percent
--------------------------------------------------------
Example Con1 | Paul | 2012-10-12 | 2012-10-15 | 1/8
Secound List should have
Contract | Worker | Day | Percent
------------------------------------------------
Should Have Con 1 | Paul | 2012-10-12 | 1/8
Con 1 | Paul | 2012-10-13 | 1/8
Con 1 | Paul | 2012-10-14 | 1/8
Con 1 | Paul | 2012-10-15 | 1/8
With name, and Surname
So In this example I want to get from one list and one data record, and update 4 records with for 4 days in the second list.
I have writen a code, but it always copies elements, and only I want to update when another element is added:
protected void Button1_Click(object sender, EventArgs e)
{
SPWeb witryna = SPContext.Current.Web;
SPListItemCollection czasPracyWpisy = witryna.Lists["DR2013 Czas Pracy Wpisy"].Items;
SPListItemCollection czasPracySzczegoly= witryna.Lists["DR2013 Czas Pracy Szczegóły"].Items;
int index;
string hfzm1, hfzm2;
foreach (SPListItem oCzasPracyKolejnyWpis in czasPracyWpisy)
{
foreach(SPListItem oCzasPracyKolejnySzczegoly in czasPracySzczegoly){
Label1.Text = oCzasPracyKolejnyWpis["Numer Kontraktu/Oferty/Szansy"].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;
}
if (
(HFzm2.Value != HFzm1.Value && HFzm1.Value ==HFzm2.Value || HFzm1.Value=="" || HFzm2.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";
}
}
}
}}