Monday, November 16, 2009

ViewPaymentSent !!

public partial class viewpaymentsent : System.Web.UI.Page
{
private const string ASCENDING = " ASC";
private const string DESCENDING = " DESC";
string _Strfill;
IDLDPLMain objIDLDPLMain = new IDLDPLMain();
string strPayOperation = String.Empty;
string strPayApprove = String.Empty;
DynMenu objDynMenu = new DynMenu();

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
objIDLDPLMain.AddlogDetails("View Payment Sent", Request.Url.ToString());
fillviewPayment();
}

}
//*Code for Fill The GridView*//
private void fillviewPayment()
{
using (SqlConnection ViewPayconn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
ViewPayconn.Open();
string viewpaymentstr;
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
viewpaymentstr = "select * from viewPaymentMadeNew where pm_delete='No' order by pm_id desc";
}
else
{
viewpaymentstr = "select * from viewPaymentMade where pm_delete='No' AND (loc_id = " + Session["loglocid"] + ") order by pm_id desc";
}
SqlDataAdapter viewPayDA = new SqlDataAdapter(viewpaymentstr, ViewPayconn);
DataSet ds = new DataSet();
viewPayDA.Fill(ds,"tmptable");


if (ds.Tables["tmptable"].Rows.Count == 0)
{
gviewPaymentSent.Visible = false;
hidetr.Visible = true;
EmptyMsg.Visible = true;
}
else
{
gviewPaymentSent.Visible = true;
EmptyMsg.Visible = false;
hidetr.Visible = false;
gviewPaymentSent.DataSource = ds;
gviewPaymentSent.DataBind();
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
ViewPayconn.Close();
}
}
}

//*Below 4 function ( code ) are used for Sorting*//
private void SortGridView(string sortExpression, string direction)
{
// You can cache the DataTable for improving performance
DataTable dt = GetData().Tables[0];
DataView dv = new DataView(dt);

dv.Sort = sortExpression + direction;

gviewPaymentSent.DataSource = dv;
gviewPaymentSent.DataBind();

}
private DataSet GetData()
{

SqlConnection StWConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]);

//SqlDataAdapter ad = new SqlDataAdapter("SELECT * from emplistview where emp_delete='No' order by emp_id desc", StWConn);
SqlDataAdapter ad;

if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
ad = new SqlDataAdapter("select * from viewPaymentMadeNew where pm_delete='No' order by pm_id desc", StWConn);
}
else
{
ad = new SqlDataAdapter("select * from viewPaymentMade where pm_delete='No' AND (loc_id = " + Session["loglocid"] + ") order by pm_id desc", StWConn);
}
DataSet ds = new DataSet();

ad.Fill(ds);

return ds;

}
public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
else
ViewState["sortDirection"] = SortDirection.Descending;
return (SortDirection)ViewState["sortDirection"];
}
set { ViewState["sortDirection"] = value; }
}
protected void gviewPaymentSent_Sorting(object sender, GridViewSortEventArgs e)
{
{
string sortExpression = e.SortExpression;

if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
SortGridView(sortExpression, DESCENDING);
}
else
{
GridViewSortDirection = SortDirection.Ascending;
SortGridView(sortExpression, ASCENDING);
ViewState["sortDirection"] = null;
}
}
}
protected void gviewPaymentSent_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gviewPaymentSent.PageIndex = e.NewPageIndex;
fillviewPayment();
}
protected void gviewPaymentSent_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Separator)
{
Label lblstatus = (Label)e.Row.Cells[9].FindControl("lblActive");
Label lblid = (Label)e.Row.Cells[9].FindControl("lblID");
Label lblDel = (Label)e.Row.Cells[9].FindControl("lblDel");


string status = lblstatus.Text.ToString();
string id = lblid.Text.ToString();

// \"Click Realised
// \"Click UnRealised

strPayOperation = objDynMenu.GetPermission("Accounts", "Payment Sent");


//////////////////////////Begin Approval Permission//////////////////////////////
if (strPayOperation.Length.ToString() != "0")
{
strPayOperation = strPayOperation.ToString().Substring(0, strPayOperation.Length - 1);
ArrayList myList = new ArrayList();
char[] sep ={ ',' };

string[] values = strPayOperation.Split(sep);

int i;
for (i = 0; i < values.Length; i++)
{
myList.Add(values[i]);
if (values[i].ToString().ToLower() == "approve")
{
strPayApprove = "approve";
break;
}
}
}


if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
if (status.ToString() == "Realised")
{
e.Row.Cells[7].Text = "\"Click";
}
else
{
e.Row.Cells[7].Text = "\"Click";
}
}
else if (strPayApprove.ToString() == "approve")
{
if (status.ToString() == "Realised")
{
e.Row.Cells[7].Text = "\"Click";
}
else
{
e.Row.Cells[7].Text = "\"Click";
}
}
else
{
if (status.ToString() == "Realised")
{
e.Row.Cells[7].Text = "\"Click";
}
else
{
e.Row.Cells[7].Text = "\"Click";
}
}
//////////////////////////End Approval Permission//////////////////////////////


