Tuesday, August 10, 2010

What are the main components of WCF ?

Dev Palmistry

What are the main components of WCF ?

The main components of WCF are

1. Service class
2. Hosting environment
3. End point

What was the code name for WCF ?

Dev Palmistry

What was the code name for WCF ?

The code name of WCF was Indigo .

WCF is a unification of .NET framework communication technologies which unites the following technologies:-

NET remoting
MSMQ
Web services
COM+

What are various ways of hosting WCF Services ?

What are various ways of hosting WCF Services?

There are three major ways of hosting a WCF services

• Self-hosting the service in his own application domain. This we have already covered in the first section. The service comes in to existence when you create the object of Service Host class and the service closes when you call the Close of the Service Host class.

• Host in application domain or process provided by IIS Server.

• Host in Application domain and process provided by WAS (Windows Activation Service) Server.

What is the difference WCF and Web services ?

What is the difference WCF and Web services ?

Web services can only be invoked by HTTP (traditional webservice with .asmx). While WCF Service or a WCF component can be invoked by any protocol (like http, tcp etc.) and any transport type.

Second web services are not flexible. However, WCF Services are flexible. If you make a new version of the service then you need to just expose a new end. Therefore, services are agile and which is a very practical approach looking at the current business trends.

We develop WCF as contracts, interface, operations, and data contracts. As the developer we are more focused on the business logic services and need not worry about channel stack. WCF is a unified programming API for any kind of services so we create the service and use configuration information to set up the communication mechanism like HTTP/TCP/MSMQ etc

What is three major points in WCF ?

What is three major points in WCF ?

We Should remember ABC.

Address --- Specifies the location of the service which will be like http://Myserver/MyService.Clients will use this location to communicate with our service.

Binding --- Specifies how the two paries will communicate in term of transport and encoding and protocols

Contract --- Specifies the interface between client and the server.It's a simple interface with some attribute.

What are the various ways of hosting a WCF service ?

What are the various ways of hosting a WCF service ?

Self hosting the service in his own application domain. This we have already covered in the first section. The service comes in to existence when you create the object of ServiceHost class and the service closes when you call the Close of the ServiceHost class.
Host in application domain or process provided by IIS Server.
Host in Application domain and process provided by WAS (Windows Activation Service) Server.

Difference between WCF and Web services ?

Difference between WCF and Web services ?

Web Services

1.It Can be accessed only over HTTP
2.It works in stateless environment

WCF

WCF is flexible because its services can be hosted in different types of applications. The following lists several common scenarios for hosting WCF services:
IIS
WAS
Self-hosting
Managed Windows Service

What is WCF ?

What is WCF?

Answer :

Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for services, enabling you to expose CLR types as services, and to consume other services as CLR types.

WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on systems that support it.



WCF is Microsoft’s unified programming model for building service-oriented applications with managed code. It extends the .NET Framework to enable developers to build secure and reliable transacted Web services that integrate across platforms and interoperate with existing investments.




WCF ---Windows communication foundation is a feature in .NET 3.5 framework.

As we have the webservice in the earlier versions, we have in addition WCF in 3.5.

The main advantage with WCF is
1) you can create one service that can be binded with multiple protocols, like HTTP, TCP,SecureHTTP.

so if you want to connect with HTTP you can use the endpoint http, and so on.

Here we have the concept 'ABC'
that is Address, Binding and Contract.
Here we create more than one endpoint with different bindings.
And you can use one of the binding well suited for your application.
For windows you can TCP, and for web based you can use HTTP or secure HTTP.






Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data. A few sample scenarios include:

* A secure service to process business transactions.

* A service that supplies current data to others, such as a traffic report or other monitoring service.

* A chat service that allows two people to communicate or exchange data in real time.

* A dashboard application that polls one or more services for data and presents it in a logical presentation.

* Exposing a workflow implemented using Windows Workflow Foundation as a WCF service.

* A Silverlight application to poll a service for the latest data feeds.

