private void button3_Click(object sender, EventArgs e) { if (Validation()) { if (update_flag == 0) { String message = ""; int c1f = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[1].Value.ToString().Equals("")) { c1f = 1; if (message.Equals("")) { message = message + "Enter Address For Supplier No. : " + (i + 1); } else { message = message + "\nEnter Address For Supplier No. : " + (i + 1); } } if (dataGridView1.Rows[i].Cells[2].Value.ToString().Equals("")) { c1f = 1; if (message.Equals("")) { message = message + "Enter Qoutation Amount For Supplier No. : " + (i + 1); } else { message = message + "\nEnter Qoutation Amount For Supplier No. : " + (i + 1); } } else { try { Decimal k = Convert.ToDecimal(dataGridView1.Rows[i].Cells[2].Value.ToString()); } catch (FormatException ex) { c1f = 1; if (message.Equals("")) { message = message + "Enter Correct Qoutation Amount For Supplier No. : " + (i + 1); } else { message = message + "\nEnter Correct Qoutation Amount For Supplier No. : " + (i + 1); } } } } for (int i = 0; i < DGV_traffic_exception.Rows.Count; i++) { if (DGV_traffic_exception.Rows[i].Cells[0].Value.ToString().Equals("")) { c1f = 1; if (message.Equals("")) { message = message + "Enter Description For Traffic Exception No. : " + (i + 1); } else { message = message + "\nEnter Description For Traffic Exception No. : " + (i + 1); } } if (DGV_traffic_exception.Rows[i].Cells[1].Value.ToString().Equals("")) { c1f = 1; if (message.Equals("")) { message = message + "Enter Expiry Date For Traffic Exception No. : " + (i + 1); } else { message = message + "\nEnter Expiry Date For Traffic Exception No. : " + (i + 1); } } } if (c1f == 0) { try { for (int i = 0; i < dataGridView1.Rows.Count; i++) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[qoutation]([supplier],[quotation amount],[vehicle no.]) VALUES ('" + dataGridView1.Rows[i].Cells[1].Value.ToString() + "'," + dataGridView1.Rows[i].Cells[2].Value.ToString() + " ,'" + tno.Text + "')"); } String n = ""; if (DGV_traffic_exception.Rows.Count != 0) { for (int i = 0; i < DGV_traffic_exception.Rows.Count; i++) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[traffic exception]([traffic exception due],[expiry date],[vehicle no.]) VALUES ('" + DGV_traffic_exception.Rows[i].Cells[0].Value.ToString() + "','" + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + "' ,'" + tno.Text + "')"); if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(DGV_traffic_exception.Rows[i].Cells[1].Value.ToString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Traffic Exception Due Certificate-" + DGV_traffic_exception.Rows[i].Cells[0].Value.ToString() + " of Vehicle No. : " + tno.Text + " will expire On : " + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + "','Expiration Date : " + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + "')"); if (n.Equals("")) { n = n + "Traffic Exception Due Certificate-" + DGV_traffic_exception.Rows[i].Cells[0].Value.ToString() + " of Vehicle No. : " + tno.Text + " will expire On : " + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + ""; } else { n = n + "\nTraffic Exception Due Certificate-" + DGV_traffic_exception.Rows[i].Cells[0].Value.ToString() + " of Vehicle No. : " + tno.Text + " will expire On : " + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + ""; } } } } db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicles]([Vehicle No.],[Type],[Model],[Fuel Capacity],[Fuel Refill Limit],[Meter Reading],[Engine No.],[Horse Power],[Chasis No.],[Fuel Type],[Color],[Engine CC],[Quotatio date],[Selected Quotation No.],[Purchase Amount],[Cheque No.],[Purchase date],[Tax Expiry date],[RC Expiry date],[Insurance Expiry date],[CF date],[Pollution Certificate Expiry date],[Permit Expiry date],[Green Tax Expiry date],[Status],[fuel],[Full tank],weight)VALUES('" + tno.Text + "','" + combotype.SelectedItem.ToString() + "','" + tmodel.Text + "'," + tmila.Text + "," + tfrefill.Text + "," + tmeter.Text + ",'" + teno.Text + "','" + thorse.Text + "','" + tchasis.Text + "','" + combofuel.Text + "','" + tcolor.Text + "','" + tecc.Text + "','" + dateTimePickerqdate.Value.ToShortDateString() + "','" + tsupplierno.Text + "','" + tpurchaseno.Text + "','" + tchequeno.Text + "','" + dateTimePickerpurchase.Value.ToShortDateString() + "','" + dateTimePickertax.Value.ToShortDateString() + "','" + dateTimePickerrc.Value.ToShortDateString() + "','" + dateTimePickerinsurance.Value.ToShortDateString() + "','" + dateTimePickercf.Value.ToShortDateString() + "','" + dateTimePickerpollution.Value.ToShortDateString() + "','" + dateTimePickerpermit.Value.ToShortDateString() + "','" + dateTimePickergreen.Value.ToShortDateString() + "','Available'," + tfcapacity.Text + "," + tfcapacity.Text + "," + tweight.Text + ")"); MessageBox.Show("Inserted Successfully"); String m = ""; if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickertax.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Tax Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickertax.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickertax.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Tax Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickertax.Value.ToShortDateString() + ""; } else { m = m + "\nTax Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickertax.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickerrc.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','RC of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerrc.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickerrc.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "RC of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerrc.Value.ToShortDateString() + ""; } else { m = m + "\nRC of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerrc.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickerinsurance.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Insurance of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerinsurance.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickerinsurance.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Insurance of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerinsurance.Value.ToShortDateString() + ""; } else { m = m + "\nInsurance of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerinsurance.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickercf.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','CF of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickercf.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickercf.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Cf of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickercf.Value.ToShortDateString() + ""; } else { m = m + "\nCf of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickercf.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickerpollution.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Pollution Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpollution.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickerpollution.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Pollution Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpollution.Value.ToShortDateString() + ""; } else { m = m + "\nPollution Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpollution.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickerpermit.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Permit of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpermit.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickerpermit.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Permit of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpermit.Value.ToShortDateString() + ""; } else { m = m + "\nPermit of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpermit.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickergreen.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Green Tax Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickergreen.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickergreen.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Green Tax Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickergreen.Value.ToShortDateString() + ""; } else { m = m + "\nGreen Tax Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickergreen.Value.ToShortDateString() + ""; } } if (!n.Equals("")) { if (m.Equals("")) { m = m + n; } else { m = m + "\n" + n; } } if (!m.Equals("")) { db.Ins_Up_Del("UPDATE [AVVMS].[dbo].[Vehicles]SET [status] = 'On Certificate Expiration' WHERE [Vehicle No.]='" + tno.Text + "'"); Program.pi.Display(m); } this.Close(); } catch (Exception ex) { MessageBox.Show("Try Again...\nReason : " + ex.Message); db.close(); } } else { MessageBox.Show(message); } } else { String message = ""; int c1f = 0; for (int i = 0; i < DGV_traffic_exception.Rows.Count; i++) { if (DGV_traffic_exception.Rows[i].Cells[0].Value.ToString().Equals("")) { c1f = 1; if (message.Equals("")) { message = message + "Enter Description For Traffic Exception No. : " + (i + 1); } else { message = message + "\nEnter Description For Traffic Exception No. : " + (i + 1); } } if (DGV_traffic_exception.Rows[i].Cells[1].Value.ToString().Equals("")) { c1f = 1; if (message.Equals("")) { message = message + "Enter Expiry Date For Traffic Exception No. : " + (i + 1); } else { message = message + "\nEnter Expiry Date For Traffic Exception No. : " + (i + 1); } } } if (c1f == 0) { try { String n = ""; if (DGV_traffic_exception.Rows.Count != 0) { db.Ins_Up_Del("DELETE FROM [AVVMS].[dbo].[traffic exception] WHERE [Vehicle No.]='" + tno.Text + "'"); for (int i = 0; i < DGV_traffic_exception.Rows.Count; i++) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[traffic exception]([traffic exception due],[expiry date],[vehicle no.]) VALUES ('" + DGV_traffic_exception.Rows[i].Cells[0].Value.ToString() + "','" + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + "' ,'" + tno.Text + "')"); if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(DGV_traffic_exception.Rows[i].Cells[1].Value.ToString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Traffic Exception Due Certificate-" + DGV_traffic_exception.Rows[i].Cells[0].Value.ToString() + " of Vehicle No. : " + tno.Text + " will expire On : " + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + "','Expiration Date : " + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + "')"); if (n.Equals("")) { n = n + "Traffic Exception Due Certificate-" + DGV_traffic_exception.Rows[i].Cells[0].Value.ToString() + " of Vehicle No. : " + tno.Text + " will expire On : " + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + ""; } else { n = n + "\nTraffic Exception Due Certificate-" + DGV_traffic_exception.Rows[i].Cells[0].Value.ToString() + " of Vehicle No. : " + tno.Text + " will expire On : " + DGV_traffic_exception.Rows[i].Cells[1].Value.ToString() + ""; } } } } db.Ins_Up_Del("UPDATE [AVVMS].[dbo].[Vehicles] SET [RC Expiry date] = '" + dateTimePickerrc.Value.ToShortDateString() + "',[CF date] = '" + dateTimePickercf.Value.ToShortDateString() + "',[Pollution Certificate Expiry date] = '" + dateTimePickerpollution.Value.ToShortDateString() + "',[Permit Expiry date] = '" + dateTimePickerpermit.Value.ToShortDateString() + "',[Green Tax Expiry date] = '" + dateTimePickergreen.Value.ToShortDateString() + "' WHERE [Vehicle No.]='" + tno.Text + "'"); MessageBox.Show("Updated Successfully"); String m = ""; if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickerrc.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','RC of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerrc.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickerrc.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "RC of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerrc.Value.ToShortDateString() + ""; } else { m = m + "\nRC of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerrc.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickercf.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','CF of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickercf.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickercf.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Cf of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickercf.Value.ToShortDateString() + ""; } else { m = m + "\nCf of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickercf.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickerpollution.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Pollution Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpollution.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickerpollution.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Pollution Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpollution.Value.ToShortDateString() + ""; } else { m = m + "\nPollution Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpollution.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickerpermit.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Permit of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpermit.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickerpermit.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Permit of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpermit.Value.ToShortDateString() + ""; } else { m = m + "\nPermit of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickerpermit.Value.ToShortDateString() + ""; } } if ((DateTime.Parse(DateTime.Now.ToShortDateString()).AddDays(15).CompareTo(DateTime.Parse(dateTimePickergreen.Value.ToShortDateString()))) >= 0) { db.Ins_Up_Del("INSERT INTO [AVVMS].[dbo].[Vehicle_Notifications]([Vehicle],[Reason],[Remarks])VALUES('" + tno.Text + "','Green Tax Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickergreen.Value.ToShortDateString() + "','Expiration Date : " + dateTimePickergreen.Value.ToShortDateString() + "')"); if (m.Equals("")) { m = m + "Green Tax Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickergreen.Value.ToShortDateString() + ""; } else { m = m + "\nGreen Tax Certificate of Vehicle No. : " + tno.Text + " will expire On : " + dateTimePickergreen.Value.ToShortDateString() + ""; } } if (!n.Equals("")) { if (m.Equals("")) { m = m + n; } else { m = m + "\n" + n; } } if (!m.Equals("")) { db.Ins_Up_Del("UPDATE [AVVMS].[dbo].[Vehicles]SET [status] = 'On Certificate Expiration' WHERE [Vehicle No.]='" + tno.Text + "'"); Program.pi.Display(m); } else { if (db.GetValue("SELECT[Status]FROM [AVVMS].[dbo].[Vehicles] where [Vehicle No.]='" + tno.Text + "'").Equals("On Certificate Expiration")) { db.Ins_Up_Del("UPDATE [AVVMS].[dbo].[Vehicles]SET [status] = 'Available' WHERE [Vehicle No.]='" + tno.Text + "'"); } } this.Close(); } catch (Exception ex) { MessageBox.Show("Try Again...\nReason : " + ex.Message); db.close(); } } else { MessageBox.Show(message); } } } }