Thursday, February 20, 2014

xml import

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/f44039e4-cb89-4dfe-bade-133842ca571a/importing-xml-files-into-sql-server-2008?forum=transactsql

static void Main(string[] args)
{
  String connectionString = "Data Source=ServerName;Initial Catalog=QA;Integrated Security=True";
  using (SqlConnection sqlconn = new SqlConnection(connectionString))
  {
    DataSet ds = new DataSet();
    DataTable sourcedata = new DataTable();
    ds.ReadXml(@"http://ws.geonames.org/countryCode?lat=40.417&lng=-3.703&type=xml");
    sourcedata = ds.Tables[0];
    sqlconn.Open();
    using (SqlBulkCopy bulkcopy = new SqlBulkCopy(sqlconn))
    {
      bulkcopy.DestinationTableName = "dbo.Geonames";
      bulkcopy.ColumnMappings.Add("countryCode", "countryCode");
      bulkcopy.ColumnMappings.Add("countryName", "countryName");
      bulkcopy.ColumnMappings.Add("languages", "languages");
      bulkcopy.ColumnMappings.Add("distance", "distance");
      bulkcopy.WriteToServer(sourcedata);
    }
    Console.ReadLine();
  }

}
 
 
//
http://stackoverflow.com/questions/16838627/import-xml-into-sql-server 

Reservation Grid(.aspx)

//delete confirm java script
<script language="javascript" type="text/javascript">

    function printPartOfPage(elementId) {
        var printContent = document.getElementById(elementId);
        var windowUrl = 'about:blank';
        var uniqueName = new Date();
        var windowName = 'Print' + uniqueName.getTime();
        var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

        printWindow.document.write(printContent.innerHTML);
        printWindow.document.close();
        printWindow.focus();
        printWindow.print();
        printWindow.close();
    }
    $(function ()
  {
      $('.myDatePickerClass').datepicker({
          controlType: 'select',
          timeFormat: 'hh:mm tt'
      });
      });
</script>


//login view
 <asp:LoginView ID="HeadLoginView0" runat="server" EnableViewState="false">
                        <AnonymousTemplate>
                            [ <a ID="HeadLoginStatus1" runat="server" href="~/Login.aspx">Log In</a> ]
                        </AnonymousTemplate>
                        <LoggedInTemplate>
                            Welcome <span class="bold">
                            <asp:LoginName ID="HeadLoginName0" runat="server" />
                            </span>! [
                            <asp:LoginStatus ID="HeadLoginStatus2" runat="server" LogoutAction="Redirect"
                                LogoutPageUrl="~/Login.aspx" LogoutText="Log Out" />
                            ]
                        </LoggedInTemplate>
                    </asp:LoginView>