While creating such applications was possible prior to the existence of WCF, WCF makes the development of endpoints easier than ever. In summary, WCF is designed to offer a manageable approach to creating Web services and Web service clients.

Wednesday, June 30, 2010

Friday, November 20, 2009

OutPut Stored Procedure !!

CREATE procedure guest_regi
@memname varchar(50),
@mememail varchar(50),
@memphone varchar(50),
@memregtype varchar(50),
@memactive int,
@gid int output
as
insert into tblmemregistration
(
memname,
mememail,
memphone,
memregtype,
memactive
)

values
(
@memname,
@mememail,
@memphone,
@memregtype,
@memactive
)

select @gid=@@IDENTITY


GO

Tuesday, November 17, 2009

GridView !!

asp:GridView ID="GDcomp" runat="server" border="0" cellpadding="5" cellspacing="1" bgcolor="#ffffff" AutoGenerateColumns="false" AllowPaging="true" Width="100%" OnRowDataBound="GDcomp_RowDataBound" OnPageIndexChanging="GDcomp_PageIndexChanging" PageSize="10" AllowSorting="True" OnSorting="GDcomp_Sorting" ForeColor="Black">
Columns>

asp:TemplateField HeaderText="S. No.">
ItemTemplate>
<%#(GDcomp.PageIndex * 10) + Container.DisplayIndex + 1%>
/ItemTemplate>
ItemStyle BackColor="#F4F0E1" HorizontalAlign="Center" Width="6%" />
HeaderStyle BackColor="#D3CCB5" HorizontalAlign="Center" Width="6%" />
/asp:TemplateField >
asp:TemplateField HeaderText="Company Name" SortExpression="comp_name">


ItemTemplate>
a href="CompanyDetail.aspx?id=<%# DataBinder.Eval(Container, "DataItem.comp_id") %> " class="black"><%# DataBinder.Eval(Container, "DataItem.comp_name") %>
/ItemTemplate>
ItemStyle BackColor="#F4F0E1" HorizontalAlign="Center" Width="12%" />
HeaderStyle BackColor="#D3CCB5" HorizontalAlign="Center" Width="12%" />
/asp:TemplateField>



asp:BoundField DataField="comp_contact_person" HeaderText="Contact Person" SortExpression="comp_contact_person">
ItemStyle BackColor="#F4F0E1" HorizontalAlign="Center" Width="12%" />
HeaderStyle BackColor="#D3CCB5" HorizontalAlign="Center" Width="12%" />
/asp:BoundField>
asp:BoundField DataField="country_name" HeaderText="Country" SortExpression="country_name">
ItemStyle BackColor="#F4F0E1" HorizontalAlign="Center" Width="8%" />
HeaderStyle BackColor="#D3CCB5" HorizontalAlign="Center" Width="8%" />
asp:BoundField DataField="comp_state" HeaderText="State" SortExpression="comp_state">
ItemStyle BackColor="#F4F0E1" HorizontalAlign="Center" Width="10%" />
HeaderStyle BackColor="#D3CCB5" HorizontalAlign="Center" Width="10%" />
/asp:BoundField>
asp:BoundField DataField="comp_city" HeaderText="City" SortExpression="comp_city">
ItemStyle BackColor="#F4F0E1" HorizontalAlign="Center" Width="9%" />
HeaderStyle BackColor="#D3CCB5" HorizontalAlign="Center" Width="8%" />
/asp:BoundField>
asp:TemplateField HeaderText="Edit" >
itemtemplate>
a href="CompanyMaster.aspx?action=edit&ID=<%# DataBinder.Eval(Container, "DataItem.comp_id") %>" class="black">
/itemtemplate>
ItemStyle BackColor="#F4F0E1" HorizontalAlign="Center" Width="6%" />
HeaderStyle BackColor="#D3CCB5" HorizontalAlign="Center" Width="6%" />
/asp:TemplateField>
asp:BoundField DataField="comp_active" HeaderText="Status" >
ItemStyle BackColor="#F4F0E1" HorizontalAlign="Center" Width="6%" />
HeaderStyle BackColor="#D3CCB5" HorizontalAlign="Center" Width="6%" />
/asp:BoundField>
asp:TemplateField HeaderText="Delete">
itemtemplate>


