Monday, November 16, 2009

AddPaymentSent !!

public partial class AddPaymentsSent : System.Web.UI.Page
{
ListItem lstInvoice;
IDLDPLMain objIDLDPLMain = new IDLDPLMain();
DynMenu objDynMenu = new DynMenu();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txtDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
if (Request.QueryString.HasKeys())
{
if (Request.QueryString["Action"] == "Edit")
{
lblPaymentSent.Text = "edit payment sent ";
objIDLDPLMain.AddlogDetails("Edit Payment Sent", Request.Url.ToString());
btnSubmit.Visible = false;
btnSubmit.Text = "Save";
SupplierName();
ModeName();
BankName();
// SelectInvoiceNoForEdit();
FillPaymentDetail();
// SelectInvoiceNoForEdit();

}
else if (Request.QueryString["action"] == "Copy")
{
lblPaymentSent.Text = "copy payment sent ";
objIDLDPLMain.AddlogDetails("Copy Payment Sent", Request.Url.ToString());
BtnSave.Visible = false;
SupplierName();
ModeName();
BankName();
FillPaymentDetail();
}
}
else
{
if (!Page.IsPostBack)
{
if (objDynMenu.PermissionOk("add", "Accounts", "Payment Sent") == "Yes")
{
objIDLDPLMain.AddlogDetails("New Payment Sent", Request.Url.ToString());
BtnSave.Visible = false;
SupplierName();
ModeName();
BankName();
}
else
{
Response.Redirect("adminhome.aspx");
}
}
}
}
}

//Code for Filling The Page For Edit and copy//
private void FillPaymentDetail()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();
string id = Request.QueryString["id"].ToString();
string str = "select * from viewPaymentMade where pm_id="+id+"";
//string str = "select * from viewPaymentMade where supl_id=@Payid ";
SqlCommand com = new SqlCommand(str, conn);
//DataSet ds=new DataSet();
//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();
DDLSupplierName.SelectedIndex = DDLSupplierName.Items.IndexOf(DDLSupplierName.Items.FindByText(dr["supl_name"].ToString()));
Session["Supl_id"] = dr["supl_id"].ToString();
// SelectInvoiceNoForEdit();
Session["InvoiceNo"] = dr["supl_invoice_no"].ToString();
DisplayInvoice(dr["supl_invoice_no"].ToString());
chkboxlistInvoice.SelectedValue = dr["supl_invoice_no"].ToString();
Session["InvoiceId"] = dr["supl_invoice_no"].ToString();
//ltboxInvoiceNo.Text = dr["supl_invoice_no"].ToString();
txtDate.Text = dr["progDate"].ToString();
DDLMode.SelectedIndex = DDLMode.Items.IndexOf(DDLMode.Items.FindByValue(dr["pmode_id"].ToString()));
DDLMode.SelectedValue = dr["pmode_id"].ToString();

Session["ChequeStatus"] = dr["pm_cheque_status"].ToString();

txtAmount.Text = dr["pm_amount"].ToString();
lblCurrency.Text = dr["pm_currency"].ToString();
// DDLBankName.SelectedIndex = DDLBankName.Items.IndexOf(DDLBankName.Items.FindByValue(dr["bank_id"].ToString()));
DDLBankName.SelectedValue = dr["bank_id"].ToString();
txtMICRCode.Text = dr["pm_bank_micr"].ToString();
txtBankBranch.Text = dr["pm_bank_branch"].ToString();
txtInstrumentNo.Text = dr["pm_instrument_no"].ToString();
txtInstrumentDate.Text = dr["progDateInstrument"].ToString();
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
}
//*Code for Filling Supplier DropDown List with Suppliers Name*//

private ArrayList GetInvoiceNo(string strInvoice)
{
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());
}
}
return arrInvoice;
}

private void DisplayInvoice(string strInvoice)
{

chkboxlistInvoice.DataSource = GetInvoiceNo(strInvoice);
chkboxlistInvoice.DataBind();
CheckAll();

}

private void CheckAll()
{
foreach (ListItem list in chkboxlistInvoice.Items)
{
list.Selected = true;
}
}

private void SupplierName()
{
using (SqlConnection SuppConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDLSupplierName.Items.Clear();
SuppConn.Open();
string suppstr = "select supl_id,supl_name from tblSupplierMaster where supl_active='Yes' and supl_delete='No'";
SqlCommand SuppCom = new SqlCommand(suppstr, SuppConn);
SqlDataReader SuppDR = SuppCom.ExecuteReader();
if (SuppDR.HasRows)
{
ListItem insertSuppName;
while (SuppDR.Read())
{
insertSuppName = new ListItem(SuppDR["supl_name"].ToString(), SuppDR["supl_id"].ToString());
DDLSupplierName.Items.Add(insertSuppName);
}
insertSuppName = new ListItem("Select--------------------->");
DDLSupplierName.Items.Insert(0, insertSuppName);
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
SuppConn.Close();
}
}
}

