Linq.Tables (dc.GTMD_Financials) öğesinden UserControl'e veri ekleyen biraz kod oluşturdum. Veritabanındaki her giriş için yeni bir usercontrol gösterir.Çoklu Linq.Yol yönteminde kullanılabilenler
Ancak bu kodu, uygulama boyunca yeniden kullanmak için bir yöntemde kullanmak istiyorum. Benim sorunum her zaman ben veritabanından farklı bir tablo kullanmak istiyorum yöntem (bu nedenle GTMD_Financials değişir)
Ben bunu anlamaya ve herhangi bir yardım veya örnek gerçekten takdir ediyorum.
int locationControl = 78;
DataClasses1DataContext dc = new DataClasses1DataContext();
dc.GTMD_Financials.ToList().ForEach(x =>
{
KPIEntrys uc = new KPIEntrys(); // UserControl
uc.KPI = x.KPI; // Add data to properties
uc.Status = x.Status.ToString();
uc.Goal = x.Goal.ToString();
uc.Currently = x.Currently.ToString();
bool checkaction = x.ShowAction == true ? uc.ShowAction = true : uc.ShowAction = false;
bool checkstats = x.ShowStats == true ? uc.ShowStats = true : uc.ShowStats = false;
bool checkstatus = x.Status < x.StatusSignal ? uc.StatusGood = true : uc.StatusGood = false;
uc.Location = new Point(21, locationControl);
this.Controls.Add(uc); // Add Control to Form
locationControl = locationControl + 34;
}
);
Bazı şeyler açık değilse lütfen bildirin. Yardımlarınız için şimdiden teşekkür ederiz.
DÜZENLEME: Ben zaten var yardımıyla çalışma almak gibi olamaz
.
int locationControl = 78;
DataClasses1DataContext dc = new DataClasses1DataContext();
public List<Control> LoadKPIs(Table<GTMD_Financial> dbTable)
{
var controls = new List<Control>();
dbTable.ToList().ForEach(x =>
{
KPIEntrys uc = new KPIEntrys();
uc.KPI = x.KPI;
uc.Status = x.Status.ToString();
uc.Goal = x.Goal.ToString();
uc.Currently = x.Currently.ToString();
uc.ShowAction = (bool)x.ShowAction;
uc.ShowStats = (bool)x.ShowStats;
uc.StatusGood = x.Status < x.StatusSignal;
uc.Location = new Point(21, locationControl);
controls.Add(uc);
locationControl = locationControl + 34;
}
);
return controls;
}
yüzden bana sorumu rephrase: i yöntemini çağırdığınızda ı sınıfı değiştirebilir nasıl LoadKPIs (Tablo < Ben zaten var Replys yardımıyla biraz yöntemini düzenlemek başardı GTMD_Financial> DBTable? Yani GTMD_Finacial değişir.
? Yeniden kullanabileceğiniz parçalar ve yeniden kullanamayacağınız parçalar olacak. Yeniden kullanılabilir bir yöntem oluşturmak istiyorsanız bunun çok açık olması gerekir; aslında ne yapıyor? – Maarten
"dc.GTMD_Financials" değişen tek şeydir. Bir dahaki sefere ben "dc.GTMD_Organisation" (ya da başka bir) – Marcel
kullanmak istiyorum sadece ihtiyacınız olan şey, dc.GTMD_Financials –