// girdview

        <asp:GridView ID="grdvwReservation"
        DataKeyNames="reservation_id"
         runat="server" AutoGenerateColumns="False" CssClass="gridview"
            onrowcancelingedit="grdvwReservation_RowCancelingEdit"
            onrowediting="grdvwReservation_RowEditing"
            onrowupdating="grdvwReservation_RowUpdating"
            onrowdatabound="grdvwReservation_RowDataBound"
            onselectedindexchanged="grdvwReservation_SelectedIndexChanged"
            onrowdeleting="grdvwReservation_RowDeleting">
            <Columns>
              
                    <asp:TemplateField HeaderText="Reservation_ID">
                   <ItemTemplate>
                    <asp:Label ID="lblResId" runat="server" Text='<%# Eval("reservation_id") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtResId" Text='<%# Bind("reservation_id") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

              
                <asp:TemplateField HeaderText="Date">
                <ItemTemplate>
                    <asp:Label ID="lblDate" runat="server" Text='<%# Eval("Pickup_Date","{0:MM/dd/yyyy }") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtDate" Text='<%# Bind("Pickup_Date") %>' runat="server" CssClass="myDatePickerClass" ></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtDate"
                        ErrorMessage="Invalid Format" ForeColor="Red"
                        ValidationExpression="^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$"
                        ValidationGroup="val"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                </asp:TemplateField>
                 
           

                 <asp:TemplateField HeaderText="DRIVER">
                   <ItemTemplate>
                    <asp:Label ID="lblDriver" runat="server" Text='<%# Eval("Driver_Name") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtDriver" Text='<%# Bind("Driver_Name") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

                  <asp:TemplateField HeaderText="PU TIME">
                <ItemTemplate>
                    <asp:Label ID="lblPuTime" runat="server" Text='<%# Eval("Pickup_Date","{0:hh:mm tt}") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtPuTime" Text='<%# Bind("Pickup_Date","{0:hh:mm tt}") %>' runat="server" Width="60px"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="regexpressPuTime" runat="server" ControlToValidate="txtPuTime"
                        ErrorMessage="Invalid Format" ForeColor="Red"
                        ValidationExpression="^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$"
                        ValidationGroup="val"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="PROGRESS">
                  <ItemTemplate>
                 <asp:Label ID="lblDProgState" runat="server" Text='<%# Eval("Progress_State") %>'></asp:Label>
                </ItemTemplate>
               
                <EditItemTemplate>
                        
                    <asp:DropDownList ID="drpdwnProgState" runat="server" >
                        <asp:ListItem Value="Pending" Text="Pending"/>
                        <asp:ListItem Value="Assigned" Text="Assigned"/>
                        <asp:ListItem Value="Done" Text="Done"/>
                        <asp:ListItem Value="Cancelled BC" Text="Cancelled BC"/>
                        <asp:ListItem Value="Cancelled SS" Text="Cancelled SS"/>
                        <asp:ListItem Value="Postphoned" Text="Postphoned"/>
                    </asp:DropDownList>
               
                </EditItemTemplate>
                </asp:TemplateField>



                <asp:TemplateField HeaderText="PHONE NO">
                <ItemTemplate>
                    <asp:Label ID="lblPhoneNo" runat="server" Text='<%# Eval("TelephoneNo") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtPhoneNo" Text='<%# Bind("TelephoneNo") %>' runat="server" Width="90px"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="FIRST NAME">
                  <ItemTemplate>
                    <asp:Label ID="lblFnm" runat="server" Text='<%# Eval("First_Name") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtFnm" Text='<%# Bind("First_Name") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="LAST NAME">
                <ItemTemplate>
                    <asp:Label ID="lblLnm" runat="server" Text='<%# Eval("Last_Name") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtLnm" Text='<%# Bind("Last_Name") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="TRIP">
                <ItemTemplate>
                    <asp:Label ID="lblTrip" runat="server" Text='<%# Eval("Airport_Trip") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtTrip" Text='<%# Bind("Airport_Trip") %>' runat="server"
                        Width="40px"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

                 <asp:TemplateField HeaderText="ADDRESS">
                   <ItemTemplate>
                    <asp:Label ID="lblAddress" runat="server" Text='<%# Eval("Address") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtAddress" Text='<%# Bind("Address") %>' runat="server"
                        Width="350px"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="FT">
                   <ItemTemplate>
                    <asp:Label ID="lblFrTyp" runat="server" Text='<%# Eval("Fare_Type") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                     <asp:DropDownList ID="drpdwnFrTyp" runat="server" >
                        <asp:ListItem Value="DC" Text="DC"/>
                        <asp:ListItem Value="ppOL" Text="ppOL"/>
                        <asp:ListItem Value="ppOP" Text="ppOP"/>
                       
                    </asp:DropDownList>
                </EditItemTemplate>
                </asp:TemplateField>


                <asp:TemplateField HeaderText="FARE">
                   <ItemTemplate>
                    <asp:Label ID="lblCost" runat="server" Text='<%# Eval("Cost") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtCost" Text='<%# Bind("Cost") %>' runat="server"
                        Width="45px"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                        ControlToValidate="txtCost" ErrorMessage="*" ForeColor="Red"
                        ValidationGroup="val"></asp:RequiredFieldValidator>
                </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="RT">
                <ItemTemplate>
                    <asp:Label ID="lblRTrp" runat="server" Text='<%# Eval("Round_Trip") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtRTrp" Text='<%# Bind("Round_Trip") %>' runat="server"
                        Width="50px"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>
             

                <asp:TemplateField HeaderText="TYPE">
                <ItemTemplate>
                    <asp:Label ID="lblTpTyp" runat="server" Text='<%# Eval("Ride_Type") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtTpTyp" Text='<%# Bind("Ride_Type") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="EMAIL">
                 <ItemTemplate>
                    <asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Email") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtEmail" Text='<%# Bind("Email") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>


                <asp:TemplateField HeaderText="Mls" ItemStyle-Width="10px">
                   <ItemTemplate>
                    <asp:Label ID="lblLength" runat="server" Text='<%# Eval("TourLength") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtLength" Text='<%# Bind("TourLength") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                    <ItemStyle Width="10px" />
                </asp:TemplateField>

             

                  <asp:TemplateField HeaderText="FLT NO">
                   <ItemTemplate>
                    <asp:Label ID="lblFltNo" runat="server" Text='<%# Eval("AirLine_Name") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtFltNo" Text='<%# Bind("AirLine_Name") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

               
                <asp:TemplateField HeaderText="FLT TIME">
                <ItemTemplate>
                    <asp:Label ID="lblFlTime" runat="server" Text='<%# Eval("AirLine_Time","{0:MM/dd/yyyy hh:mm tt}") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtFlTime" Text='<%# Bind("AirLine_Time") %>' runat="server" CssClass="datepickerCompleted" ></asp:TextBox>
                    <asp:RegularExpressionValidator ID="regexpressFltTime" runat="server" ControlToValidate="txtFlTime"
                        ErrorMessage="Invalid Format" ForeColor="Red"
                        ValidationExpression="^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$"
                        ValidationGroup="val"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                </asp:TemplateField>

                 <asp:TemplateField HeaderText="CON NO">
                   <ItemTemplate>
                    <asp:Label ID="lblResrv" runat="server" Text='<%# Eval("Reservation_No") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtResrv" Text='<%# Bind("Reservation_No") %>' runat="server" Width="100px"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

                 <asp:CommandField ValidationGroup="val" ShowEditButton="True" ButtonType="Button" />

                <asp:CommandField ShowDeleteButton="True" ButtonType="Button"  />

                <asp:TemplateField HeaderText="Comments">
                <ItemTemplate>
                    <asp:Label ID="lblCmnts" runat="server" Text='<%# Eval("Comments") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtCmnts" Text='<%# Bind("Comments") %>' runat="server"></asp:TextBox>
                </EditItemTemplate>
                </asp:TemplateField>

               
               
               
            </Columns>
        </asp:GridView>
////
http://csharp.net-informations.com/xml/how-to-read-xml.htm

reservation Grid(.cs)

DALSky objDalSky;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] != null)
            {
                objDalSky = new DALSky();
                if (!IsPostBack)
                {
                    setGridData();
                }

            }

            else
            {
                Response.Redirect("../Login.aspx");
            }
        }


  protected void grdvwReservation_RowEditing(object sender, GridViewEditEventArgs e)
        {
            grdvwReservation.EditIndex = e.NewEditIndex;
            setGridData();
        }

        protected void grdvwReservation_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            grdvwReservation.EditIndex = -1;
            setGridData();
        }


//row updating
        protected void grdvwReservation_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            TextBox txtRes_id = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtResId");
            TextBox txtDate = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtDate");
            TextBox txtTelephone = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtPhoneNo");
            TextBox txtFirstName = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtFnm");
            TextBox txtLastName = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtLnm");
            TextBox txtResNo = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtResrv");
            TextBox txtEmail = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtEmail");
            TextBox txtAddress = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtAddress");
           // TextBox txtProgState = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtProgState");
            DropDownList drpdwnProgState = (DropDownList)grdvwReservation.Rows[e.RowIndex].FindControl("drpdwnProgState");

            TextBox txtDriver = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtDriver");
            TextBox txtFltTime = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtFlTime");
            TextBox txtTrpTyp = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtTrip");
            DropDownList drpdwnFrType = (DropDownList)grdvwReservation.Rows[e.RowIndex].FindControl("drpdwnFrTyp");
            TextBox txtFare= (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtCost");
            TextBox txtRundTrp = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtRTrp");
            TextBox txtRdTyp = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtTpTyp");
            TextBox txtFltNo = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtFltNo");
            TextBox txtComments = (TextBox)grdvwReservation.Rows[e.RowIndex].FindControl("txtCmnts");

            try
            {
                ArrayList parameters = new ArrayList();
                parameters.Add(Convert.ToInt32(txtRes_id.Text));
                parameters.Add(txtDate.Text);
                parameters.Add(txtTelephone.Text);
                parameters.Add(txtFirstName.Text);
                parameters.Add(txtLastName.Text);
                parameters.Add(txtResNo.Text);
                parameters.Add(txtEmail.Text);
                parameters.Add(txtAddress.Text);
                parameters.Add(drpdwnProgState.SelectedItem.Text);
                //new parameters
                parameters.Add(txtDriver.Text);//Driver_Name
                parameters.Add(txtFltTime.Text);//AirLine_Time
                parameters.Add(txtTrpTyp.Text);//Airport_Trip
                parameters.Add(drpdwnFrType.Text);//Fare_Type
                parameters.Add(Math.Round(Convert.ToDecimal(txtFare.Text)));//Cost
                parameters.Add(txtRundTrp.Text);//Round_Trip
                parameters.Add(txtRdTyp.Text);//Ride_Type
                parameters.Add(txtFltNo.Text);//AirLine_Name
                parameters.Add(txtComments.Text);//Comments
                int result = objDalSky.UpdateReservationGrid(parameters);
            }
            catch (Exception)
            {
               
                throw;
            }


            grdvwReservation.EditIndex = -1;
            setGridData();
        }