/itemtemplate>
ItemStyle BackColor="#F4F0E1" HorizontalAlign="Center" Width="6%" />
HeaderStyle BackColor="#D3CCB5" HorizontalAlign="Center" Width="6%" />
/asp:TemplateField>
asp:TemplateField Visible="False" HeaderText="ad">
itemtemplate>
asp:Label ID="lblid" Text='<%#DataBinder.Eval(Container.DataItem,"comp_id")%>' runat="server">



/itemtemplate>
/asp:TemplateField>
/Columns>
PagerStyle BackColor="#BDB391" HorizontalAlign="Center" />
/asp:GridView>

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();
}
}
}
}

Monday, November 16, 2009

Login !!

using rangtarang.Connection;


public partial class adminindex : System.Web.UI.Page
{
GetConnection objCon = new GetConnection();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
txtuser.Focus();
}

}
protected void imgbtn_Click(object sender, ImageClickEventArgs e)
{
Login();
}

private void Login()
{
try
{
if (objCon.sqlConn.State == ConnectionState.Closed)
{
objCon.OpenConnection();
}

SqlCommand sqlquery = new SqlCommand("select * from tblAdmin where login_id='" + txtuser.Text + "' And login_pwd='" + txtpwd.Text + "' And login_active=1", objCon.sqlConn);
SqlDataReader loginReader = sqlquery.ExecuteReader();
if (loginReader.HasRows)
{
loginReader.Read();
if (loginReader["login_id"].ToString() == txtuser.Text && loginReader["login_pwd"].ToString() == txtpwd.Text)
{
lblerror.Visible = false;
Session["LoginId"] = loginReader["login_id"].ToString();
Session["AdminId"] = loginReader["login_pwd"].ToString();
Session["adminVALIDUSER"] = "true";
Session["AdminName"] = loginReader["admin_name"].ToString();
Session.Timeout = 30;
Response.Redirect("adminHome.aspx");
}
}
else
{
lblerror.Visible = true;
lblerror.ForeColor = System.Drawing.Color.Red;
lblerror.Text = "Invalid login-id or password !";
}
}
catch (Exception ex)
{
lblerror.Visible = true;
lblerror.ForeColor = System.Drawing.Color.Red;
lblerror.Text = "Error:" + ex.Message;
}
}
}

Master_Login !!

public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["adminVALIDUSER"] == null)
{
Response.Redirect("adminindex.aspx");
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
Response.Expires = -1500;
Response.CacheControl = "no-cache";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetAllowResponseInBrowserHistory(false);

Session.Abandon();

Session["AdminId"] = null;
Session["LoginId"] = null;
Session["adminVALIDUSER"] = null;
Session["AdminName"] = null;
Response.Redirect("adminindex.aspx");

}
}

WebConfig !!

appSettings>

add key="rangadmin" value="server=devesh;database=RAngTarang;Integrated Security=SSPI"/>
add key="VideoPath" value="videouploads">
/appSettings>

EditCompany !!

