in my window application i am creating a datepicker and checkboxes. once i checked (yes) so some controls are becoming invisible.and records should be go to the datatable . if some controls are invisible after checked so data should be enter blank from datepickers.
i am sending my codes
if is there any example which is related to my codes so please forward to me.
What I have tried:
private void button1_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DCID;Integrated Security=True"))
{
// string query = "insert into SystemConfiguration(FRANo,ProductCategory,make,PartName,SerialNo,BriefDetails,invoiceNo,productCost,vandorName,warranty) values(@FRANo,@ProductCategory,@make,@PartName,@SerialNo,@BriefDetails,@invoiceNo,@warranty,@productCost,@vandorName)";
string query = "insert into SystemConfiguration(FRANo,ProductCategory,make,SerialNo,BriefDetails,invoiceNo,date,productCost,vandorName,warranty,warrantyUpTo,IssuedTo,IssuedOn,UnderAMC,AMCWith,AMCUpTo) values(@FRANo,@ProductCategory,@make,@SerialNo,@BriefDetails,@invoiceNo,@date,@productCost,@vandorName,@warranty,@warrantyUpTo,@IssuedTo,@IssuedOn,@underamc,@AMCWith,@AMCUpTo)";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@FRANo", Int32.Parse(txtfrano.Text));
cmd.Parameters.AddWithValue("@ProductCategory", comboproductcategory.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@make", combomake.SelectedItem.ToString());
// cmd.Parameters.AddWithValue("@PartName", combopartname.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@SerialNo", txtserialno.Text);
cmd.Parameters.AddWithValue("BriefDetails", txtbriefConfiguration.Text);
cmd.Parameters.AddWithValue("@invoiceNo", Int32.Parse(txtinvoicno.Text));
cmd.Parameters.AddWithValue("@date", Convert.ToDateTime(dateTimePickerdate.Text));
cmd.Parameters.AddWithValue("@productCost", Convert.ToDecimal(txtproductcost.Text));
cmd.Parameters.AddWithValue("@vandorName", txtvendorname.Text);
string ss = "Empty";
if (checkBoxOnsite.Checked)
{
cmd.Parameters.AddWithValue("@warranty", warranty);
DateTimePicker objpick = new DateTimePicker();
objpick.Name = "black";
string ss1 = objpick.Name;
cmd.Parameters.AddWithValue("@warrantyUpTo", Convert.ToString(ss1));
cmd.Parameters.AddWithValue("@AMCUpTo", Convert.ToString(ss1));
cmd.Parameters.AddWithValue("@AMCWith", ss);
}
else if (!checkBoxOnsite.Checked)
{
cmd.Parameters.AddWithValue("@warranty", ss);
cmd.Parameters.AddWithValue("@AMCUpTo", Convert.ToDateTime(dateTimeWarrantyUpTo.Text));
cmd.Parameters.AddWithValue("@AMCUpTo", Convert.ToDateTime(dateTimeAMCupTo.Text));
cmd.Parameters.AddWithValue("@AMCWith", texAMCWith.Text);
}
if (checkBoxunderamcyes.Checked)
{
cmd.Parameters.AddWithValue("@UnderAMC", underamc);
}
else if (!checkBoxunderamcyes.Checked)
{
cmd.Parameters.AddWithValue("@UnderAMC", ss);
}
//cmd.Parameters.AddWithValue("@UnderAMC", underamc);
cmd.Parameters.AddWithValue("@IssuedTo", Convert.ToDateTime(dateTimeIssuedTo.Text));
cmd.Parameters.AddWithValue("@IssuedOn", Convert.ToDateTime(dateTimeIssuedON.Text));
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
MessageBox.Show("Submit");
clearAll();
}
}
catch (Exception ex)
{
MessageBox.Show("Check Again !"+ex.Message+"");
}
}
private void checkBoxOnsite_CheckedChanged(object sender, EventArgs e)
{
warranty = "On Site";
if (checkBoxOnsite.Checked)
{
checkBoxunderamcyes.Enabled = false;
checkBoxunderamcno.Enabled = false;
checkBoxunderamcyes.Checked = false;
checkBoxOffsite.Enabled = false;
dateTimeAMCupTo.Enabled = false;
texAMCWith.Enabled = false;
dateTimeWarrantyUpTo.Enabled = false;
}
else if (!checkBoxOnsite.Checked)
{
checkBoxunderamcyes.Enabled = true;
checkBoxunderamcyes.Checked = false;
checkBoxOffsite.Enabled = true;
dateTimeAMCupTo.Enabled = true;
texAMCWith.Enabled = true;
dateTimeWarrantyUpTo.Enabled = true;
}
}