//
        protected void grdvwReservation_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow ||
            e.Row.RowType == DataControlRowType.Header ||
            e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[0].Visible = false;
                e.Row.Cells[15].Visible = false;
                e.Row.Cells[16].Visible = false;
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv = e.Row.DataItem as DataRowView;

                //Change the griview row color accourding to trip
                if (drv["Airport_Trip"].ToString() == "TO")
                {
                    e.Row.BackColor = System.Drawing.Color.FromName("#CCCC00");
                }
                else
                {
                    e.Row.BackColor = System.Drawing.Color.FromName("#CC99FF");
                }

                //Label txprogress = (Label)e.Row.FindControl("lblProgState");
               
                //remove the united state part from address
                string address = drv["Address"].ToString();
                e.Row.Cells[9].Text = address.Replace(", United States","");
               
           
              

                //bind the data on progress state dropdownlist
                if ((e.Row.RowState & DataControlRowState.Edit) > 0)
                {
                    DropDownList drpdwnProgState = (e.Row.FindControl("drpdwnProgState") as DropDownList);
                    //string progess = (e.Row.FindControl("lblDProgState") as Label).Text;
                    if (drpdwnProgState != null)
                    {
                        drpdwnProgState.Items.FindByValue(drv["Progress_State"].ToString()).Selected = true;
                    }
                }

                //bind the data on fare type dropdownlist
                if ((e.Row.RowState & DataControlRowState.Edit) > 0)
                {
                    DropDownList drpdwnFrTyp = (e.Row.FindControl("drpdwnFrTyp") as DropDownList);
                    //string progess = (e.Row.FindControl("lblDProgState") as Label).Text;
                    if (drpdwnFrTyp != null)
                    {
                       // drpdwnFrTyp.Items.FindByValue(drv["Fare_Type"].ToString()).Selected = true;

                    }
                }


                //Reservation delete Confirmation Javascript
                string item = drv["Reservation_No"].ToString();
                foreach (Button button in e.Row.Cells[20].Controls.OfType<Button>())
                {
                    if (button.CommandName == "Delete")
                    {
                        button.Attributes["onclick"] = "if(!confirm('Do you want to delete Reservation  " + item + "?')){ return false; };";
                    }
                }
            }
        }


  protected void grdvwReservation_SelectedIndexChanged(object sender, EventArgs e)
        {
         
            Session["resid"] = (grdvwReservation.SelectedRow.FindControl("lblResId") as Label).Text;
            Response.Redirect("EditReservation.aspx");
        }

        protected void grdvwReservation_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
          //get the reservation id from gridview. The reservation primarty key is set as the datakeynames
            int res_id = (int)grdvwReservation.DataKeys[e.RowIndex].Value;
            int result = objDalSky.DeleteReservation(res_id);
            setGridData();
           
        }