////////////////Begin Delete Permissions////////////////////////
if (strPayOperation.Length.ToString() != "0")
{
strPayOperation = strPayOperation.ToString().Substring(0, strPayOperation.Length - 1);
ArrayList myList = new ArrayList();
char[] sep ={ ',' };
string[] values = strPayOperation.Split(sep);
int i;
for (i = 0; i < values.Length; i++)
{
myList.Add(values[i]);
if (values[i].ToString().ToLower() == "Delete")
{
lblDel.Text="";
break;
}
else if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
lblDel.Text = "";
}
else
{
lblDel.Text = "";
}
}
}
else if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
lblDel.Text = "";
}
else
{
lblDel.Text = "";
}
/////////////////End Delete Permissions///////////////////////
}
}
protected void BtnSubmit_click(object sender, EventArgs e)
{
Search();
}

//* Code for Search*//
private void Search()
{
using (SqlConnection ViewPayconn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
ViewPayconn.Open();
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = "select * from viewPaymentMadeNew ";
}
else
{
_Strfill = "select * from viewPaymentMade ";
}
string serkey;
serkey = txtSearch.Text;
if (txtSearch.Text != "")
{
if (DDLSearch.SelectedValue != "Select")
{
if (DDLSearch.SelectedValue == "Supplier Name")
{
// _Strfill = _Strfill + " where supl_name like '%" + serkey.ToString() + "%'";
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = _Strfill + " where supl_name = '" + serkey.ToString() + "'";
}
else
{
_Strfill = _Strfill + " where supl_name = '" + serkey.ToString() + "' AND (loc_id = " + Session["loglocid"] + ")";
}
}
else if (DDLSearch.SelectedValue == "Date")
{
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = _Strfill + " where progDate='" + serkey.ToString() + "'";
}
else
{
_Strfill = _Strfill + " where progDate='" + serkey.ToString() + "' AND (loc_id = " + Session["loglocid"] + ")";
}
}
else if (DDLSearch.SelectedValue == "Mode")
{
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = _Strfill + " where pmode_name='" + serkey.ToString() + "'";
}
else
{
_Strfill = _Strfill + " where pmode_name='" + serkey.ToString() + "' AND (loc_id = " + Session["loglocid"] + ")";
}
}
else if (DDLSearch.SelectedValue == "Currency")
{
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = _Strfill + " where pm_Currency='" + serkey.ToString() + "'";
}
else
{
_Strfill = _Strfill + " where pm_Currency='" + serkey.ToString() + "' AND (loc_id = " + Session["loglocid"] + ")";
}
}

}
}
// _Strfill = _Strfill + " order by pm_id desc";
PopulateSearchGrid(_Strfill);

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

public void PopulateSearchGrid(string StrKey)
{
try
{
using (SqlConnection IDLDPLConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
IDLDPLConn.Open();
SqlDataAdapter IDLDPLda = new SqlDataAdapter(StrKey.ToString(), IDLDPLConn);
DataSet IDLDPLds = new DataSet();
IDLDPLda.Fill(IDLDPLds,"Temp");
if (IDLDPLds.Tables["Temp"].Rows.Count == 0)
{
gviewPaymentSent.Visible = false;
hidetr.Visible = true;
EmptyMsg.Visible = true;
}
else
{
gviewPaymentSent.Visible = true;
EmptyMsg.Visible = false;
hidetr.Visible = false;
gviewPaymentSent.DataSource = IDLDPLds;
gviewPaymentSent.DataBind();
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}

}

No comments: