Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddItemDetails.aspx.cs" Inherits="AddItemDetails" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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>
    <link href="css/MasterStyle.css" rel="Stylesheet" type="text/css" />
    <style type="text/css">
        .style4
        {
            width: 100%;
        }
        .style5
        {
            width: 37px;
        }
        .style6
        {
            width: 131px;
        }
        .style7
        {
            width:150px;
        }
    </style>
</head>
<body>
 
   
<div id="iFrame">
    <form id="form1"  runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
    <div class="iFrameHeader">
    <asp:Label ID ="lblPage" Text="Add Item Details" runat="server">
    <hr />
    </div>
    <asp:TabContainer ID="TabContainer1" runat="server">
    <asp:TabPanel ID="tbPanel" HeaderText="Add Items" runat="server">
    <contenttemplate>
    <table class="style4">
        <tr>
            <td class="style5">
                <asp:Label ID="lblItemType" runat="server" Font-Bold="True" Text="Item Type">
            </td>
            <td class="style6">
                <asp:DropDownList ID="ddlItemType" runat="server" DataSourceID="sdlItemtype" 
                    DataTextField="Item_Type_Name" DataValueField="Item_Type_Id">
                
                <asp:SqlDataSource ID="sdlItemtype" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:IMS %>" 
                    SelectCommand="SELECT [Item_Type_Id], [Item_Type_Name] FROM [ItemType]">
                
            </td>
            <td class="style7">
                 </td>
            <td class="style7">
                <asp:Label ID="lblMake" runat="server" Font-Bold="True" Text="Make">
            </td>
            <td>
                <asp:TextBox ID="txtMake" runat="server" CssClass="inputtxt" Height="32px">
                <asp:AutoCompleteExtender ID="txtMake_AutoCompleteExtender" runat="server"  MinimumPrefixLength="0" CompletionInterval="100"
                    DelimiterCharacters="" Enabled="True" ServicePath="~/AutoComplte.asmx" ServiceMethod="Make" TargetControlID="txtMake">
                
                
            </td>
        </tr>
        <tr>
            <td class="style5">
                 </td>
            <td class="style6">
                 </td>
            <td class="style7">
                 </td>
            <td class="style7">
                 </td>
            <td><asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat ="server" 
                    ControlToValidate="txtMake" Display="Dynamic" 
                    ErrorMessage="Please Enter Make" 
                    Font-Size="X-Small">
                 </td>
        </tr>
        <tr>
            <td class="style5">
                <asp:Label ID="ldlItemDescription" runat="server" Font-Bold="True" 
                    Text="Item Description">
            </td>
            <td class="style6">
                <asp:TextBox ID="txtItemDescription" runat="server" Height="45px" 
                    TextMode="MultiLine" Width="142px" CssClass="inputtxt">
                <asp:AutoCompleteExtender ID="txtItemDescription_AutoCompleteExtender" 
                    runat="server" DelimiterCharacters="" Enabled="True" ServicePath="~/AutoComplte.asmx" CompletionInterval="100" MinimumPrefixLength="0" ServiceMethod="GetCompletionList"
                    TargetControlID="txtItemDescription">
                
            </td>
            <td class="style7">
                 </td>
            <td class="style7">
                <asp:Label ID="lblSupplier" runat="server" Font-Bold="True" Text="Supplier">
            </td>
            <td>
                <asp:TextBox ID="txtSupplier" runat="server" Height="42px" TextMode="MultiLine" 
                    Width="134px" CssClass="inputtxt">
                <asp:AutoCompleteExtender ID="txtSupplier_AutoCompleteExtender" runat="server" 
                    DelimiterCharacters="" Enabled="True" ServicePath="~/AutoComplte.asmx" CompletionInterval="100" MinimumPrefixLength="0" ServiceMethod="suppliername"
                    TargetControlID="txtSupplier">
                
            </td>
        </tr>
        <tr>
            <td class="style5">
                <asp:Label ID="LblPrice1" runat="server" Font-Bold="True" Text="Price(1-100)" Width="100px">
            </td>
            <td class="style6">
                <asp:TextBox ID="txtPrice1" runat="server" CssClass="inputtxt">
                <asp:FilteredTextBoxExtender ID="txtPrice1_FilteredTextBoxExtender" 
                    runat="server" Enabled="True" TargetControlID="txtPrice1" ValidChars="." 
                    FilterType="Custom, Numbers">
                
                <asp:RequiredFieldValidator ID="range1" runat ="server" 
                    ControlToValidate="txtPrice1" Display="Dynamic" 
                    ErrorMessage="Please Enter value (1-100)" 
                    Font-Size="X-Small">
                <asp:RangeValidator ID="rnge1" runat ="server" ControlToValidate="txtPrice1" 
                    Display="Dynamic" ErrorMessage="The value must be from 1 to 100!"" 
                    Font-Size="X-Small" MaximumValue="100" MinimumValue="1" 
                    EnableClientScript="False" Type="Integer">
            </td>
            <td class="style7">
                 </td>
            <td class="style7">
                <asp:Label ID="Label8" runat="server" Font-Bold="True" Text="price(101-1000)" Width="150px">
            </td>
            <td>
                <asp:TextBox ID="txtprice2" runat="server" CssClass="inputtxt">
                <asp:FilteredTextBoxExtender ID="txtprice2_FilteredTextBoxExtender" 
                    runat="server" Enabled="True" TargetControlID="txtprice2" ValidChars="." 
                    FilterType="Custom, Numbers">
                
                  </td>
        </tr>
        <tr>
            <td class="style5">
                 </td>
            <td class="style6">
                 </td>
            <td class="style7">
                 </td>
            <td class="style7">
                 </td>
            <td><asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat ="server" 
                    ControlToValidate="txtprice2" Display="Dynamic" 
                    ErrorMessage="Please Enter value (101-1000)" 
                    Font-Size="X-Small">
                <asp:RangeValidator ID="RangeValidator3" runat ="server" ControlToValidate="txtPrice2" 
                    Display="Dynamic" ErrorMessage="The value must be from 101 to 1000!"" 
                    Font-Size="X-Small" MaximumValue="1000" MinimumValue="101" 
                    EnableClientScript="False" Type="Integer">
                 </td>
        </tr>
        <tr>
            <td class="style5">
                <asp:Label ID="Label4" runat="server" Font-Bold="True" Text="price(1001-10000)" 
                    Width="160px">
            </td>
            <td class="style6">
                <asp:TextBox ID="txtPrice3" runat="server" CssClass="inputtxt">
                <asp:FilteredTextBoxExtender ID="txtPrice3_FilteredTextBoxExtender" 
                    runat="server" Enabled="True" TargetControlID="txtPrice3"  ValidChars="." 
                    FilterType="Custom, Numbers">
                
                <asp:RequiredFieldValidator ID="Reqp3" runat ="server" 
                    ControlToValidate="txtprice3" Display="Dynamic" 
                    ErrorMessage="Please Enter value (1001-10000)" 
                    Font-Size="X-Small">
                <asp:RangeValidator ID="Rangp3" runat ="server" ControlToValidate="txtPrice3" 
                    Display="Dynamic" ErrorMessage="The value must be from 101 to 1000!"" 
                    Font-Size="X-Small" MaximumValue="10000" MinimumValue="1001" 
                    EnableClientScript="False" Type="Integer">

            </td>
            <td class="style7">
                 </td>
            <td class="style7">
                <asp:Label ID="Label9" runat="server" Font-Bold="True" 
                    Text="Price(10001-50000)" Width="170px">
            </td>
            <td>
                <asp:TextBox ID="txtprice4" runat="server" CssClass="inputtxt">
                <asp:FilteredTextBoxExtender ID="txtprice4_FilteredTextBoxExtender" 
                    runat="server" Enabled="True" TargetControlID="txtprice4"  ValidChars="." 
                    FilterType="Custom, Numbers">
                
                 
            </td>
        </tr>
        <tr>
            <td class="style5">
                 </td>
            <td class="style6">
                 </td>
            <td class="style7">
                 </td>
            <td class="style7">
                 </td>
            <td><asp:RequiredFieldValidator ID="Reqp4" runat ="server" 
                    ControlToValidate="txtprice4" Display="Dynamic" 
                    ErrorMessage="Please Enter value (10001-50000)" 
                    Font-Size="X-Small">
                <asp:RangeValidator ID="RangeValidator1" runat ="server" ControlToValidate="txtPrice4" 
                    Display="Dynamic" ErrorMessage="The value must be from 10001 to 50000!"" 
                    Font-Size="X-Small" MaximumValue="50000" MinimumValue="10001" 
                    EnableClientScript="False" Type="Integer">
                 </td>
        </tr>
        <tr>
            <td class="style5">
                <asp:Label ID="Label5" runat="server" Font-Bold="True" 
                    Text="Price(50001-100000)" Width="170px">
            </td>
            <td class="style6">
                <asp:TextBox ID="txtprice5" runat="server" CssClass="inputtxt">
                <asp:FilteredTextBoxExtender ID="txtprice5_FilteredTextBoxExtender" 
                    runat="server" Enabled="True" TargetControlID="txtprice5"  ValidChars="." 
                    FilterType="Custom, Numbers">
                
                <asp:RequiredFieldValidator ID="Reqp5" runat ="server" 
                    ControlToValidate="txtprice5" Display="Dynamic" 
                    ErrorMessage="Please Enter value (50001-100000)"  
                    Font-Size="X-Small">
                <asp:RangeValidator ID="RangeValidator2" runat ="server" ControlToValidate="txtPrice5" 
                    Display="Dynamic" ErrorMessage="The value must be from 10001 to 50000!""  
                    Font-Size="X-Small" MaximumValue="100000" MinimumValue="50001" 
                    EnableClientScript="False" Type="Integer">
            </td>
            <td class="style7">
                 </td>
            <td class="style7">
                <asp:Label ID="Label10" runat="server" Font-Bold="True" Text="Stock">
            </td>
            <td>
                <asp:TextBox ID="txtStock" runat="server" CssClass="inputtxt">
                <asp:FilteredTextBoxExtender ID="txtStock_FilteredTextBoxExtender" 
                    runat="server" Enabled="True" TargetControlID="txtStock" 
                    FilterType="Numbers" >
                
                
            </td>
        </tr>
        <tr>
            <td class="style5">
                 </td>
            <td class="style6">
                 </td>
            <td class="style7">
                 </td>
            <td class="style7">
                 </td>
            <td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat ="server" 
                    ControlToValidate="txtStock" Display="Dynamic" 
                    ErrorMessage="Please Enter Stock" 
                    Font-Size="X-Small">
                 </td>
        </tr>
        <tr>
        <td>
            <asp:Label ID="lblTAX" runat="server" Font-Bold="True" Text="TAX%">
            </td><td>
                <asp:TextBox ID="txttax" runat="server" CssClass="inputtxt">
            </td><td></td><td>
            <asp:Label ID="lblfreightcharges" runat="server" Text="Freight Charges" 
                Font-Bold ="True">
            </td><td>
                <asp:TextBox ID="txtFreightCharges" runat="server" CssClass="inputtxt">
           </td> 
        
            </tr>
        <tr>
            <td>
                 </td>
            <td>
                 </td>
            <td>
                 </td>
            <td>
                 </td>
            <td><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat ="server" 
                    ControlToValidate="txtFreightCharges" Display="Dynamic" 
                    ErrorMessage="Please Enter Frieght Charges" 
                    Font-Size="X-Small">
                 </td>
            <td>
                 </td>
        </tr>
    </table>
    </contenttemplate>
    
    
    <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="button" 
        Font-Bold="True" Height="40px" onclick="Save_Click" />
    <asp:Button ID="btnUpdate" runat="server" CssClass="button" Font-Bold="True" 
        Height="40px" onclick="btnUpdate_Click" Text="Update" />
 </form> 
 </div>  
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;




public partial class AddItemDetails : System.Web.UI.Page
{
    // con is used for sqlConnection it get the Connection from connectionString class
    static SqlConnection con = new SqlConnection(IMS.ConnectionString.getValue());
    //da is used for fill dataSets
    SqlDataAdapter da;
    //ds is used Store Data 
    DataSet ds;
    static  int i;
    static string SupId,MakeId;
 



    protected void Page_Load(object sender, EventArgs e)
    {
        //This If condition Is Used To Check the Session avilabilty is Session is Not There Is Redirect to the LoginPage
       
        
       sessions.getsessions();
       //btnUpdate.Visible = false;
       // For query to fetch Data from Database
        string que;
        //If Page is first time Loading it Exeecute This If block
        da = new SqlDataAdapter("select max(sno) from Item ", con);
        ds = new DataSet();
        da.Fill(ds, "id");
        i = int.Parse(ds.Tables["id"].Rows[0][0].ToString());
        if (!IsPostBack)
        {
            // c is cookie with Name_Auth
       HttpCookie c = Request.Cookies["_Auth"];
        if (Request.QueryString["U"] == "ITM")
            {
              
               if (Session["UTI"].ToString() == "UT107")
                {
                    que = "select IP.Item_Id ,IP.Item_Make_Id,IP.Item_Supplier_Id ,IP.Item_Price1,IP.Item_Price2,IP.Item_Price3,IP.Item_Price4,IP.Item_Price5,IP.Item_Stock,I.Item_Description,I.Item_type_Id,IP.[TAX%],IP.freight from item i,Item_priceAndVendor ip where IP.Item_Id=I.Item_Id and Item_Supplier_Id='" + Session["UI"].ToString() + "' and Ip.Item_Supplier_Id='" + IMSNiana.SupplierId + "' and ip.Item_Id='" + IMSNiana.ItemId + "' and IP.Item_Make_Id='" + IMSNiana.MakeId + "'";
                }
                else
                {
                    que = "select IP.Item_Id ,IP.Item_Make_Id,IP.Item_Supplier_Id ,IP.Item_Price1,IP.Item_Price2,IP.Item_Price3,IP.Item_Price4,IP.Item_Price5,IP.Item_Stock,I.Item_Description,I.Item_type_Id,IP.[TAX%],IP.freight from item i,Item_priceAndVendor ip where IP.Item_Id=I.Item_Id  and Ip.Item_Supplier_Id='" + IMSNiana.SupplierId + "' and Ip.Item_Id='" + IMSNiana.ItemId + "' and IP.Item_Make_Id='" + IMSNiana.MakeId + "'";
                }
                da = new SqlDataAdapter(que, con);
                ds = new DataSet();
                da.Fill(ds, "Itemdetails");
                txtItemDescription.Text = IMSNiana.ItemDescription;
                txtMake.Text = IMSNiana.MakeName;
                txtSupplier.Text = IMSNiana.SupplierName;
                txtStock.Text = ds.Tables["Itemdetails"].Rows[0]["Item_Stock"].ToString();
                txtPrice1.Text = ds.Tables["Itemdetails"].Rows[0]["Item_Price1"].ToString();
                txtprice2.Text = ds.Tables["Itemdetails"].Rows[0]["Item_Price2"].ToString();
                txtPrice3.Text = ds.Tables["Itemdetails"].Rows[0]["Item_Price3"].ToString();
                txtprice4.Text = ds.Tables["Itemdetails"].Rows[0]["Item_Price4"].ToString();
                txtprice5.Text = ds.Tables["Itemdetails"].Rows[0]["Item_Price5"].ToString();
                txtFreightCharges.Text = ds.Tables["Itemdetails"].Rows[0]["freight"].ToString();
                txttax.Text = ds.Tables["Itemdetails"].Rows[0]["TAX%"].ToString();
                ddlItemType.SelectedValue = ds.Tables["Itemdetails"].Rows[0]["Item_type_Id"].ToString();
                txtItemDescription.Enabled = txtMake.Enabled = txtSupplier.Enabled = ddlItemType.Enabled = false;
                btnSave.Visible = false;
                btnUpdate.Visible = true;
                lblPage.Text = "Edit Item Details";
            }
          
          }
        try
        {
            if (txtSupplier.Text != "")
            {
                string query = "select User_Id from UserTable where User_Name='" + txtSupplier.Text + "' and User_type_id='UT107'";
                SqlDataAdapter daSup = new SqlDataAdapter(query, con);
                DataSet dsSup = new DataSet();
                daSup.Fill(dsSup, "Supplier");
                SupId = dsSup.Tables["Supplier"].Rows[0][0].ToString();
            }
            else
            {
            }
            if (txtMake.Text != "")
            {
                string query = "select make_id from Make where make_Name='" + txtMake.Text + "'";
                SqlDataAdapter daMake = new SqlDataAdapter(query, con);
                DataSet dsMake = new DataSet();
                daMake.Fill(dsMake, "MakeId");
                MakeId = dsMake.Tables["MakeId"].Rows[0][0].ToString();
            }
            else
            {
            }
        }
        catch
        {
        }
    }
 

    
    protected void Save_Click(object sender, EventArgs e)
    {
          da = new SqlDataAdapter("select max(sno) from Item ", con);
            ds = new DataSet();
            da.Fill(ds, "id");
            i =int.Parse(ds.Tables["id"].Rows[0][0].ToString());
        string Itemid = "ITM" + i;
        string  Icreatedby;       
        string IcreatedDate;
       // HttpCookie c = Request.Cookies["_Auth"];
        Icreatedby = Session["UN"].ToString(); 
            //c.Values["UN"];
        //t1 = (TextBox)r.FindControl("txtItemcreatedDate");
        IcreatedDate = DateTime.Now.ToShortDateString();
        SqlDataAdapter das = new SqlDataAdapter("select Item_Id from Item where Item_Description like'" +txtItemDescription.Text + "'", con);
        DataSet dss = new DataSet();
        das.Fill(dss, "item");
        //if (dss.Tables["item"].Rows.Count == 0 && c.Values["UTI"]!="UT107")
        if (dss.Tables["item"].Rows.Count == 0 && Session["UTI"].ToString()!= "UT107")
        {
            //SqlDataAdapter dat = new SqlDataAdapter("insert into item values('" + Itemid + "','" + txtItemDescription.Text+ "','" +ddlItemType.SelectedItem.Value+ "')", con);
            SqlDataAdapter dat = new SqlDataAdapter("insert into item(Item_Id,Item_Description,Item_type_Id('" + Itemid + "','" + txtItemDescription.Text + "','" + ddlItemType.SelectedItem.Value + "')", con);     //by shruthi
            DataSet dsi = new DataSet();
            dat.Fill(dsi, "Item");
            //string s = "insert into Item_priceAndVendor (Item_Id, Item_Make_Id,Item_Supplier_Id,Item_Price1,Item_Price2,Item_Price3,Item_Price4,Item_Price5,Item_Stock,Item_createdby,Item_createdDate)values('" + Itemid + "','" + MakeId + "','" + SupId + "'," + txtPrice1.Text + "," + txtprice2.Text + "," + txtPrice3.Text + "," + txtprice4.Text + "," + txtprice5.Text + "," + txtStock.Text + ",'" + Icreatedby + "','" + IcreatedDate + "')";
            // da = new SqlDataAdapter(s, con);
            //ds = new DataSet();
            //da.Fill(ds, "ItemDetails");          
        }
        else if (dss.Tables["item"].Rows.Count == 0 &&  Session["UTI"].ToString()=="UT107")//c.Values["UTI"] == "UT107")
        {
            //Page.ClientScript.RegisterStartupScript(GetType(), "f3", "alert('This Item Not Present')", true);
        }
        else
        {
            Itemid = dss.Tables["item"].Rows[0][0].ToString();
            string s = "insert into Item_priceAndVendor (Item_Id, Item_Make_Id,Item_Supplier_Id,Item_Price1,Item_Price2,Item_Price3,Item_Price4,Item_Price5,Item_Stock,Item_createdby,Item_createdDate,[TAX%],freight)values('" + Itemid + "','" + MakeId + "','" + SupId + "'," + txtPrice1.Text + "," + txtprice2.Text + "," + txtPrice3.Text + "," + txtprice4.Text + "," + txtprice5.Text + "," + txtStock.Text + ",'" + Icreatedby + "','" + IcreatedDate + "',"+txttax.Text+","+txtFreightCharges.Text+")";
             da = new SqlDataAdapter(s, con);
            ds = new DataSet();
            da.Fill(ds, "ItemDetails");
        }    
    }
    
Protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (txtFreightCharges.Text != "" && txttax.Text != "" && txtprice4.Text != "" && txtprice5.Text != "" && txtPrice3.Text != "" && txtprice2.Text != "" && txtPrice1.Text != "" && txtStock.Text != "")
        {
            SqlDataAdapter das = new SqlDataAdapter("select Item_Id from Item where Item_Description like'" + txtItemDescription.Text + "'", con);
            DataSet dss = new DataSet();
            das.Fill(dss, "item");
            string ItId = dss.Tables["item"].Rows[0][0].ToString();
            string s = "update Item_priceAndVendor  set Item_Price1=" + txtPrice1.Text + ",Item_Price2=" + txtprice2.Text + ",Item_Price3=" + txtPrice3.Text + ",Item_Price4=" + txtprice4.Text + ",Item_Price5=" + txtprice5.Text + ",Item_Stock=" + txtStock.Text + ",[TAX%]=" + txttax.Text + ",freight=" + txtFreightCharges.Text + " where Item_Make_Id='" + MakeId + "' and Item_Supplier_Id='" + SupId + "' and Item_Id='" + ItId + "'";
            SqlDataAdapter da = new SqlDataAdapter(s, con);
            ds = new DataSet();
            da.Fill(ds, "ItemDetails");
            //tbPanel.Visible = false;
            //btnUpdate.Visible = false;
            Page.ClientScript.RegisterStartupScript(GetType(), "K1", "parent.location.reload(true);", true);
        }
    }
}
Posted
Updated 2-Aug-11 2:29am
v2
Comments
Sandesh M Patil 2-Aug-11 8:05am    
Please described in short
shefeekcm 2-Aug-11 8:08am    
What is this?
RaviRanjanKr 2-Aug-11 8:32am    
Thanks for Posting Code. but you forget to mention what's your problem. ;)
Dylan Morley 2-Aug-11 8:55am    
There's so much wrong with what you've posted, I'm not even going to comment.

No, wait....
OriginalGriff 2-Aug-11 9:05am    
That is what is known as a code dump. It doesn't help anyone, because very few people are going to look through it all searching for the error. Most are (like me) just going to collapse the code and try to read teh question.
But you forgot the question.
So. Your chances of a useful answer? not good, I'm afraid.
Use the "Improve question" widget to edit your question and provide just the relevant code fragments, and describe your problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900