Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)//when the admin opens the "view services" page this code will be run first
            {
                //This opens and creates a connection with the database
                SqlConnection _Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ado"].ToString());
                _Connection.Open();
                //stores sql into a variable called sqlstring which will be the query for the database
                //This query will return the details of the service
                string SqlString = "select b.service_choice,  b.service_long_name,  b.service_short_name,  c.price_id, c.price, c.effective_date, c.service_choice, b.enabled from service b, service_price c where b.service_choice = c.service_choice and c.price_id = (select max(price_id) from service_price d where d.service_choice = c.service_choice  and d.effective_date <= getdate()) order by b.service_choice ASC";
                //This query will ask for all the necessary data that the admin needs to see about the Services offered
                //it first stores the sql in sqlString and then passes it to in to the ReadRecord class

                //Executes the sql on the database and returns the response object
                Base_Response _Response = GenericServices.ReadRecord.ProcessRead(SqlString, _Connection);
                _Connection.Close();

                if (_Response.TransactionCompleted)//Checks if the query has been sent to the database
                {
                    //dv of dataView type stores the data from the database throught the dataTable ResponseTable in readRecord class,which holds the data table passed from the database, and display it to the admin
                    DataView dv = new DataView(GenericServices.ReadRecord.ResponseTable);
                    ItemsList.DataSource = dv;
                    ItemsList.DataBind();
                }
                else
                {
                    //Show an error message on the screen.
                    lblErrorMessage.Text = _Response.ResponseMessage;//e.g. "The database is currently not available or your search return no values";
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 取得資料
        /// </summary>
        /// <param name="SearchModel">搜尋條件</param>
        /// <returns>結果</returns>
        // GET: api/TaiwanAir/
        public HttpResponseMessage Get([FromUri] SearchModel SearchModel)
        {
            _RequestModel.SearchModel = SearchModel;

            try
            {
                Response_TaiwanAirModel responseModel = _Service.Get(_RequestModel, ref _Result);
                _Response = Text.CopyModel <Result, Base_Response>(_Result);

                if (_Result.Success == true)
                {
                    _Response.CurrentPage = _RequestModel.SearchModel.CurrentPage;
                    _Response.Total       = responseModel.TaiwanAir.Count();
                    _Response.Data        = responseModel.TaiwanAir.Skip((SearchModel.CurrentPage - 1) * SearchModel.PageSize).Take(SearchModel.PageSize);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, _Response));
            }
            catch (Exception ex)
            {
                _Response.Success = false;
                _Response.Message = ex.Message.ToString();
                return(Request.CreateResponse(HttpStatusCode.BadRequest, _Response));
            }
        }
Пример #3
0
        public HttpResponseMessage Put([FromBody] NGDemo_Models.DBModels.TaiwanAir DBModel)
        {
            try
            {
                if (DBModel == null)
                {
                    ModelState.AddModelError("", "請輸入資料 !!");
                }
                if (ModelState.IsValid == false)
                {
                    _Response.Success = ModelState.IsValid;
                    _Response.Message = ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage));
                    return(Request.CreateResponse(HttpStatusCode.OK, _Response));
                }
                else
                {
                    _RequestModel.TaiwanAir = DBModel;
                    _Service.Edit(_RequestModel, ref _Result);
                    _Response = Text.CopyModel <Result, Base_Response>(_Result);

                    return(Request.CreateResponse(HttpStatusCode.OK, _Response));
                }
            }
            catch (Exception ex)
            {
                _Response.Success = false;
                _Response.Message = ex.Message.ToString();
                return(Request.CreateResponse(HttpStatusCode.BadRequest, _Response));
            }
        }
Пример #4
0
 /// <summary>
 /// 初始化
 /// </summary>
 public TaiwanAirController()
 {
     _Service      = new TaiwanAir();
     _Result       = new Result();
     _RequestModel = new Request_TaiwanAirModel();
     _Response     = new Base_Response();
 }
        public static string GetErrorInfoDetail(this Base_Response response)
        {
            var sb = new StringBuilder();

            if (response != null)
            {
                var referenceId = string.Format("VisaReferenceId:{0}", response.ReferenceId);
                sb.Append(referenceId);
                sb.AppendLine();

                var error  = response.GetError();
                var errMsg = string.Format("Error:{0}", error);
                sb.Append(errMsg);
                sb.AppendLine();

                var info    = response.GetInfo();
                var infoMsg = string.Format("Info:{0}", info);
                sb.Append(infoMsg);
                sb.AppendLine();
            }

            var errorInfoDetail = sb.ToString();

            return(errorInfoDetail);
        }
