|
What a way to explain, in-detail, anyone can understand.
|
|
|
|
|
how do you get the url to consume the webservice with something like httpwebresponse or webclient?
|
|
|
|
|
|
HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Crud.aspx.cs" Inherits="Crud" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.GridviewDiv {font-size: 100%; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helevetica, sans-serif; color: #303933;}
.headerstyle
{
color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;background-color: #df5015;padding .5em 0.5em 0.5em 0.5em;text-align:center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
Search:
<asp:TextBox ID="txtSearch" runat="server" />
<asp:Button ID="Button1" Text="Search" runat="server" OnClick="Search" />
<hr />
<div class="GridviewDiv">
<asp:GridView runat="server" ID="gvDetails" ShowFooter="true" AllowPaging="true"
PageSize="10" AutoGenerateColumns="false" DataKeyNames="productid,productname"
OnPageIndexChanging="gvDetails_PageIndexChanging" OnRowCancelingEdit="gvDetails_RowCancelingEdit"
OnRowEditing="gvDetails_RowEditing" OnRowUpdating="gvDetails_RowUpdating"
OnRowDeleting="gvDetails_RowDeleting" OnRowCommand ="gvDetails_RowCommand"
onselectedindexchanged="gvDetails_SelectedIndexChanged" >
<HeaderStyle CssClass="headerstyle" />
<Columns>
<asp:BoundField DataField="productid" HeaderText="Product Id" ReadOnly="true" />
<asp:TemplateField HeaderText="Product Name">
<ItemTemplate>
<asp:Label ID="lblProductname" runat="server" Text='<%# Eval("productname")%>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtProductname" runat="server" Text='<%# Eval("productname")%>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtpname" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Price">
<ItemTemplate>
<asp:Label ID="lblPrice" runat="server" Text='<%# Eval("price")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtProductprice" runat="server" Text='<%# Eval("price")%>'/>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtprice" runat="server" />
<asp:Button ID="btnAdd" CommandName="AddNew" runat="server" Text="Add" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ShowDeleteButton="true" />
</Columns>
</asp:GridView>
<asp:Label ID="lblresult" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
SQL:
CREATE PROCEDURE CrudOperations
@productid int = 0,
@productname varchar(50)=null,
@price int=0,
@status varchar(50)
AS
BEGIN
SET NOCOUNT ON;
--- Insert New Records
IF @status='INSERT'
BEGIN
INSERT INTO product(productname,price) VALUES(@productname,@price)
END
--- Select Records in Table
IF @status='SELECT'
BEGIN
SELECT productid,productname,price FROM product
END
--- Update Records in Table
IF @status='UPDATE'
BEGIN
UPDATE product SET productname=@productname,price=@price WHERE productid=@productid
END
--- Delete Records from Table
IF @status='DELETE'
BEGIN
DELETE FROM product where productid=@productid
END
SET NOCOUNT OFF
END
|
|
|
|
|
using System;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Configuration;
public partial class Crud : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
SqlCommand cmd = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridview();
}
}
protected void BindGridview()
{<br />
if (ConnectionState.Closed == con.State) { con.Open(); }
SqlCommand cmd = new SqlCommand("CrudOperations", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@status", "SELECT");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ConnectionState.Open == con.State) { con.Close(); }
if (ds.Tables[0].Rows.Count > 0)
{
gvDetails.DataSource = ds;
gvDetails.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gvDetails.DataSource = ds;
gvDetails.DataBind();
int columncount = gvDetails.Rows[0].Cells.Count;
gvDetails.Rows[0].Cells.Clear();
gvDetails.Rows[0].Cells.Add(new TableCell());
gvDetails.Rows[0].Cells[0].ColumnSpan = columncount;
gvDetails.Rows[0].Cells[0].Text = "No Records Found";
}
}
protected void gvDetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{
TextBox txtname = (TextBox)gvDetails.FooterRow.FindControl("txtpname");
TextBox txtprice = (TextBox)gvDetails.FooterRow.FindControl("txtprice");
crudoperations("INSERT", txtname.Text, txtprice.Text, 0);
}
}
protected void gvDetails_RowEditing(object sender, GridViewEditEventArgs e)
{
gvDetails.EditIndex = e.NewEditIndex;
BindGridview();
}
protected void gvDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvDetails.EditIndex = -1;
BindGridview();
}
protected void gvDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvDetails.PageIndex = e.NewPageIndex;
BindGridview();
}
protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int productid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["productid"].ToString());
TextBox txtname = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtProductname");
TextBox txtprice = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtProductprice");
crudoperations("UPDATE", txtname.Text, txtprice.Text, productid);
}
protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int productid = Convert.ToInt32(gvDetails.DataKeys[e.RowIndex].Values["productid"].ToString());
string productname = gvDetails.DataKeys[e.RowIndex].Values["productname"].ToString();
crudoperations("DELETE", productname, "", productid);
}
protected void crudoperations(string status, string productname, string price, int productid)
{
if (ConnectionState.Closed == con.State) { con.Open(); }
SqlCommand cmd = new SqlCommand("CrudOperations", con);
cmd.CommandType = CommandType.StoredProcedure;
if (status == "INSERT")
{
cmd.Parameters.AddWithValue("@status", status);
cmd.Parameters.AddWithValue("@productname", productname);
cmd.Parameters.AddWithValue("@price", price);
}
else if (status == "UPDATE")
{
cmd.Parameters.AddWithValue("@status", status);
cmd.Parameters.AddWithValue("@productname", productname);
cmd.Parameters.AddWithValue("@price", price);
cmd.Parameters.AddWithValue("@productid", productid);
}
else if (status == "DELETE")
{
cmd.Parameters.AddWithValue("@status", status);
cmd.Parameters.AddWithValue("@productid", productid);
}
cmd.ExecuteNonQuery();
lblresult.ForeColor = Color.Green;
lblresult.Text = productname + " details " + status.ToLower() + "d successfully";
gvDetails.EditIndex = -1;
BindGridview();
}
protected void gvDetails_SelectedIndexChanged(object sender, EventArgs e)
{
BindGridview();
}
protected void Search(object sender, EventArgs e)
{
cmd.CommandText = "SELECT productid, productname, price FROM product WHERE productname LIKE '%' + @productname + '%'";
cmd.Connection = con;
cmd.Parameters.AddWithValue("@productname", txtSearch.Text.Trim());
DataTable dt = new DataTable();
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
gvDetails.DataSource = dt;
gvDetails.DataBind();
}
}
}
modified 29-Jan-16 5:30am.
|
|
|
|
|
Hi. So I'm developing a desktop software in C#.NET which apparently might need web service to be incorporated. So the application is supposed to connect to a remote MySQL/SQL server and read some value and display it.
My problem? I read that server companies might not allow you to have a desktop application directly connect to their databases for security reasons, and so I should kind of have a web service that will connect to a script in the server to retrieve the data to be displayed in the end user's C# desktop application.
I have researched extensively on writing a web service that connects to a script on the server, to do this task that I have in mind, but I have not come across the most right on answers.
So if someone can be able to give some very good step by step instruction for a semi-skilled C# programmer, I would really appreciate it. Thanks.
Kevin Barasa
|
|
|
|
|
Se puede entender la idea, pero, algo mas practico hubiera sido ideal
|
|
|
|
|
i made bunch of web methods and pubished on web server,Now because i never faced any big project in my life So i am scared of ,wht 'll happen if 10000's of user accessing my Single Web Method on same time ..Plz I want to know about the Performance ratio of My Web Service and scenario in which condition it 'll get crashed
|
|
|
|
|
i had my web site trackallresults.com and now i want to provide a webservice for that asp .net c# web site for android.
My Questions are
1. How to add a web service in my web site
2. How to use methods of my web site into web service
Please do help me!!!!!
|
|
|
|
|
You will have to be more specific about what technology stack the existing website is using. I think I might be able to help if you could provide me some details on the tech stack and the architecture of the app(layers and tiers at least).
|
|
|
|
|
Hey, Its very nice article
|
|
|
|
|
public partial class Gridview : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
SqlCommand cmd = new SqlCommand();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
public void bind()
{
con.Open();
cmd.CommandText = "select * from studentmark";
SqlDataAdapter ada = new SqlDataAdapter(cmd.CommandText, con);
DataTable dt = new DataTable();
ada.Fill(dt);
grdShow.DataSource = dt;
grdShow.DataBind();
}
protected void grdShow_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grdShow.EditIndex = -1;
bind();
}
protected void grdShow_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
con.Open();
Label id = grdShow.Rows[e.RowIndex].FindControl("lblid") as Label;
string query="delete from studentmark where userid='"+id.Text+"'";
cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
bind();
}
protected void grdShow_RowEditing(object sender, GridViewEditEventArgs e)
{
grdShow.EditIndex = -1;
bind();
}
protected void grdShow_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
Label id = grdShow.Rows[e.RowIndex].FindControl("lblid") as Label;
TextBox username = grdShow.Rows[e.RowIndex].FindControl("txtname") as TextBox;
TextBox password = grdShow.Rows[e.RowIndex].FindControl("txtAddress") as TextBox;
TextBox mark1 = grdShow.Rows[e.RowIndex].FindControl("txtAddress") as TextBox;
TextBox mark2 = grdShow.Rows[e.RowIndex].FindControl("txtAddress1") as TextBox;
con.Open();
cmd.Parameters.Clear();
cmd.CommandText="update studentmark set username=@username,password=@password,mark1=@mark1,mark2=@mark2 where userid='"+id.Text+"'";
cmd.Parameters.AddWithValue("@username", username.Text);
cmd.Parameters.AddWithValue("@password", password.Text);
cmd.Parameters.AddWithValue("@mark1", mark1.Text);
cmd.Parameters.AddWithValue("@mark2", mark2.Text);
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('updated Successfully');window.location('Gridview.aspx')", true);
bind();
}
protected void btnSubmit_Click1(object sender, EventArgs e)
{
if (ConnectionState.Closed == con.State) { con.Open(); }
cmd.Parameters.Clear();
cmd.CommandText = "insert into studentmark (username,password,mark1,mark2) values (@username,@password,@mark1,@mark2)";
cmd.Parameters.AddWithValue("@username", txt_username.Text);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
cmd.Parameters.AddWithValue("@mark1", txt_mark1.Text);
cmd.Parameters.AddWithValue("@mark2", txt_mark2.Text);
cmd.Connection = con;
cmd.ExecuteNonQuery();
if (ConnectionState.Open == con.State) { con.Close(); }
bind();
}
}
<connectionstrings>
<add name="conn" connectionstring="Data source=\sqlexpress; Initial catalog=Training;uid=sa;pwd=pass;">
Recruiter Name:Ms. Subhashini
Contact Company:Scientific Publishing Services Pvt Ltd
Telephone:9940511652
Address :Asmina Towers, No: 7, Kumarappa Street ,Nungambakkam ,Chennai,Tamilnadu,India
Reference Id:SW130115
http://www.fastforward.co.in/post-resume.htm
hr@iboxtek.com
hr@refulgenceinc.com.
chennai career creator:
Udyog Gruhaa, No. 10, East Coast Road, Neelangarai, Chennai, Tamil Nadu 600041
044 4294 1100
jobs@polarisnetworks.net
jobs@proteam.in
http://www.porus.in/career.php
swetha@liderconsulting.com
modified 14-Jan-15 1:19am.
|
|
|
|
|
http://www.hkvstore.com/aspnetreportmaker/download.asp
http://www.enggroom.com/AspNet.aspx
http://bytescout.com/products/developer/spreadsheetsdk/landing/bytescoutspreadsheetsdk_excel_asp_net_csharp.html
http://www.enggroom.com/ASP/Free%20Download%20Online%20Employee%20Registration%20System%20in%20Asp%20Dot%20Net.htm
http://www.freeproject.co.in/DownloadHandler.ashx?fp=~/FreeProjects_Downloads/Source/Free_Projects_01c12ed7-a461-4744-904b-dfec964a868c~leave%20management%20system.rar
http://www.projectcorner.in/employee-administration-system-college-project-asp-net-synopsis/
http://dbakings.com/ASP/GridViewwithControls.aspx
http://www.webcodeexpert.com/2013/06/send-email-to-multiple-users-based-on.html
http://www.sanfoundry.com/csharp-programming-examples/
modified 30-Dec-14 6:35am.
|
|
|
|
|
Thanks Rahul .
It helped me lot in starting with webservices.
|
|
|
|
|
Hello can you send me some advance in web services
for more practice
|
|
|
|
|
|
/*!
* JavaScript Validation v1.0.0
*
* Copyright 2014, SURM
*/
// To Allow only Numerics (0-9) Controls
function Numeric(event) {
//console.log("Numeric");
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval < 58 && Keyval > 47)) { return true; }
else { return false; }
}
// To Allow ip address (0-9) Controls
function ipNumeric(event) {
//console.log("Numeric");
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval == 46 || (Keyval < 58 && Keyval > 47)) { return true; }
else { return false; }
}
// To Allow only Characters (a-z)(A-Z) Controls
function Character(event) {
//console.log("Character");
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval < 91 && Keyval > 64) || (Keyval < 123 && Keyval > 96)) { return true; }
else { return false; }
}
// To Allow only Numerics (0-9) & Dot Controls
function onlyDotsandNumbers(event) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval == 46 || (Keyval < 58 && Keyval > 47)) { return true; }
else { return false; }
return true;
}
// To Allow only Alpanumerics (a-z)(A-Z)(0-9) Controls
function Alphanumberic(event) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval < 58 && Keyval > 47) || (Keyval < 91 && Keyval > 64) || (Keyval < 123 && Keyval > 96)) { return true; }
else { return false; }
}
// To Allow only Numerics (0-9),Currency Symbol & Dot Controls
function Currency_Dollar(event) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval < 58 && Keyval > 47) || Keyval == 36 || Keyval == 46) { return true; }
else { return false; }
}
// To Allow only Numerics (0-9) & Plus Controls
function Phone(event) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval < 58 && Keyval > 47) || Keyval == 43) { return true; }
else { return false; }
}
// To Allow only Numerics (0-9), Space & Minus Controls
function LandLine(event) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval < 58 && Keyval > 47) || Keyval == 32 || Keyval == 45) { return true; }
else { return false; }
}
// To Allow only Characters (A-Z) (a-z), Space & Dot Controls
function CharacterName(event) {
console.log(event);
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval == 32 || Keyval == 46 || (Keyval < 91 && Keyval > 64) || (Keyval < 123 && Keyval > 96)) { return true; }
else { return false; }
}
// To Allow only Characters (A-Z) (a-z), Space & Dot Controls
function NounName(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval == 32 || (Keyval < 91 && Keyval > 64) || (Keyval < 123 && Keyval > 96)) { return true; }
else { return false; }
}
// To Allow only AlpaNumerics (A-Z) (a-z) (0-9), Space & Dot Controls
function AlphanumbericName(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval == 32 || Keyval == 46 || (Keyval < 58 && Keyval > 47) || (Keyval < 91 && Keyval > 64) || (Keyval < 123 && Keyval > 96)) { return true; }
else { return false; }
}
// To Allow only Special Character Controls
function SpecialCharacter(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval <= 47 && Keyval >= 32) || (Keyval <= 64 && Keyval >= 58) || (Keyval <= 96 && Keyval >= 91) || (Keyval <= 126 && Keyval >= 123)) { return true; }
else { return false; }
}
//To Lock the 'ESC','BackSpace','Delete,'Tab' Control
function Controls(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval != 27 && Keyval != 8 && Keyval != 127 && Keyval != 9) { return true; }
else { return false; }
}
// To Allow only Calculator Controls With Number
function CalculatorNumber(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval >= 36 && Keyval <= 38) || (Keyval >= 40 && Keyval <= 43) || (Keyval >= 45 && Keyval <= 47) || (Keyval >= 60 && Keyval <= 62) || Keyval == 94 || Keyval == 124 || (Keyval < 58 && Keyval > 47)) { return true; }
else { return false; }
}
// To Allow only Calculator Controls Without Number
function Calculator(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval >= 36 && Keyval <= 38) || (Keyval >= 40 && Keyval <= 43) || (Keyval >= 45 && Keyval <= 47) || (Keyval >= 60 && Keyval <= 62) || Keyval == 94 || Keyval == 124) { return true; }
else { return false; }
}
// To Allow only Arithmetic Controls With Number
function Arithmetic(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval == 42 || Keyval == 43 || (Keyval >= 45 && Keyval <= 47)) { return true; }
else { return false; }
}
// To Allow only Arithmetic Controls Without Number
function ArithmeticNumber(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval == 42 || Keyval == 43 || (Keyval >= 45 && Keyval <= 57)) { return true; }
else { return false; }
}
// To Allow only Boolean Controls With Number
function Boolean_Check1(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval == 33 || Keyval == 38 || Keyval == 94 || Keyval == 124 || (Keyval <= 48 && Keyval >= 57)) { return true; }
else { return false; }
}
// To Allow only Boolean Controls Without Number
function Boolean_Check2(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || Keyval == 33 || Keyval == 38 || Keyval == 94 || Keyval == 124) { return true; }
else { return false; }
}
// To Allow only Small Case Character Controls
function LowerCharacter(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval < 123 && Keyval > 96)) { return true; }
else { return false; }
}
// To Allow only Capital Case Character Controls
function UpperCharacter(e) {
var Keyval = (event.keyCode == 0 ? (event.charCode == 0 ? event.which : event.charCode) : event.keyCode);
if (Keyval == 8 || (Keyval < 91 && Keyval > 64)) { return true; }
else { return false; }
}
|
|
|
|
|
|
|
Thanks for sharing nice article
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Server=servername; Database=dbname; Uid=userid; Password=password;");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
get();
}
GridView1.EditIndex = -1;
}
protected void get()
{
con.Open();
SqlCommand cmd = new SqlCommand("select Projectname,ProposedProjectID,NewProjectID,GroupID from ProjectDetails", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
HiddenField1.Value = GridView1.Rows[e.NewEditIndex].Cells[4].Text;
get();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
con.Open();
GridViewRow grv = GridView1.Rows[e.RowIndex];
string selectedProjectId = grv.Cells[4].Text;
SqlCommand cmd=new SqlCommand("delete from RCM_ProjectDetails where NewProjectID='"+selectedProjectId+"'",con);
cmd.ExecuteReader();
con.Close();
get();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
get();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
con.Open();
GridViewRow upd = GridView1.Rows[e.RowIndex];
//a.Enabled = false;
TextBox t1 = (TextBox)upd.Cells[2].Controls[0];
TextBox t2 = (TextBox)upd.Cells[3].Controls[0];
TextBox t3 = (TextBox)upd.Cells[4].Controls[0];
TextBox t4 = (TextBox)upd.Cells[5].Controls[0];
SqlCommand cmd = new SqlCommand("update ProjectDetails set ProjectName='" + t1.Text + "',ProposedProjectID='" + t2.Text + "',NewProjectID='" + t3.Text + "',GroupID='" + t4.Text + "' where NewProjectID='" + HiddenField1.Value + "'", con);
cmd.ExecuteNonQuery();
con.Close();
get();
GridView1.EditIndex = -1;
}
}
-------------------------------------------------------------------
excel report generation:
protected void BtnReport_Click1(object sender, EventArgs e)
{
string qry = "";
string dates = " currentdate between '" + TxtFromDate.Text + "' and '" + TxtTodate.Text + "'";
if (con.State != ConnectionState.Closed) con.Open();
if (TxtEmpid.Text == "")
{
qry = "SELECT userid, empname, shift, convert(varchar(10),currentdate,101)currentdate, ProjectName,NoOfpages,ErrorType,ErrorCount,Status,PublisherArticalType,ArticleType, starttime, endtime, breaktime, meetingtime,meetingremark, totaltakentime, remarks FROM DPRTest where " + dates + " order by userid,currentdate,starttime,endtime asc";
}
else
{
qry = "SELECT userid, empname, shift, convert(varchar(10),currentdate,101)currentdate, ProjectName,NoOfpages,ErrorType,ErrorCount, Status,PublisherArticalType,ArticleType, starttime, endtime, breaktime, meetingtime,meetingremark, totaltakentime, remarks FROM DPRTest where (empname='" + lblempnameResult.Text + "') and (" + dates + ") order by slno asc";
}
SqlDataAdapter da = new SqlDataAdapter(qry, con);
DataSet dts = new DataSet();
da.Fill(dts);
if (con.State != ConnectionState.Open) con.Close();
StringBuilder sbdesign = new StringBuilder();
var Header = Convert.ToDateTime(TxtFromDate.Text).ToString("MMM - yy") + " to " + Convert.ToDateTime(TxtTodate.Text).ToString("MMM - yy");
sbdesign.Append(@"
");
for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
{
sbdesign.Append("");
}
sbdesign.Append(" SlNo | UserID | Employee Name | Shift | Date [MM/DD/YYYY] | ProjectName | NoOfpages | ErrorType | ErrorCount | Status | PublisherArtical Type | Article Type | Start Time | End Time | Break Time | Meeting Time | Meeting Remark | Total Takentime | Remarks | " + (i + 1) + " | " + dts.Tables[0].Rows[i]["userid"].ToString() + " | " + dts.Tables[0].Rows[i]["empname"].ToString() + " | " + dts.Tables[0].Rows[i]["shift"].ToString() + " | " + dts.Tables[0].Rows[i]["currentdate"].ToString() + " | " + dts.Tables[0].Rows[i]["ProjectName"].ToString() + " | " + dts.Tables[0].Rows[i]["NoOfpages"].ToString() + " | " + dts.Tables[0].Rows[i]["ErrorType"].ToString() + " | " + dts.Tables[0].Rows[i]["ErrorCount"].ToString() + " | " + dts.Tables[0].Rows[i]["Status"].ToString() + " | " + dts.Tables[0].Rows[i]["PublisherArticalType"].ToString() + " | " + dts.Tables[0].Rows[i]["ArticleType"].ToString() + " | " + dts.Tables[0].Rows[i]["Starttime"].ToString() + " | " + dts.Tables[0].Rows[i]["endtime"].ToString() + " | " + dts.Tables[0].Rows[i]["breaktime"].ToString() + " | " + dts.Tables[0].Rows[i]["meetingtime"].ToString() + " | " + dts.Tables[0].Rows[i]["meetingremark"].ToString() + " | " + dts.Tables[0].Rows[i]["totaltakentime"].ToString() + " | " + dts.Tables[0].Rows[i]["remarks"].ToString() + " | ");
Main.InnerHtml = sbdesign.ToString();
var _FileContents = Main.InnerHtml;
string excelname = "DPR" + "-" + Convert.ToDateTime(TxtFromDate.Text).ToString("MMM") + "'" + Convert.ToDateTime(TxtFromDate.Text).ToString("dd") + " " + Convert.ToDateTime(TxtFromDate.Text).ToString("yyyy") + " " + "to" + " " + Convert.ToDateTime(TxtTodate.Text).ToString("MMM") + "'" + Convert.ToDateTime(TxtTodate.Text).ToString("dd") + " " + Convert.ToDateTime(TxtTodate.Text).ToString("yyyy") + ".xls";
var Excelpath = Server.MapPath(".") + "\\Reports\\" + excelname;
File.WriteAllText(Excelpath, _FileContents);
Response.ContentType = "xls";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + excelname);
Response.TransmitFile(Excelpath);
Response.End();
}
modified 30-Aug-14 0:32am.
|
|
|
|
|
|
أحسنت اخي راهول و الى الامام
|
|
|
|
|
|
asp.net:
http://www.dotnetfox.com/articles/how-to-add-edit-delete-update-records-in-grid-view-Asp-Net-1003.aspx
http://www.asp.net/ajaxlibrary/ajaxcontroltoolkitsamplesite/
http://www.aspsnippets.com/Articles/DataBinding-DropDownList-Label-and-Textbox-Controls-in-ASP.Net.aspx
http://www.cramerz.com/aspdotnet
http://www.slideshare.net/mannysiddiqui/Advanced-ASPNET-Concepts-and-Constructs
http://msdn.microsoft.com/en-us/library/az24scfc.aspx
http://www.aspsnippets.com/Articles/How-to-bind-GridView-with-DataReader-in-ASPNet-using-C-and-VBNet.aspx
http://www.aspdotnet-suresh.com/2012/10/aspnet-difference-between-datareader.html
http://www.microsoft.com/web/post/adding-video-to-your-website-using-the-new-html5-video-tag
http://www.homewebsitebuilder.com/admin/site/niche
http://www.tutorialspoint.com/asp.net/asp.net_multi_views.htm
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html
http://www.aspsnippets.com/Articles/Simple-Insert-Select-Edit-Update-and-Delete-in-ASPNet-GridView-control.aspx
http://www.aspdotnet-suresh.com/2011/12/how-to-create-simple-login-form-using.html
c#.net:
http://www.c-sharpcorner.com/1/75/asp-net-controls.aspx
http://www.c-sharpcorner.com/UploadFile/sapnabeniwal/a-glimpse-to-image-slideshow-using-jquery/
http://www.c-sharpcorner.com/UserRegistration/UserRegistration.aspx?check=r&ReturnURL=/uploadfile/sapnabeniwal/a-glimpse-to-image-slideshow-using-jquery/
http://samples.gaiaware.net/Combinations/WebApps/Chess/
http://www.dotnetpools.com/Article/ArticleDetiail/?articleId=183
http://www.tutorialspoint.com/csharp/csharp_overview.htm
http://www.c-sharpcorner.com/UploadFile/b8d90a/send-sms-using-C-Sharp-net/
http://forums.asp.net/t/1883175.aspx/1
http://social.msdn.microsoft.com/Search/en-US?query=sms%20senting%20method%20asp.net&emptyWatermark=true&ac=6
file related
http://go.microsoft.com/FwLink/p/?LinkID=303856
http://go.microsoft.com/FwLink/p/?LinkID=303859
http://go.microsoft.com/FwLink/p/?LinkID=303863
http://go.microsoft.com/FwLink/p/?LinkID=303861
http://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CDsQFjAA&url=http%3A%2F%2Fsourceforge.net%2Fdirectory%2Fbusiness-enterprise%2Fenterprise%2Fmedhealth%2F&ei=qGvmUoPWJcWNrgfUtYHIDQ&usg=AFQjCNE1mbxdpBcX7qYaBVokbUtxpOxO3g&cad=rja
http://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&ved=0CFQQFjAE&url=http%3A%2F%2Fmastersinhealthinformatics.com%2F2009%2F25-open-source-software-projects-that-are-changing-healthcare%2F&ei=qGvmUoPWJcWNrgfUtYHIDQ&usg=AFQjCNEFLVbn2_l2eTlmgD4P8_O1iAkGCA&cad=rja
http://www.1000projects.org/sr1p/dn17p/he-in-ma.zip
http://www.1000projects.org/sr1p/dn17p/he-in-ma.zip
http://www.ondd.org/the-top-100-open-source-software-tools-for-medical-professionals/
sql
http://programmers.stackexchange.com/questions/181651/are-these-sql-concepts-for-beginners-intermediate-or-advanced-developers
http://www.gplivna.eu/papers/sql_join_types.htm
http://developers.cartodb.com/tutorials/joining_data.html
webservice:http://www.aspdotnet-suresh.com/2011/05/aspnet-web-service-or-creating-and.html
http://www.aeiucm.com/index.php/erp-system/payroll-system
http://www.finetechcode.com/upload-and-free-download-php-source-code-php-projects/
http://visuallightbox.com/visuallightbox-mac-setup.zip?affiliateid=WPG731GH
http://www.kannel.org/download.shtml#devel
http://www.developershome.com/sms/sms_tutorial.asp?page=smsGateway
http://www.clickatell.com/
http://www.ozekisms.com/index.php?owpn=230
wpf&wcf:
http://tnvbalaji.com/articles/wcf-tutorials/
http://www.codeproject.com/Tips/468354/WCF-Example-for-Inserting-Deleting-and-Displaying
http://www.codeproject.com/Articles/99330/WPF-Step-by-Step-Getting-Started-with-WPF-and-Expr
http://www.aspdotnet-suresh.com/2012/10/c-difference-between-aspnet-webservice.html
jquery url:
http://jqueryui.com/effect/
http://www.slidesjs.com/
http://bxslider.com/examples
http://www.htmlgoodies.com/tutorials/forms/article.php/3895776/HTML-Forms-jQuery-Basics---Getting-Started.htm
http://www.asp.net/ajaxlibrary/ajaxcontroltoolkitsamplesite/
http://msdn.microsoft.com/en-us/library/bb386416%28v=vs.100%29.aspx
http://msdn.microsoft.com/en-us/library/x8k61whf%28v=vs.100%29.aspx
http://gregfranko.com/jquery.selectBoxIt.js/#Examples
http://www.cssbasics.com/css-classes/
menu
http://jqueryui.com/menu/#default and apycom.com
Design
http://www.subcide.com/articles/creating-a-css-layout-from-scratch/
wizard
ttp://www.codeproject.com/Articles/15804/ASP-NET-2-0-Wizard-Control
calender holiday
http://www.c-sharpcorner.com/uploadfile/puranindia/calendar-control-in-Asp-Net/
tutorial
http://www.java2s.com/Tutorial/CSharp/CatalogCSharp.htm
ajax asp.net
http://www.programcall.com/7/aspnet/binding-dropdownlist-with-dataset-values-in-aspnet.aspx
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/
storedprocedure
http://www.mssqltips.com/sqlservertutorial/164/using-try-catch-in-sql-server-stored-procedures/
nth max salary
http://www.programmerinterview.com/index.php/database-sql/find-nth-highest-salary-sql/
hosting
http://www.dotnetfunda.com/articles/article1247-how-to-host-aspnet-application-on-the-web-server-iis.aspx
js slider
http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/#prettyPhoto
solutions
http://www.dotnetspider.com/resources/Category518-ASP.NET-GridView.aspx
Excel
>http://www.codeproject.com/Articles/16210/Excel-Reader
>http://www.smartxls.com/download.htm\
mobile find location:
http://msdn.microsoft.com/en-us/magazine/hh852592.aspx
js:
http://bxslider.com/examples/auto-show-start-stop-controls
jscript validation
http://webcheatsheet.com/javascript/form_validation.php
http://www.w3resource.com/javascript/form/javascript-sample-registration-form-validation.php
http://www.tizag.com/javascriptT/javascriptform.php
sql:
http://www.1keydata.com/sql/inline-view.html
http://www.tutorialspoint.com/sql/sql-rdbms-concepts.htm
http://programmers.stackexchange.com/questions/181651/are-these-sql-concepts-for-beginners-intermediate-or-advanced-developers
image slide show using jquery
http://www.c-sharpcorner.com/UserRegistration/UserRegistration.aspx?check=r&ReturnURL=/uploadfile/sapnabeniwal/a-glimpse-to-image-slideshow
http://www.aspdotnet-suresh.com/2011/04/ajax-accordion-control-example-or-how.html
http://www.w3resource.com/javascript/form/javascript-field-level-form-validation.php
http://www.mywebsite123.com/
http://www.aspdotnet-suresh.com/2013/04/8-jquery-popup-window-plugin-examples.html
jqueryslidertemplates
http://wowslider.com/rq/own-template-beautiful-jquery-slider-1e.html
http://wowslider.com/best-jquery-slider-crystal-linear-demo.html
http://cube3x.com/2013/08/30-free-jquery-slider-plugins/
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html
Xcode for iphones apps
1.https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html
2.http://www.appcoda.com/improve-detail-view-controller-storyboard-segue/
basic web service in codeproject
ado.net :
*dataset
*datatable
*datarow
*datacolumn
***********
*sqldataadapter
*sqldatareader
*sqlcommand
************
*executereader
*executenonquery
*executescalar
**********************
http://www.dotnetspider.com/projects/category2.aspx
http://wowslider.com/download/wowslider-win-setup.zip?utm_source=free_downl_win&utm_medium=email&utm_campaign=wow_downl_link
http://www.freshdesignweb.com/jquery-login-registration-contact-form.html
http://demos.devexpress.com/MVCxGridViewDemos/DataBinding/DataBinding
http://w3layouts.com/healthy-mobile-website-template
http://www.webcodeexpert.com/2013/08/create-registration-form-and-send.html#.UyGOqD-Sxr0 conformation email
http://www.aspdotnet-suresh.com/2012/10/aspnet-difference-between-datareader.html
http://visuallightbox.com/visuallightbox-mac-setup.zip?affiliateid=WPG731GH
http://www.c-sharpcorner.com/UploadFile/sapnabeniwal/a-glimpse-to-image-slideshow-using-jquery/
http://www.c-sharpcorner.com/UserRegistration/UserRegistration.aspx?check=r&ReturnURL=/uploadfile/sapnabeniwal/a-glimpse-to-image-slideshow-using-jquery/
http://www.microsoft.com/web/post/adding-video-to-your-website-using-the-new-html5-video-tag
http://www.homewebsitebuilder.com/admin/site/niche
http://www.filesmix.com/item/live-demo/3127 LOGIN TEMPLATE
http://www.templatemo.com/
http://streetsmash.com/admin-templates/
http://bootsnipp.com/?page=4
Dynamic cloud widgets animation
http://www.dotnettips4u.com/2013/03/registering-in-web-site.html
http://www.goat1000.com/tagcanvas.php
http://www.portnine.com/bootstrap-themes
c#.net add webmethod important:
http://www.mikesdotnetting.com/Article/104/Many-ways-to-communicate-with-your-database-using-jQuery-AJAX-and-ASP.NET
http://www.citehr.com/318322-payroll-excel-sheet.html
----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
[Serializable]
public class BAL
{
SqlConnection con;
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
public Dictionary<string, object=""> DParameter { get; set; }
string Result = string.Empty;
public BAL() { DParameter = new Dictionary<string, object="">(); }
#region Clear Member Function
public void Clear_DropDownList(ControlCollection ControlCollections)
{
List<dropdownlist> allControls = new List<dropdownlist>();
GetControlList<dropdownlist>(ControlCollections, allControls);
foreach (var childControl in allControls) { childControl.SelectedIndex = -1; }
}
public void Clear_TextBox(ControlCollection ControlCollections)
{
List<textbox> allControls1 = new List<textbox>();
GetControlList<textbox>(ControlCollections, allControls1);
foreach (var childControl in allControls1) { childControl.Text = ""; }
}
public void Clear_RadioButtonList(ControlCollection ControlCollections)
{
List<radiobuttonlist> allControls2 = new List<radiobuttonlist>();
//GetControlList<radiobuttonlist>(Page.Controls, allControls2);
GetControlList<radiobuttonlist>(ControlCollections, allControls2);
foreach (var childControl in allControls2) { childControl.SelectedIndex = -1; }
}
public void Clear_CheckBoxList(ControlCollection ControlCollections)
{
List<checkboxlist> allControls3 = new List<checkboxlist>();
GetControlList<checkboxlist>(ControlCollections, allControls3);
foreach (var childControl in allControls3) { childControl.SelectedIndex = -1; }
}
private void GetControlList<t>(ControlCollection controlCollection, List<t> resultCollection) where T : Control
{
foreach (Control control in controlCollection)
{
//if (control.GetType() == typeof(T))
if (control is T) // This is cleaner
resultCollection.Add((T)control);
if (control.HasControls())
GetControlList(control.Controls, resultCollection);
}
}
#endregion
#region SQLCommand Member Function
public string CAIUDT_Data(string ConnectionName, string Query, CommandType CommandTypes = CommandType.Text, Boolean IsParam = false)
{
try
{
using (con = new SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString))
{
cmd.Parameters.Clear();
cmd.Connection = con;
cmd.CommandText = Query;
cmd.CommandType = CommandTypes;
if (IsParam)
{
foreach (KeyValuePair<string, object=""> kvp in DParameter)
cmd.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
if (con.State == ConnectionState.Closed) con.Open();
Result = Convert.ToString(cmd.ExecuteNonQuery());
//if (Result == "1") Result = Result + " row affected";
//else Result = Result + " row(s) affected";
}
}
catch (Exception Ex) { Result = Ex.Message; }
finally
{
cmd.Dispose();
if (con.State == ConnectionState.Open) con.Close();
}
return Result;
}
#endregion
#region SQLDataAdapter Member Function
public string SingleData(string ConnectionName, string Query, CommandType CommandTypes = CommandType.Text, Boolean IsParam = false)
{
try
{
using (con = new SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString))
{
cmd.Parameters.Clear();
cmd.Connection = con;
cmd.CommandText = Query;
cmd.CommandType = CommandTypes;
if (IsParam)
{
foreach (KeyValuePair<string, object=""> kvp in DParameter)
cmd.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
if (con.State == ConnectionState.Closed) con.Open();
Result = Convert.ToString(cmd.ExecuteScalar());
}
}
catch (Exception Ex)
{
Result = Ex.Message;
}
finally
{
cmd.Dispose();
sda.Dispose();
}
return Result;
}
public DataTable SelectMethod(string ConnectionName, string Query, CommandType CommandTypes = CommandType.Text, Boolean IsParam = false)
{
DataTable dts = new DataTable();
try
{
using (con = new SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString))
{
cmd.Parameters.Clear();
dts.Clear();
cmd.Connection = con;
cmd.CommandText = Query;
cmd.CommandType = CommandTypes;
if (IsParam)
{
foreach (KeyValuePair<string, object=""> kvp in DParameter)
cmd.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
if (con.State == ConnectionState.Closed) con.Open();
sda = new SqlDataAdapter(cmd);
sda.Fill(dts);
}
}
catch (Exception Ex) { dts = null; }
finally
{
cmd.Dispose();
sda.Dispose();
}
return dts;
}
public void FillData(System.Web.UI.WebControls.WebControl ctrl, DataTable dt, Boolean IsSelectValue = false, string DataTextField = null, string DataValueField = null, string SelectText = "-select-")
{
try
{
if (ctrl.GetType() == typeof(System.Web.UI.WebControls.DropDownList))
{
DropDownList ddls = (DropDownList)ctrl;
ddls.DataSource = dt;
ddls.DataTextField = DataTextField;
ddls.DataValueField = DataValueField;
ddls.DataBind();
if (IsSelectValue) { ddls.Items.Insert(0, SelectText); }
}
else if (ctrl.GetType() == typeof(System.Web.UI.WebControls.RadioButtonList))
{
RadioButtonList ddls = (RadioButtonList)ctrl;
ddls.DataSource = dt;
ddls.DataTextField = DataTextField;
ddls.DataValueField = DataValueField;
ddls.DataBind();
}
else if (ctrl.GetType() == typeof(System.Web.UI.WebControls.CheckBoxList))
{
CheckBoxList ddls = (CheckBoxList)ctrl;
ddls.DataSource = dt;
ddls.DataTextField = DataTextField;
ddls.DataValueField = DataValueField;
ddls.DataBind();
}
else if (ctrl.GetType() == typeof(System.Web.UI.WebControls.ListBox))
{
ListBox ddls = (ListBox)ctrl;
ddls.DataSource = dt;
ddls.DataTextField = DataTextField;
ddls.DataValueField = DataValueField;
ddls.DataBind();
}
else if (ctrl.GetType() == typeof(System.Web.UI.WebControls.FormView))
{
FormView ddls = (FormView)ctrl;
ddls.DataSource = dt;
ddls.DataBind();
}
else if (ctrl.GetType() == typeof(System.Web.UI.WebControls.DetailsView))
{
DetailsView ddls = (DetailsView)ctrl;
ddls.DataSource = dt;
ddls.DataBind();
}
else if (ctrl.GetType() == typeof(System.Web.UI.WebControls.GridView))
{
GridView ddls = (GridView)ctrl;
ddls.DataSource = dt;
ddls.DataBind();
}
else if (ctrl.GetType() == typeof(System.Web.UI.WebControls.ListView))
{
ListView ddls = (ListView)ctrl;
ddls.DataSource = dt;
ddls.DataBind();
}
}
catch (Exception Ex) { }
}
#endregion
#region Other Members
public static string Numbers2Words(string inputNumber)
{
int inputNo = Convert.ToInt32(inputNumber);
if (inputNo == 0) { return "Zero"; }
int[] numbers = new int[4];
int first = 0, u, h, t;
StringBuilder sb = new StringBuilder();
if (inputNo < 0) { sb.Append("Minus "); inputNo = -inputNo; }
string[] words0 = { "", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine " };
string[] words1 = { "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen " };
string[] words2 = { "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety " };
string[] words3 = { "Thousand ", "Lakhs ", "Crore " };
numbers[0] = inputNo % 1000;
numbers[1] = inputNo / 1000;
numbers[2] = inputNo / 100000;
numbers[1] = numbers[1] - 100 * numbers[2];
numbers[3] = inputNo / 10000000;
numbers[2] = numbers[2] - 100 * numbers[3];
for (int i = 3; i > 0; i--) { if (numbers[i] != 0) { first = i; break; } }
for (int i = first; i >= 0; i--)
{
if (numbers[i] == 0) continue;
u = numbers[i] % 10;
t = numbers[i] / 10;
h = numbers[i] / 100;
t = t - 10 * h;
if (h > 0) sb.Append(words0[h] + "Hundred ");
if (u > 0 || t > 0)
{
if (h > 0 || i == 0) sb.Append("and ");
if (t == 0) { sb.Append(words0[u]); }
else if (t == 1) { sb.Append(words1[u]); }
else { sb.Append(words2[t - 2] + words0[u]); }
}
if (i != 0) sb.Append(words3[i - 1]);
}
return sb.ToString().TrimEnd();
}
public DateTime Server_DateTime(string ConnectionName)
{
DateTime dt = new DateTime();
try
{
using (con = new SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString))
{
if (con.State == ConnectionState.Closed) con.Open();
cmd.Parameters.Clear();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select DATEADD(MI,tz_diff,GETDATE())[tz_diff] from tbl_TimeZone";
dt = Convert.ToDateTime(cmd.ExecuteScalar());
}
}
catch (Exception Ex)
{
dt = Convert.ToDateTime("1900-01-01");
}
finally
{
cmd.Dispose();
if (con.State == ConnectionState.Open) con.Close();
}
return dt;
}
public DateTime ServerDateTime(string ConnectionName)
{
DateTime dt = new DateTime();
try
{
using (con = new SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString))
{
if (con.State == ConnectionState.Closed) con.Open();
cmd.Parameters.Clear();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select GETDATE()[TimeZone]";
dt = Convert.ToDateTime(cmd.ExecuteScalar());
}
}
catch (Exception Ex)
{
dt = Convert.ToDateTime("1900-01-01");
}
finally
{
cmd.Dispose();
if (con.State == ConnectionState.Open) con.Close();
}
return dt;
}
public string Current_Ident(string ConnectionName, string TableName)
{
try
{
using (con = new SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString))
{
if (con.State == ConnectionState.Closed) con.Open();
cmd.Parameters.Clear();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select IDENT_CURRENT('" + TableName + "')";
Result = Convert.ToString(cmd.ExecuteScalar());
}
}
catch (Exception Ex)
{
Result = Ex.Message;
}
finally
{
cmd.Dispose();
if (con.State == ConnectionState.Open) con.Close();
}
return Result;
}
public void Grid2Excel(DataTable dt, System.Web.UI.WebControls.WebControl ctrl)
{
GridView grdvw = (GridView)ctrl;
string attachment = "attachment; filename=report.xls";
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
grdvw.AllowPaging = false;
grdvw.ShowHeader = true;
grdvw.DataSource = dt;
grdvw.DataBind();
grdvw.HeaderRow.Style.Add("background-color", "#fe3dec");
grdvw.HeaderRow.Style.Add("border", "1px solid #000");
grdvw.DataBind();
foreach (GridViewRow gvr in grdvw.Rows)
{
foreach (TableCell tc in gvr.Cells)
{
tc.Style.Add("border", "1px solid #000");
}
}
for (int i = 0; i < grdvw.HeaderRow.Cells.Count; i++)
{
grdvw.HeaderRow.Cells[i].Style.Add("color", "#df5015");
grdvw.HeaderRow.Cells[i].Style.Add("border", "1px solid #000");
}
grdvw.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(grdvw);
frm.RenderControl(htw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
public string getJSON(DataTable dt)
{
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<dictionary<string, object="">> rows = new List<dictionary<string, object="">>();
Dictionary<string, object=""> row;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object="">();
foreach (DataColumn col in dt.Columns)
row.Add(col.ColumnName, dr[col]);
rows.Add(row);
}
return serializer.Serialize(rows);
}
public string Encryption(string PlainText, string Key)
{
try
{
byte[] CypherText;
string NewKey = string.Empty;
foreach (char ch in Key.ToCharArray()) { NewKey = ch + NewKey; }
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8Encoding.UTF8.GetBytes(NewKey));
TripleDESCryptoServiceProvider TDES = new TripleDESCryptoServiceProvider();
TDES.Key = TDESKey;
TDES.Mode = CipherMode.ECB;
TDES.Padding = PaddingMode.PKCS7;
byte[] ASCIICode = UTF8Encoding.UTF8.GetBytes(PlainText);
try
{
ICryptoTransform Encryptor = TDES.CreateEncryptor();
CypherText = Encryptor.TransformFinalBlock(ASCIICode, 0, ASCIICode.Length);
Result = Convert.ToBase64String(CypherText);
}
finally
{
TDES.Clear();
HashProvider.Clear();
}
}
catch (Exception Ex) { Result = null; }
return Result;
}
public string Decryption(string Text, string Key)
{
byte[] Results;
string NewKey = string.Empty;
foreach (char ch in Key.ToCharArray()) { NewKey = ch + NewKey; }
MD5CryptoServiceProvider Hash = new MD5CryptoServiceProvider();
byte[] TDESKey = Hash.ComputeHash(UTF8Encoding.UTF8.GetBytes(NewKey));
TripleDESCryptoServiceProvider TDES = new TripleDESCryptoServiceProvider();
TDES.Key = TDESKey;
TDES.Mode = CipherMode.ECB;
TDES.Padding = PaddingMode.PKCS7;
byte[] ASCIICode = Convert.FromBase64String(Text);
try
{
ICryptoTransform Decryptor = TDES.CreateDecryptor();
Results = Decryptor.TransformFinalBlock(ASCIICode, 0, ASCIICode.Length);
}
finally
{
TDES.Clear();
Hash.Clear();
}
return UTF8Encoding.UTF8.GetString(Results);
}
#endregion
}
-------------
http://www.c-sharpcorner.com/Blogs/12509/difference-between-datareader-dataset-dataadapter-and-data.aspx[^]
modified 4-Oct-14 6:43am.
|
|
|
|
|