У меня есть два столбца DueDat
и PaymentDate
из datagridview
.Я хочу, чтобы, если оплата была произведена либо before
или ON
, либо after
срок платежа, результат должен быть Paid
.Мне нужен следующий результат, когда при сравнении обоих столбцов даты
Сегодняшняя дата - 10-10-2018
InstallmentNo DueDate PaymentDate Status
-------------------------------------------------
1 08-11-2018 18-11-2018 Paid
2 08-12-2018 Up Coming
3 08-12-2018 Up Coming
4 08-12-2018 Up Coming
или
InstallmentNo DueDate PaymentDate Status
---------------------------------------------------
1 27-10-2018 Up Coming
2 08-12-2018 Up Coming
3 08-12-2018 Up Coming
4 08-12-2018 Up Coming
, но мой код выдает следующеерезультат:
InstallmentNo DueDate PaymentDate Status
-------------------------------------------------
1 08-11-2018 18-11-2018 Paid
2 08-12-2018 Pending
3 08-12-2018 Up Coming
4 08-12-2018 Up Coming
или
InstallmentNo DueDate PaymentDate Status
--------------------------------------------------
1 27-10-2018 Pending
2 08-12-2018 Pending
3 08-12-2018 Pending
4 08-12-2018 Pending
Вот мой мой код, который получает данные из textbox
для данных таблицы выше
private void txtSID_TextChanged(object sender, EventArgs e)
{
try
{
int isid;
string sid = "";
sid = txtSID.Text.ToString();
if (int.TryParse(sid, out isid)) ;
using (SqlConnection conn = new SqlConnection(connection))
{
string CmdString = " SELECT InsttNo,CONVERT(VARCHAR(10),DD,105) as DD,CONVERT(VARCHAR(10),PD,105) as PD from InstallmentPaymentHistory where SalesInvoiceID=" + isid + "";
SqlCommand cmd = new SqlCommand(CmdString, conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt1 = new DataTable("SalesInvoice");
sda.Fill(dt1);
dataGridView1.DataSource = dt1.DefaultView;
DateTime d1 = new DateTime();
DateTime d2 = new DateTime();
DateTime d3 = new DateTime(2011, 2, 19);
d3 = DateTime.Now;
string s = d3.ToString("dd-MM-yyyy");
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
var dueDate = dataGridView1.Rows[i].Cells["DueDate"].Value != null
? dataGridView1.Rows[i].Cells["DueDate"].Value.ToString()
: string.Empty;
var paymentDate = dataGridView1.Rows[i].Cells["PaymentDate"].Value != null
? dataGridView1.Rows[i].Cells["PaymentDate"].Value.ToString()
: string.Empty;
if (!DateTime.TryParse(dueDate, out d1) || !DateTime.TryParse(paymentDate, out d2)) ;
int a = DateTime.Compare(d1, d2);
int b = DateTime.Compare(d3, d1);
if ((a <= 0 || a >= 0) && paymentDate.ToString() != "")
dataGridView1.Rows[i].Cells["Status"].Value = "Paid";
else if (b <= 0)
dataGridView1.Rows[i].Cells["Status"].Value = "Up Coming";
else
dataGridView1.Rows[i].Cells["Status"].Value = "Pending";
}
}
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}
}