Пример #6
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            //If the "add" button is clicked after the admin has filled it up these lines of code will run
            //This opens and creates a connection with the database
            SqlConnection _Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ado"].ToString());

            _Connection.Open();

            if (hidID.Value == "0" || hidID.Value == "")//This checks if the information in the form belongs to a new service being created
            {
                //sqlString stores the sql for the new item to be inserted into the database's table called Service
                string SqlString = "Insert into Service(service_long_name,service_short_name,effective_date,created_by,enabled) values('" + txtServiceNameMain.Text + "','" + txtServiceNameShort.Text + "','" + txtEffectiveDate.SelectedDate.ToString("dd-MMM-yyyy") + "','" + txtCreatedBy.Text + "','" + chbEnabled.Checked.ToString().Substring(0, 1).ToUpper() + "') ";//This is the necessary information needed to be stored into the database inorder to create a new service

                //Executes the sql on the database and returns the response object
                Base_Response _Response = GenericServices.CreateRecord.Processcreate(SqlString, true, _Connection);


                //sqlString1 stores the sql for the new item to be inserted into the database's table called Service_Price
                string SqlString1 = "Insert into Service_price(service_choice, effective_date,price,created_by,enabled) values('" + _Response.NewID + "','" + txtEffectiveDate.SelectedDate.ToString("dd-MMM-yyyy") + "','" + txtPrice.Text + "','" + txtCreatedBy.Text + "','" + chbEnabled.Checked.ToString().Substring(0, 1).ToUpper() + "')";//This is the necessary information needed to be stored into the database inorder to allow the new service to have a price

                //Executes the sql on the database and returns the response object
                _Response = GenericServices.CreateRecord.Processcreate(SqlString1, true, _Connection);
            }
            else//This checks if the information in the form belongs to an existing service
            {
                //sqlString stores the sql for the updating item to be updated into the database
                string SqlString = " update ";// need to fix this so the price can change and store modified by
                SqlString += " service set ";
                SqlString += " service_long_name = '" + txtServiceNameMain.Text.ToString().Replace("'", "''") + "',";
                SqlString += " service_short_name='" + txtServiceNameShort.Text.ToString().Replace("'", "''") + "',";
                SqlString += " enabled='" + chbEnabled.Checked.ToString().Substring(0, 1).ToUpper() + "'";
                SqlString += " where service_choice ='" + hidID.Value + "'";

                //the code bellow does the insert into the database for when the admin changers the prices and so the database will keep record or when the prices changed
                double CurrentPrice = Convert.ToDouble(hidPrice.Value);
                double NewPrice     = Convert.ToDouble(txtPrice.Text);
                if (CurrentPrice != NewPrice)
                {
                    string SqlString1 = "Insert into Service_price(service_choice, effective_date,price,created_by,enabled) values('" + hidID.Value + "','" + txtEffectiveDate.SelectedDate.ToString("dd-MMM-yyyy") + "','" + txtPrice.Text + "','" + txtCreatedBy.Text + "','" + chbEnabled.Checked.ToString().Substring(0, 1).ToUpper() + "')";//This is the necessary information needed to be stored into the database inorder to allow the new service to have a price

                    //Executes the sql on the database and returns the response object
                    Base_Response _Response2 = GenericServices.CreateRecord.Processcreate(SqlString1, true, _Connection);
                }

                //Executes the sql on the database and returns the response object
                Base_Response _Response = GenericServices.UpdateRecord.ProcessUpdate(SqlString, _Connection);

                if (_Response.TransactionCompleted)
                {
                }
            }

            _Connection.Close();                         //Closes database

            Response.Redirect("~/pages/admin/services"); //Once the data has been passed to othe database the admin is returned to "View Services" page
        }