public partial class EditCompany : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
selectCompDetails();
insertContPerDetail();
//addCountry();
}
private void selectCompDetails()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();
string id=Request.QueryString["id"].ToString();
string str = "select * from tblCompanyMaster where comp_id="+id+"";
SqlCommand com = new SqlCommand(str,conn);
SqlDataReader dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
txtCompName.Text = dr["comp_name"].ToString();
txtaddr1.Text = dr["comp_addr1"].ToString();
txtaddr2.Text = dr["comp_addr2"].ToString();
txtPin.Text = dr["comp_city"].ToString();
DDState.SelectedItem.Text =dr["comp_state"].ToString();
DDCountry.SelectedIndex = DDCountry.Items.IndexOf(DDCountry.Items.FindByValue(dr["comp_country"].ToString()));
txtPin.Text = dr["comp_pin"].ToString();
txtCompPhone.Text = dr["comp_phone"].ToString();
txtCompMobile.Text = dr["comp_mobile"].ToString();
txtCompFax.Text = dr["comp_fax"].ToString();
txtCompEmail.Text = dr["comp_email"].ToString();
txtWebsit.Text = dr["comp_website"].ToString();
txtVatNo.Text = dr["comp_vat_no"].ToString();
txtTin_CstNo.Text = dr["comp_tin_cst_no"].ToString();
}


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

}

}
private void insertContPerDetail()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();

string str = "select * from tblEmployeeMaster where emp_id=" + DDName.SelectedValue.ToString() + "";
SqlCommand insertCom = new SqlCommand(str, conn);
SqlDataReader dr = insertCom.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
txtContPersName.Text = dr["emp_name"].ToString();
txtDesi.Text = dr["emp_designation"].ToString();
txtCPPhone.Text = dr["emp_phone"].ToString(); ;
txtCPMobile.Text = dr["emp_mobile"].ToString(); ;
txtCPFax.Text = dr["emp_fax"].ToString(); ;
txtCPEmail.Text = dr["emp_email"].ToString(); ;

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

}
private void addCountry()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDCountry.Items.Clear();
conn.Open();
string str = "select country_name,country_id from tblCountryMaster";
ListItem Locat;
SqlCommand insertCom = new SqlCommand(str, conn);
SqlDataReader userReader = insertCom.ExecuteReader();
if (userReader.HasRows)
{
while (userReader.Read())
{
ListItem insert;
insert = new ListItem(userReader["country_name"].ToString(), userReader["country_id"].ToString());
DDCountry.Items.Add(insert);

}
}

Locat = new ListItem("Select--------------------->");
DDCountry.Items.Insert(0, Locat);
userReader.Close();

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

}

}
protected void tbSubmit_Click(object sender, EventArgs e)
{

}
}

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();
}
}
}

}

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());
}
}

}

AddLocation !!

protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
if (Request.QueryString["action"].ToString() == "edit")
{
if (!Page.IsPostBack)
{
lblLocation.Text = "Edit Location";
btnSubmit.Text = "Save";
addLocType();
addCompName();
addCountry();
FillLocationDetail();

}
}
else if (Request.QueryString["action"].ToString() == "copy")
{
if (!Page.IsPostBack)
{
lblLocation.Text = "Copy Location";
btnSubmit.Text = "Save";
addLocType();
addCompName();
addCountry();
FillLocationDetail();
//addCountry();
}


}
}
else
{
if (!Page.IsPostBack)
{
addLocType();
addCompName();
addCountry();
}
}
}

######################################

// Add Company Location Type

private void addLocType()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDCountry.Items.Clear();
conn.Open();
string str = "select loc_type_name,loc_type_id from tblLocationType where loc_type_active='Yes' and loc_type_delete='No'";
ListItem Locat;
SqlCommand insertCom = new SqlCommand(str, conn);
SqlDataReader userReader = insertCom.ExecuteReader();
if (userReader.HasRows)
{
while (userReader.Read())
{
ListItem insert;
insert = new ListItem(userReader["loc_type_name"].ToString(), userReader["loc_type_id"].ToString());
DDLocation.Items.Add(insert);

}
}

Locat = new ListItem("Select--------------------->");
DDLocation.Items.Insert(0, Locat);
userReader.Close();

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

}

}

##########################################

// Add Company Name

private void addCompName()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDCountry.Items.Clear();
conn.Open();
string str = "select comp_name,comp_id from tblCompanyMaster where comp_active='Yes' and comp_delete='No'";
ListItem Locat;
SqlCommand insertCom = new SqlCommand(str, conn);
SqlDataReader userReader = insertCom.ExecuteReader();
if (userReader.HasRows)
{
while (userReader.Read())
{
ListItem insert;
insert = new ListItem(userReader["comp_name"].ToString(), userReader["comp_id"].ToString());
DDCompName.Items.Add(insert);

}
}

