using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Globalization; using System.Linq; using System.Runtime.Remoting.Contexts; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Newdelhibarassocia.dhadmin { public partial class billmview : System.Web.UI.Page { Class1 obj=new Class1(); protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"]!=null) { Panel1.Visible = true; Panel2.Visible = true; userdetails(); datadetails(); datak(); } } void photowithname() { string qra = "select * from tb_members where Post='President' order by id desc"; DataSet dsra = obj.ReturnDataSet(qra); if (dsra != null && dsra.Tables[0].Rows.Count > 0) { Literal24.Text = dsra.Tables[0].Rows[0]["Post"].ToString(); Literal25.Text = dsra.Tables[0].Rows[0]["Name"].ToString(); Image1.ImageUrl = dsra.Tables[0].Rows[0]["Photo"].ToString(); Literal31.Text = dsra.Tables[0].Rows[0]["Post"].ToString(); Literal30.Text = dsra.Tables[0].Rows[0]["Name"].ToString(); Image4.ImageUrl = dsra.Tables[0].Rows[0]["Photo"].ToString(); } } void photowithname1() { string qra = "select * from tb_members where Post='Hony. Secretary' order by id desc"; DataSet dsra = obj.ReturnDataSet(qra); if (dsra != null && dsra.Tables[0].Rows.Count > 0) { Literal27.Text = dsra.Tables[0].Rows[0]["Post"].ToString(); Literal26.Text = dsra.Tables[0].Rows[0]["Name"].ToString(); Image2.ImageUrl = dsra.Tables[0].Rows[0]["Photo"].ToString(); Literal33.Text = dsra.Tables[0].Rows[0]["Post"].ToString(); Literal32.Text = dsra.Tables[0].Rows[0]["Name"].ToString(); Image5.ImageUrl = dsra.Tables[0].Rows[0]["Photo"].ToString(); } } void photowithname2() { string qra = "select * from tb_members where Post='Treasurer' order by id desc"; DataSet dsra = obj.ReturnDataSet(qra); if (dsra != null && dsra.Tables[0].Rows.Count > 0) { Literal29.Text = dsra.Tables[0].Rows[0]["Post"].ToString(); Literal28.Text = dsra.Tables[0].Rows[0]["Name"].ToString(); Image3.ImageUrl = dsra.Tables[0].Rows[0]["Photo"].ToString(); Literal35.Text = dsra.Tables[0].Rows[0]["Post"].ToString(); Literal34.Text = dsra.Tables[0].Rows[0]["Name"].ToString(); Image6.ImageUrl = dsra.Tables[0].Rows[0]["Photo"].ToString(); } } public static string NumberToWords(int number) { if (number == 0) return "Zero"; if (number < 0) return "Minus " + NumberToWords(Math.Abs(number)); string words = ""; if ((number / 1000) > 0) { words += NumberToWords(number / 1000) + " Thousand "; number %= 1000; } if ((number / 100) > 0) { words += NumberToWords(number / 100) + " Hundred "; number %= 100; } if (number > 0) { string[] unitsMap = { "Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine", "Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen", "Seventeen","Eighteen","Nineteen" }; string[] tensMap = { "Zero","Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety" }; if (number < 20) words += unitsMap[number]; else { words += tensMap[number / 10]; if ((number % 10) > 0) words += " " + unitsMap[number % 10]; } } return words.Trim(); } void datadetails() { string qrajneeti = "select * from Memberslist where Ndbano='" + Literal4.Text + "' order by id desc"; DataSet dsrajneeti = obj.ReturnDataSet(qrajneeti); if (dsrajneeti != null && dsrajneeti.Tables[0].Rows.Count > 0) { if (dsrajneeti.Tables[0].Rows[0]["Ndbadate"].ToString() != "0") { string dts = dsrajneeti.Tables[0].Rows[0]["Ndbadate"].ToString(); CalculateMembershipDue(dts); GetTotals(dsrajneeti.Tables[0].Rows[0]["Bcdenroll"].ToString()); } } } private void CalculateMembershipDue(string dts) { // ✅ Membership Date from TextBox DateTime membershipDate; string[] formats = { "yyyy-MM-dd", "dd/MM/yyyy" }; if (!DateTime.TryParseExact( dts, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out membershipDate)) { // Label1.Text = "Invalid Date!"; return; } DateTime today = DateTime.Today; DateTime dtt = new DateTime(2016, 1, 1); DateTime discountStart = new DateTime(2020, 4, 1); DateTime discountEnd = new DateTime(2021, 9, 30); decimal totalAmount = 0; // ✅ Loop month by month DateTime loopDate = new DateTime(membershipDate.Year, membershipDate.Month, 1); while (loopDate <= today) { decimal monthAmount = 0; if (loopDate >= discountStart && loopDate <= discountEnd) { monthAmount = 0; // full discount } else if (loopDate >= dtt) { // 👉 You can change this logic if you have count monthAmount = 100; // default } else { monthAmount = 50; } totalAmount += monthAmount; loopDate = loopDate.AddMonths(1); } // ✅ Final Discount (optional 10%) // decimal discount = totalAmount * 0.10m; decimal finalAmount = totalAmount; // ✅ Labels Literal39.Text = Literal41.Text = finalAmount.ToString("0"); } private void GetTotals(string bcd) { string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; decimal totalMembers = 0; decimal totalBills = 0; using (SqlConnection con = new SqlConnection(connStr)) { con.Open(); // ✅ 1. SUM from Membersallrecpit SqlCommand cmd1 = new SqlCommand( "SELECT ISNULL(SUM(Amount),0) FROM Membersallrecpit where Bcdenroll = '" + bcd + "'", con); object result1 = cmd1.ExecuteScalar(); totalMembers = Convert.ToDecimal(result1); // ✅ 2. SUM from newdelhibar_bill SqlCommand cmd2 = new SqlCommand( "SELECT ISNULL(SUM(TRY_CAST(totalamount AS DECIMAL(18,2))),0) FROM newdelhibar_bill where btype!='NEW MEMBERSHIP' and btype='SUBSCRIPTION FEE' and BCDno = '" + bcd + "'", con); object result2 = cmd2.ExecuteScalar(); totalBills = Convert.ToDecimal(result2); } // ✅ Bind to Literals // Literal1.Text = totalMembers.ToString("0.00"); // Literal2.Text = totalBills.ToString("0.00"); decimal dues = 0; if (!string.IsNullOrWhiteSpace(Literal39.Text) && decimal.TryParse(Literal39.Text, out dues)) { decimal due = totalBills + totalMembers; decimal duetotal = dues - due; Literal39.Text = Literal41.Text = duetotal.ToString("0"); } else { Literal39.Text = "0"; // or handle error } } void userdetails() { // photowithname(); // photowithname1(); // photowithname2(); Panel3.Visible = true; Panel1.Visible = true; Panel2.Visible = true; // string qras = "select * from newdelhibar_bill where Billno='" + TextBox7.Text + "'"; // string bno = "7095"; string bno = Request.QueryString["id"].ToString(); string qras = "select * from newdelhibar_bill where Billno='" + bno + "'"; DataSet dss = obj.ReturnDataSet(qras); if (dss != null && dss.Tables[0].Rows.Count > 0) { // Literal10.Text = DropDownList1.SelectedValue.ToString(); Literal3.Text = dss.Tables[0].Rows[0]["Name"].ToString(); if (dss.Tables[0].Rows[0]["Daten"].ToString() != "") { DateTime dt = Convert.ToDateTime(dss.Tables[0].Rows[0]["Daten"].ToString()); if (dt.ToString("dd/MM/yyyy").Replace("12:00:00 AM", "") != "01/01/1900") { Literal2.Text = dt.ToString("dd/MM/yyyy").Replace("12:00:00 AM", ""); } } Literal4.Text = dss.Tables[0].Rows[0]["NDBAno"].ToString(); Literal22.Text = Literal23.Text = dss.Tables[0].Rows[0]["Mobile"].ToString(); Literal1.Text = dss.Tables[0].Rows[0]["Billno"].ToString(); Literal4.Text = dss.Tables[0].Rows[0]["NDBAno"].ToString(); Literal5.Text = dss.Tables[0].Rows[0]["BCDno"].ToString(); Literal6.Text = dss.Tables[0].Rows[0]["Address"].ToString(); Literal10.Text = Literal18.Text = dss.Tables[0].Rows[0]["btype"].ToString(); // Literal7.Text = dss.Tables[0].Rows[0]["Headermessage"].ToString(); Literal9.Text = dss.Tables[0].Rows[0]["Footermessage"].ToString(); // // Literal18.Text = DropDownList1.SelectedValue.ToString(); Literal13.Text = dss.Tables[0].Rows[0]["Name"].ToString(); if (dss.Tables[0].Rows[0]["Daten"].ToString() != "") { DateTime dt = Convert.ToDateTime(dss.Tables[0].Rows[0]["Daten"].ToString()); if (dt.ToString("dd/MM/yyyy").Replace("12:00:00 AM", "") != "01/01/1900") { Literal12.Text = dt.ToString("dd/MM/yyyy").Replace("12:00:00 AM", "").Replace("01/01/1900", ""); } } Literal14.Text = dss.Tables[0].Rows[0]["NDBAno"].ToString(); Literal11.Text = dss.Tables[0].Rows[0]["Billno"].ToString(); Literal14.Text = dss.Tables[0].Rows[0]["NDBAno"].ToString(); Literal15.Text = dss.Tables[0].Rows[0]["BCDno"].ToString(); Literal16.Text = dss.Tables[0].Rows[0]["Address"].ToString(); string fmessadte = ""; if (dss.Tables[0].Rows[0]["fdate"].ToString() != "") { DateTime dts = Convert.ToDateTime(dss.Tables[0].Rows[0]["fdate"].ToString().Replace("12:00:00 AM", "")); if (dts.ToString("dd/MM/yyyy").Replace("12:00:00 AM", "") != "01/01/1900") { fmessadte = "From Date:" + dts.ToString("dd/MM/yyy").Replace("12:00:00 AM", "").Replace("01/01/1900", "") + " "; } } if (dss.Tables[0].Rows[0]["todate"].ToString() != "") { DateTime dt2 = Convert.ToDateTime(dss.Tables[0].Rows[0]["todate"].ToString().Replace("12:00:00 AM", "")); if (dt2.ToString("dd/MM/yyyy").Replace("12:00:00 AM", "") != "01/01/1900") { fmessadte = fmessadte + "To Date:" + dt2.ToString("dd/MM/yyy").Replace("12:00:00 AM", "").Replace("01/01/1900", ""); } } Literal20.Text = dss.Tables[0].Rows[0]["Footermessage"].ToString(); Literal9.Text = dss.Tables[0].Rows[0]["Footermessage"].ToString(); string q = "Select SUM(CAST(Amount as int)) from newdelhibar_rowbill where Billno='" + bno + "'"; DataSet ds = obj.ReturnDataSet(q); if (ds != null && ds.Tables[0].Rows.Count > 0) { Literal8.Text = ds.Tables[0].Rows[0][0].ToString(); Literal19.Text = ds.Tables[0].Rows[0][0].ToString(); Literal38.Text = Literal42.Text = ds.Tables[0].Rows[0][0].ToString(); int number; if (int.TryParse(Literal19.Text, out number)) { Literal36.Text = Literal37.Text = "Total Amount in Words :
" + NumberToWords(number); } DateTime dts1 = Convert.ToDateTime(dss.Tables[0].Rows[0]["chedate"].ToString().Replace("12:00:00 AM", "")); //,,, string kheadermessage = "Sir(s)/Madam, We Acknowledge with thanks the receipt for Rs. " + Literal8.Text + " vide Cheque No./UPI No. " + dss.Tables[0].Rows[0]["Chequeno"].ToString() + " Dated : " + dts1.ToString("dd/MM/yyyy").Replace("01/01/1900", "") + " , Bank towards the following:"; Literal7.Text = kheadermessage; Literal17.Text = kheadermessage; } if (Literal10.Text == "SUBSCRIPTION FEE") { int outsdtingamt = Convert.ToInt32(Literal39.Text); int paidamt = Convert.ToInt32(Literal38.Text); int balnacek = outsdtingamt - paidamt; Literal40.Text = Literal43.Text = Convert.ToString(balnacek); //Panel6.Visible = true; //Panel5.Visible = false; //Panel8.Visible = true; //Panel7.Visible = false; } } } void datak() { string qrajneeti = "select * from newdelhibar_rowbill where Billno='" + Request.QueryString["id"].ToString() + "' order by id asc"; DataSet dsrajneeti = obj.ReturnDataSet(qrajneeti); if (dsrajneeti != null && dsrajneeti.Tables[0].Rows.Count > 0) { DataGrid5.Visible = DataGrid1.Visible= true; DataGrid5.DataSource = dsrajneeti; DataGrid5.DataBind(); DataGrid1.DataSource = dsrajneeti; DataGrid1.DataBind(); } else { DataGrid5.Visible = false; DataGrid1.Visible = false; } } } }