Пример #7
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection _Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ado"].ToString());//this will request and open the database in order to query it

            _Connection.Open();
            // this is the sql string that will send the filled in username and password information and pass it to the database to check if it matches the entry requirements but first it will pass it to the readRecord class in GenericServices class where it passes it to the database
            string SqlString = "select user_name[user_name], pwd[pwd] from company a where user_name = '" + txtUsername.Text + "'";
            //Executes the sql on the database and returns the response object
            Base_Response _Response = GenericServices.ReadRecord.ProcessRead(SqlString, _Connection);

            _Connection.Close();

            if (_Response.TransactionCompleted)                              //Checks if the query has been sent to the database
            {
                if (GenericServices.ReadRecord.ResponseTable.Rows.Count > 0) // This checks of the vairable ResponseTable has data stored in it
                {
                    //The following set of decisons will check if the data in the username and password fields much that of the ResponseTable variable in the ReadRecord class of GenericServices class,which holds the entry required username and password of the admin.

                    if (txtUsername.Text == GenericServices.ReadRecord.ResponseTable.Rows[0]["user_name"].ToString())//This statement checks if the usernames match
                    {
                        //if the username is correct, this statement checks if the password is correct
                        if (txtPassword.Text == GenericServices.ReadRecord.ResponseTable.Rows[0]["pwd"].ToString())
                        {
                            //This will create a new session for the admin to navigate in admins home page
                            Session.Add("Username", txtUsername.Text);
                            // redirect user
                            Response.Redirect("AdminHome.aspx");
                        }
                        else
                        {
                            //Show invalid password message
                            lblErrorMessage.Text = "Invalid user name and password combination";
                        }
                    }
                    else
                    {
                        //Show invalid username message
                        lblErrorMessage.Text = "Invalid user name and password combination";
                    }
                }
                else
                {
                    //Show invalid username message
                    lblErrorMessage.Text = "Invalid user name and password combination";
                }
            }
            else
            {
                //Shown if the data failed to reach the database
                lblErrorMessage.Text = _Response.ResponseMessage;
            }
        }
Пример #8
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         _RequestModel.TaiwanAir.TaiwanAir_ID = id;
         _Service.Delete(_RequestModel, ref _Result);
         _Response = Text.CopyModel <Result, Base_Response>(_Result);
         return(Request.CreateResponse(HttpStatusCode.OK, _Response));
     }
     catch (Exception ex)
     {
         _Response.Success = false;
         _Response.Message = ex.Message.ToString();
         return(Request.CreateResponse(HttpStatusCode.BadRequest, _Response));
     }
 }
        public static string GetInfo(this Base_Response response)
        {
            var sb = new StringBuilder();

            if (response != null)
            {
                if (response.Information != null && response.Information.Any())
                {
                    foreach (var information in response.Information)
                    {
                        var infoMsg = string.Format("{0} {1}", information.Code, information.Description);
                        sb.Append(infoMsg);
                        sb.AppendLine();
                    }
                }
            }

            var errorInfoDetail = sb.ToString();

            return(errorInfoDetail);
        }
        public static string GetError(this Base_Response response)
        {
            var sb = new StringBuilder();

            if (response != null)
            {
                if (response.Errors != null && response.Errors.Any())
                {
                    foreach (var responseError in response.Errors)
                    {
                        var errMsg = string.Format("{0} {1}", responseError.ErrorCode, responseError.ErrorMessage);
                        sb.Append(errMsg);
                        sb.AppendLine();
                    }
                }
            }

            var errorInfoDetail = sb.ToString();

            return(errorInfoDetail);
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!this.IsPostBack)//when the admin opens the "view bookings" page this code will be run first
     {
         //This opens and creates a connection with the database
         SqlConnection _Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ado"].ToString());
         _Connection.Open();
         //stores sql into a variable called sqlstring which will be the query for the database
         //This query will return the details of the booking
         string SqlString = "select a.booking_id,a.booking_date,a.booking_time_hour,a.booking_time_minute,a.first_name, a.last_name,a.mobile_no,a.email_address,a.service_choice,b.service_long_name,  a.created_by,a.date_time_created, a.modified_by,a.date_time_modified,a.price_no, a.enabled from booking a, service b where a.service_choice = b.service_choice";
         SqlString += " and a.booking_date >= '" + DateTime.Now.ToString("dd-MMM-yyyy") + "'order by booking_date ASC,booking_time_hour ASC ";
         //This query will ask for all the necessary data that the admin needs to see about the up comming appointments
         //Executes the sql on the database and returns the response object
         Base_Response _Response = GenericServices.ReadRecord.ProcessRead(SqlString, _Connection);
         _Connection.Close();
         //dv of dataView type stores the data from the database throught the dataTable ResponseTable in readRecord class,which holds the data table passed from the database, and display it to the admin
         DataView dv = new DataView(GenericServices.ReadRecord.ResponseTable);
         ItemsList.DataSource = dv;
         ItemsList.DataBind();
     }
 }