Locat = new ListItem("Select--------------------->");
DDCompName.Items.Insert(0, Locat);
userReader.Close();

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

}

}

#######################################

// Add Country
private void addCountry()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDCountry.Items.Clear();
conn.Open();
string str = "select country_name,country_id from tblCountryMaster where country_active='Yes'and country_delete='No'";
ListItem Locat;
SqlCommand insertCom = new SqlCommand(str, conn);
SqlDataReader userReader = insertCom.ExecuteReader();
if (userReader.HasRows)
{
while (userReader.Read())
{
ListItem insert;
insert = new ListItem(userReader["country_name"].ToString(), userReader["country_id"].ToString());
DDCountry.Items.Add(insert);

}
}

Locat = new ListItem("Select--------------------->");
DDCountry.Items.Insert(0, Locat);
userReader.Close();

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

}

}

###################################################

// Add Company Location
private void LocationAdd()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();
SqlCommand comLocation = new SqlCommand("insert_tblLocationMaster", conn);
comLocation.CommandType = CommandType.StoredProcedure;
comLocation.Parameters.Add(new SqlParameter("@comp_id", DDCompName.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_type_id", DDLocation.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_name", txtLocName.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_contect_person", txtContPerson.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_addr1", txtaddr1.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_addr2", txtaddr2.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_city", txtcity.Text));


if (DDState.SelectedItem.Text == "Others")
{
comLocation.Parameters.Add(new SqlParameter("@loc_state", txtother.Text));
}
else
{
comLocation.Parameters.Add(new SqlParameter("@loc_state", DDState.SelectedItem.Text));
}

// comLocation.Parameters.Add(new SqlParameter("@loc_state", DDState.SelectedItem.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_country", DDCountry.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_pin", txtpin.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_phone", txtphone.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_mobile", txtmobile.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_fax", txtfax.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_email", txtemail.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_active", "Yes"));
comLocation.Parameters.Add(new SqlParameter("@loc_delete", "No"));
comLocation.Parameters.Add(new SqlParameter("@loc_add_by", int.Parse(Session["EmpID"].ToString())));
//comLocation.Parameters.Add(new SqlParameter("@loc_add_date", "No"));

comLocation.ExecuteNonQuery();


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

}


}


}
private void FillLocationDetail()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();

string id = Request.QueryString["id"].ToString();
// string str = "select * from tblLocationMaster ";
string str = "select * from viewLocationDetail where loc_id=@Locid";


SqlCommand com = new SqlCommand(str, conn);
SqlParameter LOCID = new SqlParameter("@Locid", SqlDbType.Int, 4);
LOCID.Value = Request.QueryString["id"];
com.Parameters.Add(LOCID);
SqlDataReader dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
DDCompName.SelectedIndex = DDCompName.Items.IndexOf(DDCompName.Items.FindByValue(dr["comp_id"].ToString()));
DDLocation.SelectedIndex = DDLocation.Items.IndexOf(DDLocation.Items.FindByValue(dr["loc_type_id"].ToString()));
txtLocName.Text = dr["loc_name"].ToString();
ViewState["locName"] = dr["loc_name"].ToString();

