Tuesday, November 17, 2009

PaymentReceivedDetails !!

public partial class paymentreceiveddetail : System.Web.UI.Page
{
string Printbody;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.QueryString.HasKeys())
{
BtnSubmit.Visible = false;
FillPaymentRecDetail();
}
else
{
BtnExToPDF.Visible = false;
BtnEmail.Visible = false;
BtnCopy.Visible = false;
BtnPrint.Visible = false;
PaymentDetail();
}
}
}

//Code for Fill payment Received detail //
private void FillPaymentRecDetail()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();
string id = Request.QueryString["id"].ToString();
string str = "select * from viewPaymentReceived where pr_id=@Payid ";
SqlCommand com = new SqlCommand(str, conn);

SqlParameter PayID = new SqlParameter("@Payid", SqlDbType.Int, 4);
PayID.Value = Request.QueryString["id"];
com.Parameters.Add(PayID);

SqlDataReader dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
lblSupplierName.Text = dr["cust_name"].ToString();

lblInvoiceNo.Text = dr["invoice_no"].ToString();
//foreach (ListItem list in lblInvoiceNo.Text)
//{
// lblInvoiceNo.Text = list.Text + "," + lblInvoiceNo.Text;
//}

lblDate.Text = dr["progDate"].ToString();
lblMode.Text = dr["pmode_name"].ToString();
lblcurrency1.Text = dr["pr_currency"].ToString();
lblAmount.Text = dr["pr_amount"].ToString();
lblBankName.Text = dr["bank_name"].ToString();
lblMICRCode.Text = dr["pr_bank_micr"].ToString();
lblBankBranch.Text = dr["pr_bank_branch"].ToString();
lblInstrumentNo.Text = dr["pr_instrument_no"].ToString();
lblInstrumentDate.Text = dr["progDateInstrument"].ToString();
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
}

//*Code for *//
private void PaymentDetail()
{
using (SqlConnection PaymentConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
PaymentConn.Open();
if (Page.PreviousPage != null)
{

// TextBox _tbxMktFundRs = ((TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("tbxMktFundRs"));



DropDownList DDLSupplierName = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DDLSupplierName");
lblSupplierName.Text = DDLSupplierName.SelectedItem.Text;
Session["SupplierId"] = DDLSupplierName.SelectedValue.ToString();
// ListBox _ltboxInvoiceNo = (ListBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("ltboxInvoiceNo");
// lblInvoiceNo.Text = _ltboxInvoiceNo.SelectedItem.Text;

CheckBoxList chkboxlistInvoice = (CheckBoxList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("chkboxlistInvoice");

foreach (ListItem list in chkboxlistInvoice.Items)
{
if (list.Selected)
{
lblInvoiceNo.Text = list.Text + "," + lblInvoiceNo.Text;
}
}

if (lblInvoiceNo.Text != "")
{
lblInvoiceNo.Text = lblInvoiceNo.Text.Substring(0, lblInvoiceNo.Text.Length - 1);
}


//lblInvoiceNo.Text = chkboxlistInvoice.SelectedItem.Text;


TextBox Date = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("txtDate");
lblDate.Text = Date.Text;
DropDownList Mode = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DDLMode");
lblMode.Text = Mode.SelectedItem.Text;
Session["ModeId"] = Mode.SelectedValue.ToString();
TextBox Amount = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("txtAmount");
lblAmount.Text = Amount.Text;
Session["Amount"] = Amount.Text;
Label Currency = (Label)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("lblcurrency");
lblcurrency1.Text = Currency.Text;

DropDownList BankName = (DropDownList)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("DDLBankName");
lblBankName.Text = BankName.SelectedItem.Text;
Session["BankId"] = BankName.SelectedValue.ToString();
TextBox MICRCode = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("txtMICRCode");
lblMICRCode.Text = MICRCode.Text;
TextBox BankBranch = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("txtBankBranch");
lblBankBranch.Text = BankBranch.Text;
TextBox InstrumentNo = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("txtInstrumentNo");
lblInstrumentNo.Text = InstrumentNo.Text;
TextBox InstrumentDate = (TextBox)PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("txtInstrumentDate");
lblInstrumentDate.Text = InstrumentDate.Text;
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
PaymentConn.Close();
}

}
}
protected void BtnCopy_click(object sender, EventArgs e)
{
string id=Request.QueryString["id"].ToString();
Response.Redirect("addpaymentreceived.aspx?action=Copy&ID=" + id + "");
}

private string MakePageBody(string action)
{
if (action == "Print")
{
Printbody = " " + " " +



"" + " " +
"" + " " +
"" + " " +
"";

}
else if (action == "Email")
{
Printbody = "
Payment sent details " + " " +

"
" + " " +



"" + " " +
"" + " " +
"" + " " +
"";

}
Printbody = Printbody + " " + " " +
" " + " " +
"" + " " +
"
Payment sent details " + " " +

"
" + " " +
" " + " " +
" " + " " +
" " + " " +

" " + " " +
" " + " " +
" " + " " +
" " + " " +

" " + " " +
"" + " " +
" " + " " +
"" + " " +

"" + " " +
"" + " " +
" " + " " +
"" + " " +

"" + " " +
" " + " " +
" " + " " +
" " + " " +

" " + " " +
"" + " " +
" " + " " +
"" + " " +

"" + " " +
"" + " " +
" " + " " +
"" + " " +

"" + " " +
"" + " " +
" " + " " +
"" + " " +

" " + " " +
" " + " " +
" " + " " +
" " + " " +

" " + " " +
"" + " " +
" " + " " +
"" + " " +

" " + " " +
"" + " " +
" " + " " +
" " + " " +
" " + " " +
" " + " " +
"
Supplier Name: " + lblSupplierName.Text + "
Invoice No. :" + lblInvoiceNo.Text + "
Date:" + lblDate.Text + "
Mode:" + lblMode.Text + "
Amount:" + lblAmount.Text + "
Bank Name:" + lblBankName.Text + "
MICR Code: " + lblMICRCode.Text + "
Bank Branch:" + lblBankBranch.Text + "
Instrument No.:" + lblInstrumentNo.Text + "
Instrument Date:" + lblInstrumentDate.Text + "
 " + " " +

" " + " " +

"
";
return Printbody;
}
protected void BtnPrint_click(object sender, EventArgs e)
{
Session["PrintBody"] = MakePageBody("Print");
//Response.Redirect("Print.aspx");
Response.Write("");
}
protected void BtnEmail_click(object sender, EventArgs e)
{
Session["EmailBody"] = MakePageBody("Email");
Response.Redirect("SendEmail.aspx?Page=PaymnetReceived&ID=" + Request.QueryString["id"] + "");
}
protected void BtnBack_click(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
Response.Redirect("viewpaymentreceived.aspx");
}
else
{
//Response.Redirect( "Back to previous page" );

Response.Redirect("addpaymentreceived.aspx");
}
}
protected void BtnExToPDF_click(object sender, EventArgs e)
{

}
protected void BtnSubmit_click(object sender, EventArgs e)
{
insertPaymentSent();
UpdateCustomerMaster();
UpdateRecInvoiceMaster();
Response.Redirect("viewpaymentreceived.aspx");
}