Пример #12
0
        /// <summary>
        /// 取得單筆資料
        /// </summary>
        /// <param name="id">目標編號</param>
        /// <returns></returns>
        // GET: api/TaiwanAir/5
        public HttpResponseMessage Get(int id)
        {
            try
            {
                Response_TaiwanAirModel responseModel = _Service.Get(_RequestModel, ref _Result);
                _Response = Text.CopyModel <Result, Base_Response>(_Result);

                if (_Result.Success == true)
                {
                    _Response.Data = responseModel.TaiwanAir.Where(x => x.TaiwanAir_ID == id);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, _Response));
            }
            catch (Exception ex)
            {
                _Response.Success = false;
                _Response.Message = ex.Message.ToString();
                return(Request.CreateResponse(HttpStatusCode.BadRequest, _Response));
            }
        }
Пример #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)//when the customer is sent to "Checkout" page this code will be run first
            {
                //This opens and creates a connection with the database
                SqlConnection _Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ado"].ToString());
                _Connection.Open();
                //stores sql into a variable called sqlstring which will be the query for the database
                //This query will return the details of the booking
                string SqlString = "select a.booking_id,a.booking_date,a.booking_time_hour,a.booking_time_minute,a.first_name, a.last_name,a.service_choice,b.service_long_name, c.price from booking a, service b, service_price c where a.service_choice = b.service_choice and b.service_choice = c.service_choice and c.effective_date =(select max(effective_date) from service_price d where c.service_choice = d.service_choice and d.effective_date <=getdate()) ";
                SqlString += " and a.booking_id ='" + Request.QueryString["ID"] + "'";

                //Executes the sql on the database and returns the response object
                Base_Response _Response = GenericServices.ReadRecord.ProcessRead(SqlString, _Connection);
                _Connection.Close();//Closees the connection

                //dv, of type dataView, stores the data from the database from the dataTable ResponseTable in readRecord class, which holds the data table passed from the database, and then displays it to the customer
                DataView dv = new DataView(GenericServices.ReadRecord.ResponseTable);
                ItemsList.DataSource = dv;
                ItemsList.DataBind();
            }
        }
