私はasp.net開発者の初心者で、グリッドビューが含まれています
ProductID, ProductName, Price, Qty, Total
デフォルトは 5 列に設定
製品名を選択すると、価格が自動的に表示されますが、数量はユーザーが入力します。数量を入力しない場合は、メッセージが表示されます。いずれかの列が完全に入力されている場合は、データベースを保存しますか?
productName はドロップダウンリストです。コードにサーバー側のコードが必要です
protected void btnSave_Click(オブジェクト送信者, EventArgs e) {
SqlDataAdapter sda;
SqlCommand cmd;
DateTime savedate = DateTime.ParseExact(txtBillDate.Text.Trim() + " " + DateTime.Now.ToString("hh:mm:ss tt"), "dd/MM/yyyy hh:mm:ss tt", null);
TextBox txtProductID, txtPrice, txtQty, txtTotal;
DropDownList ddlProductName;
DataTable mdt = new DataTable();
Label lblGrandTotal;
if (DataCheck())
{
if (txtMobileNumber.Text != "")
{
con.Open();
cmd = new SqlCommand("insert into Billing(BillNumber,BillDate,CustomerName,CustomerMobile) values('" + txtBillNumber.Text + "','" + savedate + "','" + ddlCustomerName.SelectedItem.Text + "','" + txtMobileNumber.Text + "')", con);
for (int i = 0;i< GridView1.Rows.Count ; i++)
{
txtProductID = (TextBox)(GridView1.Rows[i].FindControl("txtProductID"));
ddlProductName = (DropDownList)(GridView1.Rows[i].FindControl("ddlProductName"));
txtPrice = (TextBox)(GridView1.Rows[i].FindControl("txtPrice"));
txtQty = (TextBox)(GridView1.Rows[i].FindControl("txtQty"));
txtTotal = (TextBox)(GridView1.Rows[i].FindControl("txtTotal"));
lblGrandTotal = (Label)(GridView1.Rows[i].FindControl("lblGrandTotal"));
sda = new SqlDataAdapter("insert into BillingChild(ProductID,ProductName,Price,Qty,Total,BillNumber,BillDate,CustomerName,MobileNumber,BillChildNumber) values('" + txtProductID.Text + "','" + ddlProductName.SelectedItem + "','" + Convert.ToDecimal(txtPrice.Text) + "','" + Convert.ToDecimal(txtQty.Text) + "','" + Convert.ToDecimal(txtTotal.Text) + "','" + txtBillNumber.Text + "','" + savedate + "','" + ddlCustomerName.SelectedItem + "','" + txtMobileNumber.Text + "','" + txtBillChildNumber.Text + "')", con);
sda.Fill(mdt);
cmd.ExecuteNonQuery();
}
con.Close();
}
}
else
{
Response.Write("<Script>alert('plz enter Qty')</script>");
}
}
public bool DataCheck()
{
//TextBox txtProductID = null, txtPrice = null, txtQty = null, txtTotal = null;
//DropDownList ddlProductName = null;
//Label lblGrandTotal = null;
TextBox txtProductID, txtPrice, txtQty, txtTotal;
DropDownList ddlProductName;
Label lblGrandTotal;
if (GridView1.Rows.Count != 0)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
txtProductID = (TextBox)(GridView1.Rows[i].FindControl("txtProductID"));
ddlProductName = (DropDownList)(GridView1.Rows[i].FindControl("ddlProductName"));
txtPrice = (TextBox)(GridView1.Rows[i].FindControl("txtPrice"));
txtQty = (TextBox)(GridView1.Rows[i].FindControl("txtQty"));
txtTotal = (TextBox)(GridView1.Rows[i].FindControl("txtTotal"));
lblGrandTotal = (Label)(GridView1.Rows[i].FindControl("lblGrandTotal"));
if (txtQty.Text != "")
{
continue;
}
else
{
return false;
}
}
}
return true;
}