Reputation: 815
I am working on a project,I want to generate a receipt having three copies-student copy,accounts copy,office copy.All these copies will have the same data except the heading.So what i have done is generated a panel and populating it and have made three different divs for three copies.Now at backend after populating the panel i am making three panels at runtime with different names and passing this panel to them and then adding the three panels to their respective div.By doing this i am getting the receipt only once and that to in the last div.Please help me how i can achieve this.
Code
public void generatereceipt()
{ //pnlreceipt is the main panel built in aspx page
divstudent.Controls.Add(pnlreceipt);
divpnlreceipt.Visible = true;
divstudent.Visible = true;
divoffice.Visible = true;
divaccounts.Visible = true;
Panel pnlstudent = new Panel();
pnlstudent = pnlreceipt;
divstudent.Controls.Add(pnlstudent);
Panel pnloffice = new Panel();
pnloffice = pnlreceipt;
divoffice.Controls.Add(pnloffice);
Panel pnlaccounts = new Panel();
pnlaccounts = pnlreceipt;
divaccounts.Controls.Add(pnlaccounts);
divoffice.Visible = true;
divaccounts.Visible = true;
}
//method to fill my panel receipt
public void filldata()
{
sql ="select s.admissionnumber,s.studentname,g.forename,g.relationshipcode,c.classname,concat(a.address,',',a.town,',',a.state,',',a.country) as address,e.amount "
+"from tblstudent s left join tblguardian g on s.studentcode=g.studentcode "
+"left join tblclass c on c.classcode=s.classcode "
+"left join tblcontactaddress ca on ca.usercode=g.guardiancode "
+"left join tbladdress a on ca.addressid=a.addressid "
+"left join tblmiddaymeal_entry e on e.studentcode=s.studentcode "
+"where s.studentcode='"+drpstudent.SelectedItem.Value+"' and c.classcode='"+drpclass.SelectedItem.Value+"'";
ds = obj.openDataset(sql,Session["schoolcode"].ToString());
lblfathername.Text = "";
for (int i = 0; i < ds.Tables[0].Rows.Count;i++)
{
if (ds.Tables[0].Rows[0]["relationshipcode"].ToString()=="14")
{
lblfathername.Text = ds.Tables[0].Rows[i]["forename"].ToString();
}
}
string sqlrecepit = "SELECT * FROM tblmiddaymeal_receipt order by receiptno desc";
DataSet dsreceipt = new DataSet();
dsreceipt = obj.openDataset(sqlrecepit,Session["schoolcode"].ToString());
string sqlschool = "select * from tblschool where schoolcode='"+Session["schoolcode"].ToString()+"'";
DataSet dsSchool = new DataSet();
dsSchool = obj.openDataset(sqlschool,Session["schoolcode"].ToString());
if (dsreceipt.Tables[0].Rows.Count == 0)
{
lblreceiptno.Text = "10000";
}
else
{
lblreceiptno.Text = (Convert.ToInt32(dsreceipt.Tables[0].Rows[0]["receiptno"]) + 1).ToString();
}
lblreceiptcopy.Text = "Student Copy";
lbladmno.Text = ds.Tables[0].Rows[0]["admissionnumber"].ToString();
lblcodeno.Text = "";
lbldate.Text = "<b>"+DateTime.Now.ToString("dd/MM/yyyy")+"</b>";
lblname.Text = ds.Tables[0].Rows[0]["studentname"].ToString();
lblclass.Text = ds.Tables[0].Rows[0]["classname"].ToString();
lblmonth.Text = monthdisplay;
lblschool.Text = dsSchool.Tables[0].Rows[0]["schoolname"].ToString();
lblbranch.Text = "S.S.B";
if (ds.Tables[0].Rows[0]["amount"].ToString().Length == 0)
{
lblamount.Text = "";
lbltotalamount.Text = "";
lblamountwords.Text = "";
}
else
{
lblamount.Text = ds.Tables[0].Rows[0]["amount"].ToString();
lbltotalamount.Text = "<b>" + ds.Tables[0].Rows[0]["amount"].ToString() + "</b>";
lblamountwords.Text = " " + "<b>" + NumberToWords(Convert.ToInt32(ds.Tables[0].Rows[0]["amount"])) + " only" + " </b>";
}
lblpaymenttype.Text = drppayment.SelectedItem.Text;
if(drppayment.SelectedIndex==2)
{
lblbankname.Text = txtbankname.Text;
}
string sqlinsert = "insert into tblmiddaymeal_receipt(receiptno,studentcode,date,forMonthOf,branch,amount,paymenttype,bankname) "
+ "values('" + lblreceiptno.Text + "','" + drpstudent.SelectedItem.Value + "','" + DateTime.Now.ToString("dd/MM/yyyy") + "','" + months + "','" + lblbranch.Text + "','" + lblamount.Text + "','" + lblpaymenttype.Text + "','" + lblbankname.Text + "')";
obj.executeQuery(sqlinsert, Session["schoolcode"].ToString());
}
My panel receipt structure and three divs-student,account and office in aspx page
<asp:Panel ID="pnlreceipt" runat="server">
<div id="divprint">
<div id="divpnlreceipt" runat="server" visible="false">
<table class="outertable">
<tr>
<td>
<asp:Image ID="imglogo" runat="server" ImageUrl="~/Images/scholar-logo.png" CssClass="logo"/>
<asp:Label ID="lblreceiptcopy" runat="server" Text="Label" CssClass="receiptcopyheading"></asp:Label>
</td>
</tr>
<tr>
<td>
<table class="innertablereceipt">
<tr>
<td colspan="4"><span class="innerheading">ME-LUNCH RECEIPT</span></td>
</tr>
<tr>
<td>
Receipt No:<asp:Label ID="lblreceiptno" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td>
Adm. No:<asp:Label ID="lbladmno" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td class="col3">
Code No:<asp:Label ID="lblcodeno" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td>
Date:<asp:Label ID="lbldate" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>
Name:<asp:Label ID="lblname" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td>
Class:<asp:Label ID="lblclass" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td colspan="2">
For the month of:<asp:Label ID="lblmonth" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>
Father's Name:<asp:Label ID="lblfathername" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td>
School:<asp:Label ID="lblschool" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td colspan="2">
Branch:<asp:Label ID="lblbranch" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>
Address:<asp:Label ID="lbladdress" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr style="height:4px;">
<td colspan="4">................................................................................................................................................................................................</td>
</tr>
<tr style="border-bottom:1px dotted black;">
<td colspan="2">
Particulars
</td>
<td>
Amount
</td>
</tr>
<tr style="height:4px;">
<td colspan="4">................................................................................................................................................................................................</td>
</tr>
<tr style="border-bottom:1px dotted black;height:40px">
<td colspan="2">
Me-Lunch Charges
</td>
<td colspan="2">
<asp:Label ID="lblamount" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr style="height:4px;">
<td colspan="4">................................................................................................................................................................................................</td>
</tr>
<tr>
<td colspan="3"></td>
<td>
Total amount:<asp:Label ID="lbltotalamount" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>
Cash/cheque No:<asp:Label ID="lblpaymenttype" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td colspan="3">
Bank Name:<asp:Label ID="lblbankname" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>(In words):</td>
<td colspan="2" class="txtunderline">
<asp:Label ID="lblamountwords" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td></td>
</tr>
<tr>
<td colspan="3">
*Cheque subject to realisation
</td>
<td>Cashier Signature</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</asp:Panel>
<div id="divstudent" runat="server" class="studentreceipt" visible="false">div1</div>
<div id="divoffice" runat="server" class="officereceipt" visible="false">div2</div>
<div id="divaccounts" runat="server" class="accountsreceipt" visible="false">div3</div>
output receipt i want
Upvotes: 2
Views: 4321
Reputation: 2165
This is slightly different. I think you can use "Usercontrols" available in .net
Then you will be able to do it more dynamically.
Good Luck
Upvotes: 0
Reputation: 815
I placed my pnlreceipt inside a repeater and it solved my problem i am pasting my code
Aspx code of repeater
<asp:Repeater ID="rptreceipt" runat="server" OnItemDataBound="rptreceipt_OnItemDataBound">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<asp:Panel ID="pnlreceipt" runat="server">
<div runat="server">
<div id="divpnlreceipt" runat="server">
<table id="tblreceipt" class="outertable" runat="server">
<tr>
<td>
<asp:Image ID="imglogo" runat="server" ImageUrl="~/Images/scholar-logo.png" CssClass="logo"/>
<asp:Label ID="lblreceiptcopy" runat="server" Text="Label" CssClass="receiptcopyheading"></asp:Label>
</td>
</tr>
<tr>
<td>
<table class="innertablereceipt">
<tr>
<td colspan="4"><span class="innerheading">ME-LUNCH RECEIPT</span></td>
</tr>
<tr>
<td>
Receipt No:<asp:Label ID="lblreceiptno" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td>
Adm. No:<asp:Label ID="lbladmno" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td class="col3">
Code No:<asp:Label ID="lblcodeno" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td>
Date:<asp:Label ID="lbldate" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>
Name:<asp:Label ID="lblname" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td>
Class:<asp:Label ID="lblclass" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td colspan="2">
For the month of:<asp:Label ID="lblmonth" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>
Father's Name:<asp:Label ID="lblfathername" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td>
School:<asp:Label ID="lblschool" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td colspan="2">
Branch:<asp:Label ID="lblbranch" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>
Address:<asp:Label ID="lbladdress" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr style="height:4px;">
<td colspan="4">................................................................................................................................................................................................</td>
</tr>
<tr style="border-bottom:1px dotted black;">
<td colspan="2">
Particulars
</td>
<td>
Amount
</td>
</tr>
<tr style="height:4px;">
<td colspan="4">................................................................................................................................................................................................</td>
</tr>
<tr style="border-bottom:1px dotted black;height:40px">
<td colspan="2">
Me-Lunch Charges
</td>
<td colspan="2">
<asp:Label ID="lblamount" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr style="height:4px;">
<td colspan="4">................................................................................................................................................................................................</td>
</tr>
<tr>
<td colspan="3"></td>
<td>
Total amount:<asp:Label ID="lbltotalamount" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>
Cash/cheque No:<asp:Label ID="lblpaymenttype" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td colspan="3">
Bank Name:<asp:Label ID="lblbankname" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
</tr>
<tr>
<td>(In words):</td>
<td colspan="2" class="txtunderline">
<asp:Label ID="lblamountwords" runat="server" Text="" CssClass="lblreceipt"></asp:Label>
</td>
<td></td>
</tr>
<tr>
<td colspan="3">
*Cheque subject to realisation
</td>
<td>Cashier Signature</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</asp:Panel>
</ItemTemplate>
</asp:Repeater>
C# code
public void filldata()
{
int[] a=new int[]{0,1,2};
rptreceipt.DataSource = a;
rptreceipt.DataBind();
}
public void rptreceipt_OnItemDataBound(object sender,RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
sql = "select s.admissionnumber,s.studentname,g.forename,g.relationshipcode,c.classname,concat(a.address,',',a.town,',',a.state,',',a.country) as address,e.amount "
+ "from tblstudent s left join tblguardian g on s.studentcode=g.studentcode "
+ "left join tblclass c on c.classcode=s.classcode "
+ "left join tblcontactaddress ca on ca.usercode=g.guardiancode "
+ "left join tbladdress a on ca.addressid=a.addressid "
+ "left join tblmiddaymeal_entry e on e.studentcode=s.studentcode "
+ "where s.studentcode='" + drpstudent.SelectedItem.Value + "' and c.classcode='" + drpclass.SelectedItem.Value + "'";
ds = obj.openDataset(sql, Session["schoolcode"].ToString());
Label lblreceiptcopy=(Label) e.Item.FindControl("lblreceiptcopy");
Label lblreceiptno = (Label)e.Item.FindControl("lblreceiptno");
Label lbladmno = (Label)e.Item.FindControl("lbladmno");
Label lblcodeno = (Label)e.Item.FindControl("lblcodeno");
Label lbldate = (Label)e.Item.FindControl("lbldate");
Label lblname = (Label)e.Item.FindControl("lblname");
Label lblclass = (Label)e.Item.FindControl("lblclass");
Label lblmonth = (Label)e.Item.FindControl("lblmonth");
Label lblfathername = (Label)e.Item.FindControl("lblfathername");
Label lblschool = (Label)e.Item.FindControl("lblschool");
Label lblbranch = (Label)e.Item.FindControl("lblbranch");
Label lbladdress = (Label)e.Item.FindControl("lbladdress");
Label lblamount = (Label)e.Item.FindControl("lblamount");
Label lbltotalamount = (Label)e.Item.FindControl("lbltotalamount");
Label lblpaymenttype = (Label)e.Item.FindControl("lblpaymenttype");
Label lblbankname = (Label)e.Item.FindControl("lblbankname");
Label lblamountwords = (Label)e.Item.FindControl("lblamountwords");
if (e.Item.ItemIndex == 0)
lblreceiptcopy.Text = "Student Copy";
else if (e.Item.ItemIndex == 1)
lblreceiptcopy.Text = "Office Copy";
else
lblreceiptcopy.Text = "Accounts Copy";
lblfathername.Text = "";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[0]["relationshipcode"].ToString() == "14")
{
lblfathername.Text = ds.Tables[0].Rows[i]["forename"].ToString();
}
}
string sqlrecepit = "SELECT * FROM tblmiddaymeal_receipt order by receiptno desc";
DataSet dsreceipt = new DataSet();
dsreceipt = obj.openDataset(sqlrecepit, Session["schoolcode"].ToString());
string sqlschool = "select * from tblschool where schoolcode='" + Session["schoolcode"].ToString() + "'";
DataSet dsSchool = new DataSet();
dsSchool = obj.openDataset(sqlschool, Session["schoolcode"].ToString());
if (dsreceipt.Tables[0].Rows.Count == 0)
{
lblreceiptno.Text = "10000";
}
else
{
lblreceiptno.Text = (Convert.ToInt32(dsreceipt.Tables[0].Rows[0]["receiptno"]) + 1).ToString();
}
//lblreceiptcopy.Text = "Student Copy";
lbladmno.Text = ds.Tables[0].Rows[0]["admissionnumber"].ToString();
lblcodeno.Text = "";
lbldate.Text = "<b>" + DateTime.Now.ToString("dd/MM/yyyy") + "</b>";
lblname.Text = ds.Tables[0].Rows[0]["studentname"].ToString();
lblclass.Text = ds.Tables[0].Rows[0]["classname"].ToString();
lblmonth.Text = monthdisplay;
lblschool.Text = dsSchool.Tables[0].Rows[0]["schoolname"].ToString();
lblbranch.Text = "S.S.B";
if (ds.Tables[0].Rows[0]["amount"].ToString().Length == 0)
{
lblamount.Text = "";
lbltotalamount.Text = "";
lblamountwords.Text = "";
}
else
{
lblamount.Text = ds.Tables[0].Rows[0]["amount"].ToString();
lbltotalamount.Text = "<b>" + ds.Tables[0].Rows[0]["amount"].ToString() + "</b>";
lblamountwords.Text = " " + "<b>" + NumberToWords(Convert.ToInt32(ds.Tables[0].Rows[0]["amount"])) + " only" + " </b>";
}
lblpaymenttype.Text = drppayment.SelectedItem.Text;
if (drppayment.SelectedIndex == 2)
{
lblbankname.Text = txtbankname.Text;
}
string sqlinsert = "insert into tblmiddaymeal_receipt(receiptno,studentcode,date,forMonthOf,branch,amount,paymenttype,bankname) "
+ "values('" + lblreceiptno.Text + "','" + drpstudent.SelectedItem.Value + "','" + DateTime.Now.ToString("dd/MM/yyyy") + "','" + months + "','" + lblbranch.Text + "','" + lblamount.Text + "','" + lblpaymenttype.Text + "','" + lblbankname.Text + "')";
obj.executeQuery(sqlinsert, Session["schoolcode"].ToString());
}
}
Upvotes: 2
Reputation: 11
Do you mean one user interface design with different data value? may be like this? First you create constructor, to show the panel format, simple example:
Panel myPanel = new Panel();
Label myLabel = new Label();
private void drawMe()
{
this.controls.add(mypanel);
mypanel.controls.add(mylabel);
}
private void forStudent()
{
mylabel.text = "Student Copy";
}
private void forOffice()
{
mylabel.text = "Office Copy";
}
private void forAccount()
{
mylabel.text = "Account Copy";
}
Upvotes: 0