Пример #14
0
        public ResultCode GetResultCode(Base_Response response, string[] errors)
        {
            var resultCode = ResultCode.UnknownError;

            if (errors == null)
            {
                errors = VisaCallErrorConstants.VisaErrorToResultCodeMapping.Keys.ToArray();
            }

            foreach (var error in errors)
            {
                if (response.ContainsError(error))
                {
                    if (VisaCallErrorConstants.VisaErrorToResultCodeMapping.ContainsKey(error))
                    {
                        resultCode = VisaCallErrorConstants.VisaErrorToResultCodeMapping[error];
                        break;
                    }
                }
            }

            return(resultCode);
        }
        protected void btnSubmit_Click(object sender, EventArgs e)//This button is used to insert or update the database once it has been clicked
        {
            //The nexts lines of code is used to check if the admin is updating a customer's information or the customer has created a booking
            string ID = "";

            try
            {
                ID = Request.QueryString["id"].ToString();
            }
            catch
            {
            }

            if (ID == "")//This checks if the information in the form is the creation of a new booking
            {
                // DT will store the choosen time that the customer selected based on the 3 drop downs.
                DateTime DT = DateTime.Parse(ddlMonth.SelectedValue + "-" + ddlDay.SelectedValue + "-" + DateTime.Now.Year.ToString());
                //sqlString stores the sql for the new booking to be inserted into the database
                string SqlString = "insert into [booking] (first_name, last_name, mobile_no, email_address, service_choice, booking_date, booking_time_hour, booking_time_minute)";
                SqlString += " values (";
                SqlString += "'" + txtFirstName.Text + "',";
                SqlString += "'" + txtLastName.Text + "',";
                SqlString += "'" + txtPhone.Text + "',";
                SqlString += "'" + txtemail.Text + "',";
                SqlString += "'" + lsbService.SelectedValue + "',";
                SqlString += "'" + DT.ToString("dd-MMM-yyyy") + "',";
                SqlString += "'" + ddlTimes.SelectedValue + "',";
                SqlString += "'00'";
                SqlString += ")";
                // This is the necessary information needed to be stored into the database inorder to create a new booking
                //This opens and creates a connection with the database
                SqlConnection _Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ado"].ToString());
                _Connection.Open();

                //Executes the sql on the database and returns the response object
                Base_Response _Response = GenericServices.CreateRecord.Processcreate(SqlString, true, _Connection);
                _Connection.Close();//closes connection
                //once query has been sent to database to insert a new booking for the customer, they will be redirect to a checkout page to view service purchase
                Response.Redirect("Checkout/?ID=" + _Response.NewID);
            }
            else//if there is a ID that is passed this will update data in the database
            {
                // DT will store the choosen time that the customer selected based on the 3 drop downs.
                DateTime DT = DateTime.Parse(ddlMonth.SelectedValue + "-" + ddlDay.SelectedValue + "-" + DateTime.Now.Year.ToString());
                //sqlString stores the sql for the updating customer details on the booking in the table
                string SqlString = "update  [booking] set ";
                SqlString += "first_name = '" + txtFirstName.Text + "',";
                SqlString += "last_name = '" + txtLastName.Text + "',";
                SqlString += "mobile_no = '" + txtPhone.Text + "',";
                SqlString += " email_address ='" + txtemail.Text + "',";
                SqlString += " service_choice = '" + lsbService.SelectedValue + "',";
                SqlString += " booking_date = '" + DT.ToString("dd-MMM-yyyy") + "',";
                SqlString += " booking_time_hour = '" + ddlTimes.SelectedValue + "',";
                SqlString += " booking_time_minute = '00',";
                SqlString += " enabled = '" + chbEnabled.Checked.ToString().Substring(0, 1).ToUpper() + "'";
                SqlString += " where booking_id ='" + ID + "'";

                //This opens and creates a connection with the database
                SqlConnection _Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ado"].ToString());
                _Connection.Open();

                //Executes the sql on the database and returns the response object
                Base_Response _Response = GenericServices.UpdateRecord.ProcessUpdate(SqlString, _Connection);
                _Connection.Close();                   //closes connection

                Response.Redirect("../AdminBookings"); //Once the data has been passed to othe database the admin is returned to "View appointments" page
            }
        }
 public static bool HasError(this Base_Response response)
 {
     return(response != null && response.Errors != null && response.Errors.Any());
 }
 public static bool ContainsError(this Base_Response response, string errorCode)
 {
     return(response.HasError() && response.Errors.Any(e => string.Equals(e.ErrorCode, errorCode, StringComparison.OrdinalIgnoreCase)));
 }
Пример #18
0
 /// <summary>
 /// 初始化
 /// </summary>
 public AccountController()
 {
     _Response = new Base_Response();
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)             //when the admin is redirected to this page this code will be run first
            {
                for (int i = 1; i <= 12; i++) //This helps create teh month drop down by converting the months value in to worlds for the customer to see
                {
                    ListItem _LI = new ListItem();
                    _LI.Value = i.ToString();
                    _LI.Text  = i.ToString();


                    switch (i)//This switch chnagers the values into words
                    {
                    case 1:
                        _LI.Text  = "January";
                        _LI.Value = "1";
                        ddlMonth.Items.Add(_LI);

                        break;

                    case 2:
                        _LI.Text  = "February";
                        _LI.Value = "2";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 3:
                        _LI.Text  = "March";
                        _LI.Value = "3";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 4:
                        _LI.Text  = "April";
                        _LI.Value = "4";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 5:
                        _LI.Text  = "May";
                        _LI.Value = "5";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 6:
                        _LI.Text  = "June";
                        _LI.Value = "6";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 7:
                        _LI.Text  = "July";
                        _LI.Value = "7";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 8:
                        _LI.Text  = "August";
                        _LI.Value = "8";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 9:
                        _LI.Text  = "September";
                        _LI.Value = "9";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 10:
                        _LI.Text  = "October";
                        _LI.Value = "10";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 11:
                        _LI.Text  = "November";
                        _LI.Value = "11";
                        ddlMonth.Items.Add(_LI);
                        break;

                    case 12:
                        _LI.Text  = "December";
                        _LI.Value = "12";
                        ddlMonth.Items.Add(_LI);
                        break;
                    }
                }

                //This populates the month and day drop down list's with the current month and day
                ddlMonth.SelectedValue = DateTime.Now.Month.ToString();
                //This subroutine for the day is run first before the day drop down is given the current day
                PopulateDays(Convert.ToInt32(ddlMonth.SelectedValue));
                ddlDay.SelectedValue = DateTime.Now.Day.ToString();
                //This subroutine is run to fill the time drop down list


                //This opens and creates a connection with the database
                SqlConnection _Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ado"].ToString());
                _Connection.Open();
                //Stores sql into variable sqlstring2 which will be the query for the database
                string SqlString2 = "select b.service_choice,  b.service_long_name,  b.service_short_name,  c.price_id, c.price, c.effective_date, c.service_choice, b.enabled from service b, service_price c where b.service_choice = c.service_choice and b.enabled = 'T' and c.price_id = (select max(price_id) from service_price d where d.service_choice = c.service_choice  and d.effective_date <= getdate()) order by b.service_long_name ASC";
                //This query will ask for all the necessary data that the admin needs to see the services offered by the business
                //it first stores the sql in sqlString2 and then passes it to in to the ReadRecord class

                //Executes the sql on the database and returns the response object
                Base_Response _Response = GenericServices.ReadRecord.ProcessRead(SqlString2, _Connection);


                //dt ,of type dataTable, stores the data from response of the service call
                DataTable dt = GenericServices.ReadRecord.ResponseTable;
                //Populates and displays each service offered by the business into the service table/menu
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ListItem _LI = new ListItem();
                    _LI.Value = dt.Rows[i]["service_choice"].ToString();
                    _LI.Text  = dt.Rows[i]["service_short_name"].ToString() + " - " + dt.Rows[i]["service_long_name"].ToString() + " (£ " + Convert.ToDouble(dt.Rows[i]["price"].ToString()).ToString() + ")";

                    lsbService.Items.Add(_LI);
                }
                try//Protects the system from crashing
                {
                    //The next few lines of code are here for when the admin is requesting to update the customers details and appointment

                    //stores id of the customer
                    string ID = Request.QueryString["id"].ToString();
                    //If the ID exists on the query string then following code flows, which means the screen acts as an update and not an insert.
                    //stores sql into variable sqlstring which will be the query for the database
                    string SqlString = "select a.booking_id,a.booking_date,a.booking_time_hour,a.booking_time_minute,a.first_name, a.last_name,a.mobile_no,a.email_address,a.service_choice,b.service_long_name,  a.created_by,a.date_time_created, a.modified_by,a.date_time_modified,a.price_no, a.enabled from booking a, service b where a.service_choice = b.service_choice and a.booking_id = '" + ID + "'";
                    //This query will ask for all the necessary data that the admin needs to see the customer's appointment and it gets the correct customer information by it requesting the id ,of the customer generated when the customer created a booking, and sends it with the sql to create the neccessary table
                    //it first stores the sql in sqlString and then passes it to in to the ReadRecord class

                    //Executes the sql on the database and returns the response object
                    _Response = GenericServices.ReadRecord.ProcessRead(SqlString, _Connection);
                    _Connection.Close();//Closees the connection

                    //DT ,of dataTable type, stores the data from the database throught the dataTable ResponseTable in readRecord class,which holds the data table passed from the database
                    DataTable DT = GenericServices.ReadRecord.ResponseTable;

                    //These lines of code will pull out the necessary information from DT and store it correctly into the correct fields of the form and corrects them appropriately
                    txtFirstName.Text = DT.Rows[0]["first_name"].ToString();
                    txtLastName.Text  = DT.Rows[0]["last_name"].ToString();
                    txtPhone.Text     = DT.Rows[0]["mobile_no"].ToString();
                    txtemail.Text     = DT.Rows[0]["email_address"].ToString();

                    DateTime NewDate = DateTime.Parse(DT.Rows[0]["booking_date"].ToString());
                    Populatehours(NewDate.DayOfWeek);


                    lblHeading.Text          = "View Booking";
                    lsbService.SelectedValue = DT.Rows[0]["service_choice"].ToString();
                    if (DT.Rows[0]["enabled"].ToString() == "T")
                    {
                        chbEnabled.Checked = true;
                    }
                    else
                    {
                        chbEnabled.Checked = false;
                    }
                    chbEnabled.Enabled = true;

                    ddlMonth.SelectedValue = NewDate.Month.ToString();
                    ddlDay.SelectedValue   = NewDate.Day.ToString();
                    ddlTimes.SelectedValue = DT.Rows[0]["booking_time_hour"].ToString();
                }
                catch
                {
                    //The page will land here if there is no "ID" on the querystring therefore making the screen be used for insert records.
                    //This reveals the enabled button to the admin in order to cancel or uncancel a booking
                    Populatehours(DateTime.Now.DayOfWeek);
                    divEnabled.Visible = false;
                }

                _Connection.Close();//closes connection
            }
        }
