http://www.c-sharpcorner.com/Blogs/9797/category-sub-category.aspx
http://www.c-sharpcorner.com/Blogs/9796/customer-main.aspx
http://www.c-sharpcorner.com/Blogs/9795/storedprocedure-handler.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dtService = new DataTable();
dtService = StoredProcedureHandler.GetData("usp_getAllService");
drpService.DataTextField = "ServiceName";
drpService.DataValueField = "ServiceID";
drpService.DataSource = dtService;
drpService.DataBind();
ListItem i = new ListItem("Select", "0", true);
i.Selected = true;
drpService.Items.Add(i);
DataTable dt = (DataTable)Session["MyData"];
if (dt == null)
{
dt = createDataTable();
}
grdCustomerDetail.DataSource = dt;
Session["MyData"] = dt;
grdCustomerDetail.DataBind();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)Session["MyData"];
if (dt == null)
{
dt = createDataTable();
}
DataRow dr;
dr = dt.NewRow();
dr["ID"] = dt.Rows.Count + 1;
dr["CustomerName"] = txtCustomerName.Text;
dr["ServiceID"] = drpService.SelectedItem.Value;
dr["ServiceName"] = drpService.SelectedItem.Text;
dr["Price"] = txtPrice.Text;
dr["Date"] = DateTime.Now;// txtDate.Text;
dt.Rows.Add(dr);
grdCustomerDetail.DataSource = dt;
Session["MyData"] = dt;
grdCustomerDetail.DataBind();
}
protected void drpService_SelectedIndexChanged(object sender, EventArgs e)
{
Dictionary param = new Dictionary();
param.Add("@ServiceID", drpService.SelectedItem.Value);
DataTable dtService = new DataTable();
dtService = StoredProcedureHandler.GetDataWithPara("usp_getServicePricebyServiceID", param);
txtPrice.Text = dtService.Rows[0]["Price"].ToString();
}
public DataTable createDataTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", System.Type.GetType("System.Int32"));
dt.Columns.Add("CustomerName", System.Type.GetType("System.String"));
dt.Columns.Add("ServiceID", System.Type.GetType("System.Int32"));
dt.Columns.Add("ServiceName", System.Type.GetType("System.String"));
dt.Columns.Add("Price", System.Type.GetType("System.Int32"));
dt.Columns.Add("Date", System.Type.GetType("System.DateTime"));
return dt;
}
protected void grdCustomerDetail_RowEditing(object sender, GridViewEditEventArgs e)
{
grdCustomerDetail.EditIndex = e.NewEditIndex;
grdCustomerDetail.DataSource = (DataTable)Session["MyData"];
grdCustomerDetail.DataBind();
}
protected void grdCustomerDetail_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DataTable dt = (DataTable)Session["MyData"];
GridViewRow gr = grdCustomerDetail.Rows[e.RowIndex];
DropDownList drpService = (DropDownList)grdCustomerDetail.Rows[e.RowIndex].FindControl("drpService");
dt.Rows[gr.DataItemIndex]["ServiceID"] = drpService.SelectedItem.Value;
dt.Rows[gr.DataItemIndex]["ServiceName"] = drpService.SelectedItem.Text;
Dictionary param = new Dictionary();
param.Add("@ServiceID", drpService.SelectedItem.Value);
DataTable dtService = new DataTable();
dtService = StoredProcedureHandler.GetDataWithPara("usp_getServicePricebyServiceID", param);
dt.Rows[gr.DataItemIndex]["Price"] = dtService.Rows[0]["Price"].ToString();
dt.AcceptChanges();
grdCustomerDetail.EditIndex = -1;
Session["MyData"] = dt;
grdCustomerDetail.DataSource = (DataTable)Session["MyData"];
grdCustomerDetail.DataBind();
}
protected void grdCustomerDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList drpService = (DropDownList)e.Row.FindControl("drpService");
Label lblServiceID = (Label)e.Row.FindControl("lblServiceIDEdit");
if (drpService != null)
{
drpService.DataSource = StoredProcedureHandler.GetData("usp_getAllService");
drpService.DataBind();
drpService.SelectedValue = lblServiceID.Text;
}
}
}
protected void grdCustomerDetail_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grdCustomerDetail.EditIndex = -1;
grdCustomerDetail.DataSource = (DataTable)Session["MyData"];
grdCustomerDetail.DataBind();
}
protected void grdCustomerDetail_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataTable dt = (DataTable)Session["MyData"];
GridViewRow gr = grdCustomerDetail.Rows[e.RowIndex];
dt.Rows[gr.DataItemIndex].Delete();
dt.AcceptChanges();
Session["MyData"] = dt;
grdCustomerDetail.DataSource = (DataTable)Session["MyData"];
grdCustomerDetail.DataBind();
}
protected void btnSaveAll_Click(object sender, EventArgs e)
{
Dictionary param = new Dictionary();
Label lblCustomerName = (Label)grdCustomerDetail.Rows[0].FindControl("lblCustomerName");
param.Add("@CustomerName", lblCustomerName.Text);
param.Add("@CustomerID", 0);
param.Add("@Date", DateTime.Now);
DataTable dtService = new DataTable();
int returnvalue = StoredProcedureHandler.InsertDataOutPutValue("isp_InserCustomer", param, "@CustomerID");
for (int i = 0; i < grdCustomerDetail.Rows.Count; i++)
{
//Label lblCustomerName = (Label)grdCustomerDetail.Rows[i].FindControl("lblCustomerName");
Label lblServiceID = (Label)grdCustomerDetail.Rows[i].FindControl("lblServiceID");
Label lblPrice = (Label)grdCustomerDetail.Rows[i].FindControl("lblPrice");
Label lblDate = (Label)grdCustomerDetail.Rows[i].FindControl("lblDate");
Dictionary param1 = new Dictionary();
param1.Add("@ServiceID", lblServiceID.Text);
param1.Add("@CustomerID", returnvalue);
StoredProcedureHandler.InsertData("isp_InserCustomerServiceMap", param1);
}
}
http://www.c-sharpcorner.com/Blogs/9796/customer-main.aspx
http://www.c-sharpcorner.com/Blogs/9795/storedprocedure-handler.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dtService = new DataTable();
dtService = StoredProcedureHandler.GetData("usp_getAllService");
drpService.DataTextField = "ServiceName";
drpService.DataValueField = "ServiceID";
drpService.DataSource = dtService;
drpService.DataBind();
ListItem i = new ListItem("Select", "0", true);
i.Selected = true;
drpService.Items.Add(i);
DataTable dt = (DataTable)Session["MyData"];
if (dt == null)
{
dt = createDataTable();
}
grdCustomerDetail.DataSource = dt;
Session["MyData"] = dt;
grdCustomerDetail.DataBind();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)Session["MyData"];
if (dt == null)
{
dt = createDataTable();
}
DataRow dr;
dr = dt.NewRow();
dr["ID"] = dt.Rows.Count + 1;
dr["CustomerName"] = txtCustomerName.Text;
dr["ServiceID"] = drpService.SelectedItem.Value;
dr["ServiceName"] = drpService.SelectedItem.Text;
dr["Price"] = txtPrice.Text;
dr["Date"] = DateTime.Now;// txtDate.Text;
dt.Rows.Add(dr);
grdCustomerDetail.DataSource = dt;
Session["MyData"] = dt;
grdCustomerDetail.DataBind();
}
protected void drpService_SelectedIndexChanged(object sender, EventArgs e)
{
Dictionary
param.Add("@ServiceID", drpService.SelectedItem.Value);
DataTable dtService = new DataTable();
dtService = StoredProcedureHandler.GetDataWithPara("usp_getServicePricebyServiceID", param);
txtPrice.Text = dtService.Rows[0]["Price"].ToString();
}
public DataTable createDataTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", System.Type.GetType("System.Int32"));
dt.Columns.Add("CustomerName", System.Type.GetType("System.String"));
dt.Columns.Add("ServiceID", System.Type.GetType("System.Int32"));
dt.Columns.Add("ServiceName", System.Type.GetType("System.String"));
dt.Columns.Add("Price", System.Type.GetType("System.Int32"));
dt.Columns.Add("Date", System.Type.GetType("System.DateTime"));
return dt;
}
protected void grdCustomerDetail_RowEditing(object sender, GridViewEditEventArgs e)
{
grdCustomerDetail.EditIndex = e.NewEditIndex;
grdCustomerDetail.DataSource = (DataTable)Session["MyData"];
grdCustomerDetail.DataBind();
}
protected void grdCustomerDetail_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DataTable dt = (DataTable)Session["MyData"];
GridViewRow gr = grdCustomerDetail.Rows[e.RowIndex];
DropDownList drpService = (DropDownList)grdCustomerDetail.Rows[e.RowIndex].FindControl("drpService");
dt.Rows[gr.DataItemIndex]["ServiceID"] = drpService.SelectedItem.Value;
dt.Rows[gr.DataItemIndex]["ServiceName"] = drpService.SelectedItem.Text;
Dictionary
param.Add("@ServiceID", drpService.SelectedItem.Value);
DataTable dtService = new DataTable();
dtService = StoredProcedureHandler.GetDataWithPara("usp_getServicePricebyServiceID", param);
dt.Rows[gr.DataItemIndex]["Price"] = dtService.Rows[0]["Price"].ToString();
dt.AcceptChanges();
grdCustomerDetail.EditIndex = -1;
Session["MyData"] = dt;
grdCustomerDetail.DataSource = (DataTable)Session["MyData"];
grdCustomerDetail.DataBind();
}
protected void grdCustomerDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList drpService = (DropDownList)e.Row.FindControl("drpService");
Label lblServiceID = (Label)e.Row.FindControl("lblServiceIDEdit");
if (drpService != null)
{
drpService.DataSource = StoredProcedureHandler.GetData("usp_getAllService");
drpService.DataBind();
drpService.SelectedValue = lblServiceID.Text;
}
}
}
protected void grdCustomerDetail_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grdCustomerDetail.EditIndex = -1;
grdCustomerDetail.DataSource = (DataTable)Session["MyData"];
grdCustomerDetail.DataBind();
}
protected void grdCustomerDetail_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataTable dt = (DataTable)Session["MyData"];
GridViewRow gr = grdCustomerDetail.Rows[e.RowIndex];
dt.Rows[gr.DataItemIndex].Delete();
dt.AcceptChanges();
Session["MyData"] = dt;
grdCustomerDetail.DataSource = (DataTable)Session["MyData"];
grdCustomerDetail.DataBind();
}
protected void btnSaveAll_Click(object sender, EventArgs e)
{
Dictionary
Label lblCustomerName = (Label)grdCustomerDetail.Rows[0].FindControl("lblCustomerName");
param.Add("@CustomerName", lblCustomerName.Text);
param.Add("@CustomerID", 0);
param.Add("@Date", DateTime.Now);
DataTable dtService = new DataTable();
int returnvalue = StoredProcedureHandler.InsertDataOutPutValue("isp_InserCustomer", param, "@CustomerID");
for (int i = 0; i < grdCustomerDetail.Rows.Count; i++)
{
//Label lblCustomerName = (Label)grdCustomerDetail.Rows[i].FindControl("lblCustomerName");
Label lblServiceID = (Label)grdCustomerDetail.Rows[i].FindControl("lblServiceID");
Label lblPrice = (Label)grdCustomerDetail.Rows[i].FindControl("lblPrice");
Label lblDate = (Label)grdCustomerDetail.Rows[i].FindControl("lblDate");
Dictionary
param1.Add("@ServiceID", lblServiceID.Text);
param1.Add("@CustomerID", returnvalue);
StoredProcedureHandler.InsertData("isp_InserCustomerServiceMap", param1);
}
}