//*Code for Filling Bank DropDown List with Bank Name*//
private void BankName()
{
using (SqlConnection SuppConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDLBankName.Items.Clear();
SuppConn.Open();
string suppstr = "select bank_id,bank_name from tblBankMaster where bank_active='Yes' and bank_delete='No'";
SqlCommand SuppCom = new SqlCommand(suppstr, SuppConn);
SqlDataReader SuppDR = SuppCom.ExecuteReader();
if (SuppDR.HasRows)
{
ListItem insertSuppName;
while (SuppDR.Read())
{
insertSuppName = new ListItem(SuppDR["bank_name"].ToString(), SuppDR["bank_id"].ToString());
DDLBankName.Items.Add(insertSuppName);
}
insertSuppName = new ListItem("Select--------------------->");
DDLBankName.Items.Insert(0, insertSuppName);
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
SuppConn.Close();
}
}
}

//*Code for Filling Mode DropDown List with Mode Name*//
private void ModeName()
{
using (SqlConnection SuppConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDLMode.Items.Clear();
SuppConn.Open();
string suppstr = "select pmode_id,pmode_name from tblPaymentMode where pmode_active='Yes' and pmode_delete='No'";
SqlCommand SuppCom = new SqlCommand(suppstr, SuppConn);
SqlDataReader SuppDR = SuppCom.ExecuteReader();
if (SuppDR.HasRows)
{
ListItem insertSuppName;
while (SuppDR.Read())
{
insertSuppName = new ListItem(SuppDR["pmode_name"].ToString(), SuppDR["pmode_id"].ToString());
DDLMode.Items.Add(insertSuppName);
}
insertSuppName = new ListItem("Select--------------------->");
DDLMode.Items.Insert(0, insertSuppName);
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
SuppConn.Close();
}
}
}
//*Code for Gating the Currency Name *//
private void CurrencyName()
{
using (SqlConnection SuppConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
// DDLBankName.Items.Clear();
//DDLMode.Items.Clear();
SuppConn.Open();
//where supl_active='Yes' and supl_delete='No'
if (DDLSupplierName.SelectedValue.ToString() != "Select--------------------->")
{
string suppstr = "select * from viewSupplierCurrencyForPaySent where supl_id=" + DDLSupplierName.SelectedValue.ToString() + "";

SqlCommand SuppCom = new SqlCommand(suppstr, SuppConn);
SqlDataReader SuppDR = SuppCom.ExecuteReader();
if (SuppDR.HasRows)
{

while (SuppDR.Read())
{
lblCurrency.Text = SuppDR["currency_name"].ToString();
Session["CurrencyId"] = SuppDR["currency_id"].ToString();
}

}
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
SuppConn.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_tblPaymentMade", PaymentConn);
PaymantCom.CommandType = CommandType.StoredProcedure;
PaymantCom.Parameters.Add(new SqlParameter("@supl_id", DDLSupplierName.SelectedValue.ToString()));
//PaymantCom.Parameters.Add(new SqlParameter("@supl_invoice_no", ltboxInvoiceNo.Text));
string StrDate = txtDate.Text.Substring(3, 2) + "/" + txtDate.Text.Substring(0, 2) + "/" + txtDate.Text.Substring(6, 4);
PaymantCom.Parameters.Add(new SqlParameter("@pm_date", StrDate.ToString()));
PaymantCom.Parameters.Add(new SqlParameter("@pmode_id", DDLMode.SelectedValue ));
PaymantCom.Parameters.Add(new SqlParameter("@pm_amount", txtAmount.Text));
PaymantCom.Parameters.Add(new SqlParameter("@pm_currency", lblCurrency.Text));
PaymantCom.Parameters.Add(new SqlParameter("@bank_id", DDLBankName.SelectedValue.ToString()));
PaymantCom.Parameters.Add(new SqlParameter("@pm_bank_micr", txtMICRCode.Text));
PaymantCom.Parameters.Add(new SqlParameter("@pm_instrument_no", txtInstrumentNo.Text));
PaymantCom.Parameters.Add(new SqlParameter("@pm_bank_branch", txtBankBranch.Text));
string StrInstrDate = txtDate.Text.Substring(3, 2) + "/" + txtDate.Text.Substring(0, 2) + "/" + txtDate.Text.Substring(6, 4);
PaymantCom.Parameters.Add(new SqlParameter("@pm_instrument_date", StrInstrDate.ToString()));

PaymantCom.Parameters.Add(new SqlParameter("@pm_cheque_status","Unrealised"));
PaymantCom.Parameters.Add(new SqlParameter("@pm_created_by", 2));
PaymantCom.Parameters.Add(new SqlParameter("@pm_active", "Yes"));
PaymantCom.Parameters.Add(new SqlParameter("@pm_delete", "No"));
// PaymantCom.Parameters.Add(new SqlParameter("@pm_instrument_date", txtInstrumentDate.Text));
PaymantCom.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
PaymentConn.Close();
}
}
}

protected void btnCancel_click(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
Response.Redirect("viewpaymentsent.aspx");
}
else
{
Response.Redirect("adminhome.aspx");
}
}
protected void btnSubmit_click(object sender, EventArgs e)
{

//insertPaymentSent();
//Response.Redirect("paymentsentdetail.aspx");
}

//*Code for update the paymentsent*//
private void UpdatePaymentSent()
{
string InvoiceEdit=String.Empty;
using (SqlConnection PaymentConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
PaymentConn.Open();
SqlCommand PaymantCom = new SqlCommand("update_tblPaymentMade", PaymentConn);
PaymantCom.CommandType = CommandType.StoredProcedure;
PaymantCom.Parameters.Add(new SqlParameter("@pm_id", Request.QueryString["id"]));
PaymantCom.Parameters.Add(new SqlParameter("@supl_id", DDLSupplierName.SelectedValue.ToString()));
string InvoiceNo = Session["InvoiceId"].ToString();
foreach (ListItem list in chkboxlistInvoice.Items)
{

InvoiceEdit = list.Text + "," + InvoiceEdit.ToString();
}
InvoiceEdit = InvoiceEdit.ToString().Substring(0, InvoiceEdit.ToString().Length-1);

//Session["InvoiceNo"] = Session["InvoiceNo"].ToString().Substring(0,Session["InvoiceNo"].ToString().Length-1);
PaymantCom.Parameters.Add(new SqlParameter("@supl_invoice_no", InvoiceEdit));

string StrDate = txtDate.Text.Substring(3, 2) + "/" + txtDate.Text.Substring(0, 2) + "/" + txtDate.Text.Substring(6, 4);
PaymantCom.Parameters.Add(new SqlParameter("@pm_date", StrDate.ToString()));
PaymantCom.Parameters.Add(new SqlParameter("@pmode_id", DDLMode.SelectedValue));
PaymantCom.Parameters.Add(new SqlParameter("@pm_amount", txtAmount.Text));
PaymantCom.Parameters.Add(new SqlParameter("@pm_currency", lblCurrency.Text));
PaymantCom.Parameters.Add(new SqlParameter("@bank_id", DDLBankName.SelectedValue.ToString()));
PaymantCom.Parameters.Add(new SqlParameter("@pm_bank_micr", txtMICRCode.Text));
PaymantCom.Parameters.Add(new SqlParameter("@pm_instrument_no", txtInstrumentNo.Text));
PaymantCom.Parameters.Add(new SqlParameter("@pm_bank_branch", txtBankBranch.Text));
string StrInstrDate = txtDate.Text.Substring(3, 2) + "/" + txtDate.Text.Substring(0, 2) + "/" + txtDate.Text.Substring(6, 4);
PaymantCom.Parameters.Add(new SqlParameter("@pm_instrument_date", StrInstrDate.ToString()));


//Session["ModeRealisatin"]=DDLMode.SelectedValue;

//if (DDLMode.SelectedIndex <=0 )
//{
// PaymantCom.Parameters.Add(new SqlParameter("@pm_cheque_status",DDLMode.SelectedValue));
//}
// string ModeRealisation = Session["ModeRealisation"].ToString();
if (Session["ModeRealisation"] == null)
{
PaymantCom.Parameters.Add(new SqlParameter("@pm_cheque_status", Session["ChequeStatus"].ToString()));
}
else
{
string ModeRealisation = Session["ModeRealisation"].ToString();
if (ModeRealisation == "Auto")
{
PaymantCom.Parameters.Add(new SqlParameter("@pm_cheque_status", "Realised"));
}
else if (ModeRealisation == "Manual")
{
PaymantCom.Parameters.Add(new SqlParameter("@pm_cheque_status", "UnRealised"));
}
}
// PaymantCom.Parameters.Add(new SqlParameter("@pm_cheque_status", "Yes"));
PaymantCom.Parameters.Add(new SqlParameter("@pm_edit_by", 2));
PaymantCom.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
PaymentConn.Close();
}
}

}
protected void DDLBankName_SelectedIndexChanged(object sender, EventArgs e)
{
BankMICRCode();
}
//*Code for Get the Bank's MICR*//
private void BankMICRCode()
{
using (SqlConnection BankMICRConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{

BankMICRConn.Open();
txtMICRCode.Text = "";
if (DDLBankName.SelectedValue.ToString() != "Select--------------------->")
{
string BankMICRstr = "select bank_micr from tblBankMaster where bank_id=" + DDLBankName.SelectedValue.ToString() + " and bank_active='Yes' and bank_delete='No'";
SqlCommand BankMICRCom = new SqlCommand(BankMICRstr, BankMICRConn);
SqlDataReader BankMICRDR = BankMICRCom.ExecuteReader();
if (BankMICRDR.HasRows)
{
BankMICRDR.Read();
txtMICRCode.Text = BankMICRDR["bank_micr"].ToString();
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
BankMICRConn.Close();
}
}
}
protected void DDLSupplierName_SelectedIndexChanged(object sender, EventArgs e)
{
SelectInvoiceNo();
CurrencyName();
}

//*Code for Get the Inventory No*//
private void SelectInvoiceNo()
{
using (SqlConnection BankMICRConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{

chkboxlistInvoice.Items.Clear();
if (DDLSupplierName.SelectedValue.ToString() != "Select--------------------->")
{
BankMICRConn.Open();
string BankMICRstr = "select rinv_no,supl_id from tblRecInvoice where rinv_paid='No' and supl_id=" + DDLSupplierName.SelectedValue.ToString() + " ";
SqlCommand BankMICRCom = new SqlCommand(BankMICRstr, BankMICRConn);
SqlDataReader BankMICRDR = BankMICRCom.ExecuteReader();
if (BankMICRDR.HasRows)
{
ListItem insertSuppName;
while (BankMICRDR.Read())
{
insertSuppName = new ListItem(BankMICRDR["rinv_no"].ToString(), BankMICRDR["supl_id"].ToString());
chkboxlistInvoice.Items.Add(insertSuppName);
}
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
BankMICRConn.Close();
}
}
}

//*Code for Get the Inventory No for Edit*//
private void SelectInvoiceNoForEdit()
{
using (SqlConnection BankMICRConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
chkboxlistInvoice.Items.Clear();

BankMICRConn.Open();
string BankMICRstr = "select rinv_no,supl_id from tblRecInvoice where supl_id=" + Session["Supl_id"].ToString() + " ";
SqlCommand BankMICRCom = new SqlCommand(BankMICRstr, BankMICRConn);
SqlDataReader BankMICRDR = BankMICRCom.ExecuteReader();
if (BankMICRDR.HasRows)
{
ListItem insertSuppName;
while (BankMICRDR.Read())
{
insertSuppName = new ListItem(BankMICRDR["rinv_no"].ToString(), BankMICRDR["supl_id"].ToString());
//ltboxInvoiceNo.Items.Add(insertSuppName);
chkboxlistInvoice.Items.Add(insertSuppName);
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
BankMICRConn.Close();
}
}
}
protected void BtnSave_click(object sender, EventArgs e)
{
UpdatePaymentSent();
Response.Redirect("viewpaymentsent.aspx");
}
protected void DDLMode_SelectedIndexChanged(object sender, EventArgs e)
{
ModeRealisation();
}
//*Code for Gating the ModeRealisation Name *//
private void ModeRealisation()
{
using (SqlConnection SuppConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
SuppConn.Open();
//where supl_active='Yes' and supl_delete='No' tblPaymentMode ,pmode_realisation
if (DDLMode.SelectedValue.ToString() != "Select--------------------->")
{
string suppstr = "select * from tblPaymentMode where pmode_id=" + DDLMode.SelectedValue.ToString() + "";
SqlCommand SuppCom = new SqlCommand(suppstr, SuppConn);
SqlDataReader SuppDR = SuppCom.ExecuteReader();
if (SuppDR.HasRows)
{
SuppDR.Read();
Session["ModeRealisation"] = SuppDR["pmode_realisation"].ToString();
}
}

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

//*Code for Deleting record for Edit *//
private void DeleteRecForEditInvoiceNo()
{
using (SqlConnection SuppConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{

SuppConn.Open();
//where supl_active='Yes' and supl_delete='No' tblPaymentMode ,pmode_realisation
string suppstr = "Delete tblPaymentMade where pm_id="+Request.QueryString["id"]+"";
SqlCommand SuppCom = new SqlCommand(suppstr, SuppConn);
SuppCom.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
SuppConn.Close();
}
}
}

}

No comments: