I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
I have two table, such as complaint table and status table. Now, i want to add data in both table through same SqlCommand class instance. Now, first to prepare the Connection using SqlConnection class, after that design the query for first table after inserting the data, we can add data into other table.
<tr>
<td class="style3">
Complaint against To</td>
</tr>
<tr>
<td class="style1">
Name :
<asp:TextBox ID="pname" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="pname" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Business
<asp:TextBox ID="pbusiness" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ControlToValidate="pbusiness" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Address
<asp:TextBox ID="padd" runat="server" Height="61px" Width="248px"
TextMode="MultiLine" ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
ControlToValidate="padd" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Phone Number
<asp:TextBox ID="pnumber" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"
ControlToValidate="pnumber" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Faulty Proff
<asp:TextBox ID="pfproff" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server"
ControlToValidate="pfproff" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Faulty Proff Image
<asp:FileUpload ID="pproffimage" runat="server" />
</td>
</tr>
<tr>
<td class="style1">
Review Against
<asp:TextBox ID="preview" runat="server" Height="55px" Width="248px"
TextMode="MultiLine" ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server"
ControlToValidate="preview" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Fir Number (if any)
<asp:TextBox ID="pfir" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server"
ControlToValidate="pfir" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
</p>
<p>
<asp:Label ID="Label1" runat="server"></asp:Label>
</p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red"
ValidationGroup="cr" />
You can check the complete.
Source Code
<table style="width:100%;"><tr>
<td class="style3">
Complaint against To</td>
</tr>
<tr>
<td class="style1">
Name :
<asp:TextBox ID="pname" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="pname" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Business
<asp:TextBox ID="pbusiness" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ControlToValidate="pbusiness" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Address
<asp:TextBox ID="padd" runat="server" Height="61px" Width="248px"
TextMode="MultiLine" ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
ControlToValidate="padd" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Phone Number
<asp:TextBox ID="pnumber" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"
ControlToValidate="pnumber" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Faulty Proff
<asp:TextBox ID="pfproff" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server"
ControlToValidate="pfproff" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Faulty Proff Image
<asp:FileUpload ID="pproffimage" runat="server" />
</td>
</tr>
<tr>
<td class="style1">
Review Against
<asp:TextBox ID="preview" runat="server" Height="55px" Width="248px"
TextMode="MultiLine" ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server"
ControlToValidate="preview" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style1">
Fir Number (if any)
<asp:TextBox ID="pfir" runat="server" Height="24px" Width="245px"
ValidationGroup="cr"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server"
ControlToValidate="pfir" ErrorMessage="Consumer Name Required" ForeColor="Red"
ValidationGroup="cr">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
</p>
<p>
<asp:Label ID="Label1" runat="server"></asp:Label>
</p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red"
ValidationGroup="cr" />
Design View Of Source code
Complete Business Logic Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class UserControl_complaint : System.Web.UI.UserControl
{
string savefile = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string un=System.Guid.NewGuid ().ToString ();
if (pproffimage.HasFile)
{
pproffimage.SaveAs(Server.MapPath("~/images/" + pproffimage.FileName));
savefile = "~/images/" + pproffimage.FileName;
}
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into complaint(Party_Name,Business,Address,Faulty_proff,Image,Review,Fir_Numer,Consumer_Id,date,uniquet) values(@cuoname,@cuofname,@cuodob,@cuoadd,@cuoimage,@cuophone,@cuoemail,@cuoph,@cuodate,@cuoun)";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@cuoname",pname.Text);
cmd.Parameters.AddWithValue("@cuofname",pbusiness.Text);
cmd.Parameters.AddWithValue("@cuodob", padd.Text);
cmd.Parameters.AddWithValue("@cuoadd",pfproff .Text);
cmd.Parameters.AddWithValue("@cuoimage", savefile);
cmd.Parameters.AddWithValue("@cuophone",preview.Text);
cmd.Parameters.AddWithValue("@cuoemail", pfir .Text);
cmd.Parameters.AddWithValue("@cuoph",Session["cons_id"].ToString());
cmd.Parameters.AddWithValue("@cuodate", DateTime.Now.ToString ());
cmd.Parameters.AddWithValue("@cuoun", un);
int a = cmd.ExecuteNonQuery();
if (a > 0)
{
Label1.Text = "Data Inserted Sucessfully";
Label1.ForeColor = System.Drawing.Color.Green;
}
cmd.Parameters.Clear();
cmd.CommandText = "insert into status(status,Complaint_Id,consumer_id) values(@stname,@comid,@cunsid)";
cmd.Parameters.AddWithValue("@stname", "pending");
cmd.Parameters.AddWithValue("@comid",un);
cmd.Parameters.AddWithValue("@cunsid", Session["cons_id"].ToString());
cmd.ExecuteNonQuery();
}
}
Comments
Post a Comment