data access(reservation)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;

 public class DALSky
    { 
      public DataSet GetReservationById(int resid)
        {
            using (SqlConnection conn = DBConn.GetDbConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("usp_GetReservationByRId", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@resid",resid);
                   
                    SqlDataAdapter adp = new SqlDataAdapter(cmd);
                    DataSet dtst = new DataSet();
                    adp.Fill(dtst);
                    return dtst;

                }
                catch (Exception)
                {

                    throw;
                }
            }
        }

   //get reservation
        public DataSet GetReseravation()
        {
            using (SqlConnection Conn = DBConn.GetDbConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("usp_GetReservation", Conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                  
                    DataSet dtst = new DataSet();
                    SqlDataAdapter adp = new SqlDataAdapter(cmd);
                    adp.Fill(dtst);
                    return dtst;
                }
                catch (Exception)
                {

                    throw;
                }
            }
        }

        //set co line data
        public int SetReservation(ArrayList data)
        {
            using (SqlConnection Conn = DBConn.GetDbConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("usp_SetReservation", Conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@nvcAirport_Trip", data[0]);
                    cmd.Parameters.AddWithValue("@nvcRound_Trip", data[1]);
                    cmd.Parameters.AddWithValue("@nvcRide_Type", data[2]);
                    cmd.Parameters.AddWithValue("@inNumber_Of_Adult", data[3]);
                    cmd.Parameters.AddWithValue("@inNumber_Of_Children", data[4]);
                    cmd.Parameters.AddWithValue("@dtPickup_Date", data[5]);
                    cmd.Parameters.AddWithValue("@nvcFirst_Name", data[6]);
                    cmd.Parameters.AddWithValue("@nvcLast_Name", data[7]);
                    cmd.Parameters.AddWithValue("@nvcTelephoneNo", data[8]);
                    cmd.Parameters.AddWithValue("@nvcEmail", data[9]);
                    cmd.Parameters.AddWithValue("@nvcAirLine_Name", data[10]);
                    cmd.Parameters.AddWithValue("@dtAirLine_Time", data[11]);
                    cmd.Parameters.AddWithValue("@nvcAddress", data[12]);
                    cmd.Parameters.AddWithValue("@inTourLength", data[13]);
                    cmd.Parameters.AddWithValue("@dcCost", data[14]);
                    cmd.Parameters.AddWithValue("@nvcNo_Of_Bags", data[15]);
                    cmd.Parameters.AddWithValue("@nvcComments", data[16]);
                    cmd.Parameters.AddWithValue("@nvcReservation_No", data[17]);
                    cmd.Parameters.AddWithValue("@inRes_Id", data[18]);
                    cmd.Parameters.AddWithValue("@dtCreated_On", data[19]);
                   
                    return cmd.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }

//update reservation
    public int UpdateReservationGrid(ArrayList data)
        {
            using (SqlConnection Conn = DBConn.GetDbConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("usp_UpdateReservationGrid", Conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@resid", data[0]);
                    cmd.Parameters.AddWithValue("@dtPickup_Date", data[1]);
                    cmd.Parameters.AddWithValue("@nvcTelephoneNo", data[2]);
                    cmd.Parameters.AddWithValue("@nvcFirst_Name", data[3]);
                    cmd.Parameters.AddWithValue("@nvcLast_Name", data[4]);
                    cmd.Parameters.AddWithValue("@nvcReservation_No", data[5]);
                    cmd.Parameters.AddWithValue("@nvcEmail", data[6]);
                    cmd.Parameters.AddWithValue("@nvcAddress", data[7]);
                    cmd.Parameters.AddWithValue("@nvcProgress_State", data[8]);
                    //new parameters
                    cmd.Parameters.AddWithValue("@nvcDriver_Name", data[9]);
                    cmd.Parameters.AddWithValue("@dtAirLine_Time", data[10]);
                    cmd.Parameters.AddWithValue("@nvcAirport_Trip", data[11]);
                    cmd.Parameters.AddWithValue("@nvcFare_Type", data[12]);
                    cmd.Parameters.AddWithValue("@dcCost", data[13]);
                    cmd.Parameters.AddWithValue("@nvcRound_Trip", data[14]);
                    cmd.Parameters.AddWithValue("@nvcRide_Type", data[15]);
                    cmd.Parameters.AddWithValue("@nvcAirLine_Name", data[16]);
                    cmd.Parameters.AddWithValue("@nvcComments", data[17]);
                    return cmd.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }

data access class(DAL)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DALWatsans
{
    class DataAccess
    {
        public DataAccess()
        {

        }
        #region example of data accessing
        public DataSet Getdetails()
        {
            using (SqlConnection Conn = DBConn.GetDbConnection())
            {
                SqlCommand cmd = new SqlCommand("SP", Conn);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                DataSet dst = new DataSet();
                adp.Fill(dst);

                return dst;


            }
        }


        public void SetDetails(string name, string address, string phn)
        {
            using (SqlConnection Conn = DBConn.GetDbConnection())
            {
                SqlCommand cmd = new SqlCommand("SP", Conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@s_name", name);
                cmd.Parameters.AddWithValue("@s_address", address);
                cmd.Parameters.AddWithValue("@s_phn", phn);
                cmd.ExecuteNonQuery();



            }

        }

        public DataSet getdtl2()
        {
            using (SqlConnection Conn = DBConn.GetDbConnection())
            {

                string sql = "SELECT * FROM student";
                SqlCommand cmd = new SqlCommand(sql, Conn);
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                DataSet dst = new DataSet();
                adp.Fill(dst);

                return dst;
            }
        }

        #endregion
    }
}
/////////////////////////////////
 #region Get Item Search
        public DataSet GetItemSearch(ArrayList parameters)
        {
            using (SqlConnection conn = DBConn.GetDbConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("usp_GetItemSearch", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@nvcSEARCH", parameters[0]);
                    cmd.Parameters.AddWithValue("@inItemCatID", parameters[1]);
                    SqlDataAdapter adp = new SqlDataAdapter(cmd);
                    DataSet dtst = new DataSet();
                    adp.Fill(dtst);
                    return dtst;

                }
                catch (Exception)
                {

                    throw;
                }
            }
        }

database connection

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class DBConn
    {
        private static SqlConnection Conn;

        private DBConn()
        {
        }

        public static SqlConnection getDbConnection()
        {
            try
            {
                if (Conn == null)
                {
                    Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["watsandatabaseConnectionString"].ConnectionString);

                    Conn.Open();
                }

                else if (Conn.State == ConnectionState.Closed)
                {
                    Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["watsandatabaseConnectionString"].ToString());
                    Conn.Open();
                }


                return Conn;
            }
            catch (Exception)
            {
               
                throw;
            }
           
        }
    }
}

Tuesday, October 22, 2013

Add Item Sub Category

<%@ Page Title="Add New Sub Category" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Add_ItemSubCategory.aspx.cs" Inherits="Watson.Stock.Add_ItemSubCategory" %>
<%@ Register src="../UserControl/Notification.ascx" tagname="Notification" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
    rel="stylesheet" type="text/css" />
<script type="text/javascript">
    function ShowPopup(message) {
        $(function () {
           
            $("#dialog").dialog({
                title: "Item Category Popup",
                buttons: {
                    Close: function () {
                        $(this).dialog('close');
                    }
                },
                modal: true
            });
        });
    };
</script>
<div id="dialog" style="display: block" >

    <asp:GridView ID="grdvwCat" runat="server" CssClass="gridview"
        onselectedindexchanged="grdvwCat_SelectedIndexChanged"
        onrowcreated="grdvwCat_RowCreated" onrowdatabound="grdvwCat_RowDataBound">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
        </Columns>
    </asp:GridView>
<<<<<<< .mine
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
=======
 
>>>>>>> .r146
</div>

  <div class="divTable">
 <div class="divRow">
 <div class="divColumn"  style="width:100%;">
     <uc1:Notification ID="Notification1" runat="server" />
 </div>

 </div>
 </div>
 <div class="divTable">
           <br />
            <div class="divRow" style="text-align:left">
                <asp:Label ID="lblSubCatHeader" runat="server"
            Text="Add New Sub Category" Font-Bold="True" Font-Size="20px"></asp:Label>
            </div>
</div>
    <asp:Panel ID="pnl_addItmSubCatgry" CssClass="paneldashbord" Width="94%" runat="server">
        <div class="divTable">
          
            <div class="divRow" style="width: 100%">
               
                <div class="divColumn" style="width:10%">
                    <asp:Label ID="lblCatName" runat="server" Text="Name:"></asp:Label>
                </div>
                <div class="divColumn" style="width:30%">
                    <asp:TextBox ID="txtSubCatName" runat="server" Width="95%"></asp:TextBox>
                </div>
                <div class="divColumn" style="width:20%">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                        ControlToValidate="txtSubCatName" ErrorMessage="*"
                        ValidationGroup="valgrpCat" ForeColor="Red" ToolTip="Name is required"><img
                        src="../Images/exclamation.png" /></asp:RequiredFieldValidator>
                    <asp:Label ID="lblNamerror" runat="server" Text="Name is already exist"
                        Visible="False"></asp:Label>
                </div>
                <div class="divColumn" style="width:10%">
                </div>
                <div class="divColumn" style="width:20%">
                </div>
                <div class="divColumn" style="width:10%">
                </div>
            </div>
            <div class="divRow">
                <div class="divRow">
                   
                    <div class="divColumn" style="width:10%">
                        <asp:Label ID="Label1" runat="server" Text="Category"></asp:Label>
                        :</div>
                    <div class="divColumn" style="width:30%">
                        <asp:TextBox ID="txtCatName" runat="server" Width="95%" ReadOnly="True"></asp:TextBox>
                    </div>
                    <div class="divColumn" style="width:20%">
                       
                        <asp:Button ID="btnAddCat" runat="server" onclick="btnAddCat_Click" Text="--" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                            ControlToValidate="txtCatName" ErrorMessage="*" ForeColor="Red"
                            ValidationGroup="valgrpCat" ToolTip="category is required"><img
                            src="../Images/exclamation.png" /></asp:RequiredFieldValidator>
                        <asp:HiddenField ID="hdnfldCatId" runat="server" />
                    </div>
                    <div class="divColumn" style="width:10%">
                    </div>
                    <div class="divColumn" style="width:20%">
                    </div>
                    <div class="divColumn" style="width:10%">
                    </div>
                </div>
            </div>
            <div class="divRow" style="width: 100%">
               
                <div class="divColumn" style="width:10%">
                    <asp:Label ID="lblCatDes" runat="server" Text="Description:"></asp:Label>
                </div>
                <div class="divColumn" style="width:30%">
                    <asp:TextBox ID="txtSubCatDes" runat="server" TextMode="MultiLine" Width="95%"></asp:TextBox>
                </div>
                <div class="divColumn" style="width:20%">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                        ControlToValidate="txtSubCatDes" ErrorMessage="*"
                        ValidationGroup="valgrpCat" ForeColor="Red"
                        ToolTip="Description is required"><img
                        src="../Images/exclamation.png" /></asp:RequiredFieldValidator>
                </div>
                <div class="divColumn" style="width:10%">
                </div>
                <div class="divColumn" style="width:20%">
                </div>
                <div class="divColumn" style="width:10%">
                </div>
            </div>
            <div class="divRow" style="height:120px">
            </div>
            <div class="divRow">
            </div>
            <div class="divRow" style="width: 100%">
               
                <div class="divColumn" style="width:10%">
                </div>
                <div class="divColumn" style="width:30% ">
                    <div class="divColumn" style="width:40%; text-align:right;">
                        <asp:Button ID="btnSave" runat="server"
                            Text="Save" ValidationGroup="valgrpCat" onclick="btnSave_Click"
                            CssClass="btn_sav" />
                    </div>
                    <div class="divColumn" style="width:60%; text-align:right;">
                        <asp:Button ID="btnCancel" runat="server" onclick="btnCancel_Click"
                            Text="Cancel" CssClass="btn_cnl" />
                    </div>
                </div>
                <div class="divColumn" style="width:20%">
                </div>
                <div class="divColumn" style="width:10%">
                </div>
                <div class="divColumn" style="width:20%">
                </div>
                <div class="divColumn" style="width:10%">
                </div>
            </div>
        </div>
    </asp:Panel>
    </asp:Content>
........................................................................................................................................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DALWatsans;

namespace Watson.Stock
{
    public partial class Add_ItemSubCategory : System.Web.UI.Page
    {
        public DALItem dalItem;
        public Add_ItemSubCategory()
        {
            dalItem = new DALItem();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Notification1.HideMessages();
            //check session of catid and name
            if (Session["catid"] != null && Session["catname"] != null)
            {
                txtCatName.Text = Session["catname"].ToString();
            }

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("View_ItemSubCategory.aspx");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string subcatname = txtSubCatName.Text.Trim();
            int catid = Convert.ToInt32(hdnfldCatId.Value);
            string subcatdes = txtSubCatDes.Text.Trim();

            int result = dalItem.SetItemSubCategory(subcatname, catid, subcatdes);
            if (result == 2)
            {
                Notification1.FindControl("noticmsg").Visible = true;

                Label lblnotice = (Label)Notification1.FindControl("lblnotice");
                lblnotice.Text = Common.Common.GerErrorMessage("DE-02");

                Cleartxt();
            }
            else
            {
                lblNamerror.Visible = false;

                Notification1.FindControl("sucmsg").Visible = true;

                Label lblsuccess = (Label)Notification1.FindControl("lblsuccess");
                lblsuccess.Text = Common.Common.GerErrorMessage("DE-00");


                Cleartxt();
            }

        }

        protected void btnAddCat_Click(object sender, EventArgs e)
        {
            //SetGridData();
            //pnl_addItmSubCatgry.Visible = false;
            //pnl_selectCategory.Visible = true;
            DataSet dtst = dalItem.GetItemCategory();
            grdvwCat.DataSource = dtst;
            grdvwCat.DataBind();
            string message = "Message from server side";
            ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
           
        }

        protected void SetGridData()
        {
            DataSet dtst = dalItem.GetItemCategory();
            grdvwCat.DataSource = dtst;
            grdvwCat.DataBind();
        }

        #region Clear all Text Box
        /// <summary>
        /// Clear all text fields .
        /// Set Wizad active step as 0.
        /// </summary>
        private void Cleartxt()
        {



            foreach (Control cntrol in EnumerateControlsRecursive(Page))
            {
                if (cntrol is TextBox)
                {
                    TextBox txt = (TextBox)cntrol;
                    txt.Text = string.Empty;
                }
                else if (cntrol is DropDownList)
                {
                    DropDownList ddl = (DropDownList)cntrol;
                    ddl.SelectedIndex = 0;

                }
            }

        }

        /// <summary>
        /// Recursive function for get controls
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        IEnumerable<Control> EnumerateControlsRecursive(Control parent)
        {
            foreach (Control child in parent.Controls)
            {
                yield return child;
                foreach (Control descendant in EnumerateControlsRecursive(child))
                    yield return descendant;
            }
        }
        #endregion


        protected void grdvwCat_SelectedIndexChanged(object sender, EventArgs e)
        {
            hdnfldCatId.Value = grdvwCat.SelectedRow.Cells[1].Text.ToString();
            txtCatName.Text = grdvwCat.SelectedRow.Cells[2].Text.ToString();
            //pnl_addItmSubCatgry.Visible = true;
            //pnl_selectCategory.Visible = false;
        }

        protected void grdvwCat_RowCreated(object sender, GridViewRowEventArgs e)
        {

        }

        protected void grdvwCat_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow ||
            e.Row.RowType == DataControlRowType.Header ||
            e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[1].Visible = false;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Button1.Text = "NEW TEXT";
        }
    }
}

Popular Posts

Recent Posts

Text Widget

Powered by Blogger.

Find Us On Facebook

Flickr Images

Recent Posts

Video Of Day

Random Posts

Facebook

Random Posts

Advertising

Popular Posts