چیزی که من با کد خودم یعنی این کد ایجاد کردم.
try
{
DataTable dt = new DataTable();
Database db = new Database();
string Vaziat = "";
int MandeHesab = 0;
dt = db.MySelect("SELECT Id_Kalaei, Kod_Moshtari, Name_Moshtari, Sharh, Tedad, Takhfif, PriceVahed, PasAzTakhfif, Bedehkar, Bostankar, '" + Vaziat + "', '" + MandeHesab + "', Tarikh FROM tbl_Kalaei");
dataGridView1.DataSource = dt;
dataGridView1.Rows.Cast<DataGridViewRow>().Where(c 2 => !c2.Cells[3].Value.ToString().StartsWith("کالای"))
.Where(c3 => !c3.Cells[3].Value.ToString().StartsWith("تخفیف"))
.All(c =>
{
MandeHesab = Convert.ToInt32(c.Cells[11].Value.ToString());
if (MandeHesab > 0) Vaziat = "بدهکار";
if (MandeHesab < 0) Vaziat = "بستانکار";
if (MandeHesab == 0) Vaziat = "تسویه";
c.Cells[10].Value = Vaziat;
c.Cells[11].Value = dataGridView1.Rows.Cast<DataGridViewRow>()
.Where(c1 => c1.Index < c.Index)
.Where(c1 => !c1.Cells[3].Value.ToString().StartsWith("کالای"))
.Select(c1 => int.Parse(c1.Cells[8].Value.ToString()) -
int.Parse(c1.Cells[9].Value.ToString())).Sum() +
int.Parse(c.Cells[8].Value.ToString()) - int.Parse(c.Cells[9].Value.ToString());
return true;
} );
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
نتیجش این شده:
Me.PNG
چیزی که من در اصل میخوام اینطور باید باشه:
Me - Copy.PNG
ممنون