Пример #20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack) //when the admin clicks the update button this code will be run first
            {
                try               //This is here to protect the system from crashing
                {
                    //The next few lines are for the updating service option.
                    //This line stores the id of the updating service inorder to pass it to the database through the ReadRecord class ,of GenericServices class, so that the services information can be fill out the fields that can be edited.
                    string        ID          = Request.QueryString["id"].ToString();
                    SqlConnection _Connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ado"].ToString());
                    _Connection.Open();//Requests and opens the database
                    //stores sql into a variable called sqlstring which will be the query for the database
                    //This query will return the details of the service
                    //the sql that will ask for the neccessary information about the service that is being updated
                    string SqlString = "select b.service_choice,  b.service_short_name, b.service_long_name,  c.price_id, c.price, c.effective_date, c.service_choice, b.enabled, b.effective_date[service_date] from service b, service_price c where b.service_choice = c.service_choice and c.price_id = (select max(price_id) from service_price d where d.service_choice = c.service_choice  and d.effective_date <= getdate()) and b.service_choice = '" + ID + "'";
                    //Executes the sql on the database and returns the response object
                    Base_Response _Response = GenericServices.ReadRecord.ProcessRead(SqlString, _Connection);
                    _Connection.Close();//closes database


                    if (_Response.TransactionCompleted)//Checks if the query has been sent to the database
                    {
                        //DT ,of dataTable type, stores the data from the database throught the dataTable ResponseTable in readRecord class,which holds the data table passed from the database
                        DataTable DT = GenericServices.ReadRecord.ResponseTable;

                        if (DT.Rows.Count > 0)//Checks if DT has data in it
                        {
                            //These lines of code will pull out the necessary information from DT and store it correctly into the correct fields of the form and corrects them appropriately
                            hidID.Value = ID;
                            txtServiceNameShort.Text = DT.Rows[0]["service_short_name"].ToString();
                            txtServiceNameMain.Text  = DT.Rows[0]["service_long_name"].ToString();
                            txtPrice.Text            = DT.Rows[0]["price"].ToString();
                            hidPrice.Value           = DT.Rows[0]["price"].ToString();


                            DateTime SelectedDate = DateTime.Parse(DT.Rows[0]["service_date"].ToString());
                            txtEffectiveDate.SelectedDate = SelectedDate;
                            txtEffectiveDate.VisibleDate  = SelectedDate;
                            lblHeading.Text = "Update Service";
                            lblCreator.Text = "Modified By:";

                            chbEnabled.Checked = false;
                            if (DT.Rows[0]["enabled"].ToString().ToLower() == "t")
                            {
                                chbEnabled.Checked = true;
                            }
                        }
                        else
                        {
                            //Error message handling goes here
                            lblErrorMessage.Text = _Response.ResponseMessage;
                        }
                    }
                    else
                    {
                        //Error message handling goes here
                        lblErrorMessage.Text = _Response.ResponseMessage;
                    }
                }
                catch
                {
                }
            }
        }