txtContPerson.Text = dr["loc_contect_person"].ToString();
txtaddr1.Text = dr["loc_addr1"].ToString();
txtaddr2.Text = dr["loc_addr2"].ToString();
txtcity.Text = dr["loc_city"].ToString();
// DDState.SelectedItem.Text = dr["loc_state"].ToString();
DDCountry.SelectedIndex = DDCountry.Items.IndexOf(DDCountry.Items.FindByValue(dr["loc_country"].ToString()));
if (DDCountry.SelectedIndex > 0)
{
DDState.SelectedIndex = DDState.Items.IndexOf(DDState.Items.FindByText(dr["loc_state"].ToString()));
if (DDState.SelectedIndex <= 0)
{

txtother.Visible = true;
txtother.Text = dr["loc_state"].ToString();
DDState.SelectedIndex = DDState.Items.Count - 1;

}
}
else
{
txtother.Visible = false;

}
txtpin.Text = dr["loc_pin"].ToString();
txtphone.Text = dr["loc_phone"].ToString();
txtmobile.Text = dr["loc_mobile"].ToString();
txtfax.Text = dr["loc_fax"].ToString();
txtemail.Text = dr["loc_email"].ToString();

}

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

}

}
/*This code is used for update the LocationDetail*/
private void UpdateLocationDetail()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();
SqlCommand comLocation = new SqlCommand("update_tblLocationMaster1", conn);
comLocation.CommandType = CommandType.StoredProcedure;
string id = Request.QueryString["id"].ToString();
comLocation.Parameters.Add(new SqlParameter("@loc_id", id));
comLocation.Parameters.Add(new SqlParameter("@comp_id", DDCompName.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_type_id", DDLocation.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_name", txtLocName.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_contect_person", txtContPerson.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_addr1", txtaddr1.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_addr2", txtaddr2.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_city", txtcity.Text));


if (DDState.SelectedItem.Text == "Others")
{
comLocation.Parameters.Add(new SqlParameter("@loc_state", txtother.Text));
}
else
{
comLocation.Parameters.Add(new SqlParameter("@loc_state", DDState.SelectedItem.Text));
}

// comLocation.Parameters.Add(new SqlParameter("@loc_state", DDState.SelectedItem.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_country", DDCountry.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_pin", txtpin.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_phone", txtphone.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_mobile", txtmobile.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_fax", txtfax.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_email", txtemail.Text));

comLocation.Parameters.Add(new SqlParameter("@loc_edit_by", int.Parse(Session["EmpID"].ToString())));

comLocation.ExecuteNonQuery();

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

}


}


}

protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
if (Request.QueryString["action"].ToString() == "edit")
{
UpdateLocationDetail();
Response.Redirect("viewlocation.aspx");
}
else if (Request.QueryString["action"].ToString() == "copy")
{
checkLocationStauts();

}
}
else
{
checkLocationStauts();
//LocationAdd();
//Response.Redirect("viewlocation.aspx");

}
}
public void checkLocationStauts()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{

try
{
lblmsg.Text = "";
conn.Open();
// string str = "select * from tblLocationMaster where loc_name='" + ViewState["locName"] + "'";
string str = "select * from tblLocationMaster where loc_name='" + txtLocName.Text + "'";
SqlCommand chkCom = new SqlCommand(str,conn);
SqlDataReader dr = chkCom.ExecuteReader();
if (dr.HasRows)
{

dr.Read();
lblmsg.Text="Location name already exists!";
}
else
{
LocationAdd();
Response.Redirect("viewlocation.aspx",false);
//checkLocationStauts();
}
}
catch (Exception ex)
{
Response.Redirect(ex.Message.ToString());
}
finally
{
conn.Close();
}
}


}
protected void btCancle_Click(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
Response.Redirect("viewlocation.aspx");
}
else
{
Response.Redirect("adminhome.aspx");
}
}
protected void DDState_SelectedIndexChanged(object sender, EventArgs e)
{
if (DDState.SelectedItem.Text == "Others")
{

txtother.Visible = true;
}
else
{
txtother.Visible = false;
}

}
protected void DDCountry_SelectedIndexChanged(object sender, EventArgs e)
{
if (DDCountry.SelectedItem.Text != "India")
{
DDState.SelectedValue = "Others";
txtother.Visible = true;
// lblStar.Visible = true;
this.txtother.Focus();
}
else
{
txtother.Visible = false;
DDState.SelectedValue = DDState.SelectedValue.ToString();
// DDState.SelectedIndex = 0;
// lblStar.Visible = false;

}
}