//Code for Update tblSupplierMaster //
private void UpdateCustomerMaster()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
if (conn.State == ConnectionState.Closed) conn.Open();

//where pm_id=@Payid
// string id = Request.QueryString["id"].ToString();
string str = "update tblCustomerMaster set cust_payment_due=cust_payment_due-" + Session["Amount"] + " where cust_id=" + Session["SupplierId"] + " ";
SqlCommand com = new SqlCommand(str, conn);
com.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
}

//*Code for Insert the forms values into the Table*//
private void insertPaymentSent()
{
using (SqlConnection PaymentConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
PaymentConn.Open();
SqlCommand PaymantCom = new SqlCommand("insert_tblPaymentReceived", PaymentConn);
PaymantCom.CommandType = CommandType.StoredProcedure;
PaymantCom.Parameters.Add(new SqlParameter("@cust_id", Session["SupplierId"].ToString()));
PaymantCom.Parameters.Add(new SqlParameter("@invoice_no", lblInvoiceNo.Text));
string StrDate = lblDate.Text.Substring(3, 2) + "/" + lblDate.Text.Substring(0, 2) + "/" + lblDate.Text.Substring(6, 4);
PaymantCom.Parameters.Add(new SqlParameter("@pr_date", StrDate.ToString()));
PaymantCom.Parameters.Add(new SqlParameter("@pmode_id", Session["ModeId"].ToString()));
PaymantCom.Parameters.Add(new SqlParameter("@pr_amount", lblAmount.Text));
PaymantCom.Parameters.Add(new SqlParameter("@pr_currency", lblcurrency1.Text));

PaymantCom.Parameters.Add(new SqlParameter("@bank_id", Session["BankId"].ToString()));
PaymantCom.Parameters.Add(new SqlParameter("@pr_bank_micr", lblMICRCode.Text));
PaymantCom.Parameters.Add(new SqlParameter("@pr_instrument_no", lblInstrumentNo.Text));
PaymantCom.Parameters.Add(new SqlParameter("@pr_bank_branch", lblBankBranch.Text));
string StrInstrDate = lblInstrumentDate.Text.Substring(3, 2) + "/" + lblInstrumentDate.Text.Substring(0, 2) + "/" + lblInstrumentDate.Text.Substring(6, 4);
PaymantCom.Parameters.Add(new SqlParameter("@pr_instrument_date", StrInstrDate.ToString()));

string ModeRealisation = Session["ModeRealisation"].ToString();
if (ModeRealisation == "Auto")
{
PaymantCom.Parameters.Add(new SqlParameter("@pr_cheque_status", "Realised"));
}
else if (ModeRealisation == "Manual")
{
PaymantCom.Parameters.Add(new SqlParameter("@pr_cheque_status", "UnRealised"));
}

//PaymantCom.Parameters.Add(new SqlParameter("@pr_cheque_status", "Yes"));
PaymantCom.Parameters.Add(new SqlParameter("@pr_created_by", int.Parse(Session["EmpID"].ToString())));
PaymantCom.Parameters.Add(new SqlParameter("@pr_delete", "No"));

//PaymantCom.Parameters.Add(new SqlParameter("@pm_active", "Yes"));

// PaymantCom.Parameters.Add(new SqlParameter("@pm_instrument_date", txtInstrumentDate.Text));
PaymantCom.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
PaymentConn.Close();
}

}

}
private void UpdateRecInvoiceMaster()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
if (conn.State == ConnectionState.Closed) conn.Open();

//where pm_id=@Payid
string strInvoice = lblInvoiceNo.Text;
ArrayList arrInvoice = new ArrayList();
string[] strInvoiceName = strInvoice.Split(',');
if (strInvoiceName.Length > 0)
{
for (int i = 0; i < strInvoiceName.Length; i++)
{
//arrInvoice.Add(strInvoiceName[i].ToString());
//Response.Write(strInvoiceName[i].ToString()+ "---");
string str = "update tblInvoiceMaster set inv_paid='Yes' where inv_no='" + strInvoiceName[i].ToString() + "' ";
SqlCommand com = new SqlCommand(str, conn);
com.ExecuteNonQuery();
}
}


}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
}
}

No comments: