Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Примеры дипломов / ВКР_Ботов.pdf

Скачиваний:
35
Добавлен:
13.05.2015
Размер:
2 Мб
Скачать

// получение пути к View и проверка его существования

var path = string.Format("~/Views/{0}/{1}.aspx", controller, viewName);

path = filterContext.RequestContext.HttpContext.Server.MapPath(path);

return File.Exists(path);

}

/// Проверка, что запрос был сделан с мобильного устройства public static bool IsMobileSafari(HttpContextBase context)

{

var isMobileSafari = false;

if (context != null)

{

var userAgent = context.Request.UserAgent;

if (!string.IsNullOrEmpty(userAgent))

{

var iphoneIndex = userAgent.IndexOf("iphone", StringComparison.CurrentCultureIgnoreCase);

if (iphoneIndex > -1) isMobileSafari = true;

}

}

return isMobileSafari;

}

}

72

ПРИЛОЖЕНИЕ 4. Представление BillingInfo.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/_templates/Base.Master" Inherits="System.Web.Mvc.ViewPage<MainBL.Address>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> BillingInfo

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <% using (Html.BeginForm("SubmitBillInfo", "Checkout"))

{ %>

<table width="100%"> <tr>

<th>

Your Checkout Progress </th>

<th>

Billing Information </th>

</tr>

<tr>

<td style="vertical-align: top;"> <b>Billing Address</b><br /> Shipping Address<br /> Shipping Method<br /> Payment Method<br />

<p>

<%= Html.ValidationSummary() %> </p>

</td>

<td rowspan="2">

<table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr>

<td align="right"> * First Name

</td>

<td>

<%= Html.TextBox("FirstName", Model.FirstName)%> </td>

</tr>

<tr>

<td align="right"> * Last Name

</td>

<td>

<%= Html.TextBox("LastName", Model.LastName)%> </td>

</tr>

<tr>

<td align="right"> * Email Address

</td>

<td>

<%= Html.TextBox("Email", Model.Email)%> </td>

</tr>

<tr>

<td align="right"> * Address

</td>

<td>

<%= Html.TextBox("AddressLine1", Model.AddressLine1)%> </td>

</tr>

<tr>

<td>

</td>

<td>

<%= Html.TextBox("AddressLine2", Model.AddressLine2)%> </td>

</tr>

<tr>

<td align="right"> * City

</td>

<td>

<%= Html.TextBox("City", Model.City)%>

73

</td>

</tr>

<tr>

<td align="right">

* State / Province </td>

<td>

<%= Html.TextBox("State", Model.State) %> </td>

</tr>

<tr>

<td align="right">

* Zip / Postal Code </td>

<td>

<%= Html.TextBox("Zip", Model.Zip)%> </td>

</tr>

<tr>

<td align="right"> * Country

</td>

<td>

<%= Html.DropDownList("Country", new List<SelectListItem>(){ new SelectListItem(){ Value="", Text=""},

new SelectListItem(){ Value="AF", Text="Afghanistan"}, new SelectListItem(){ Value="AL", Text="Albania"}, new SelectListItem(){ Value="DZ", Text="Algeria"},

new SelectListItem(){ Value="AS", Text="American Samoa"}, new SelectListItem(){ Value="RU", Text="Russia"},

new SelectListItem(){ Value="ZW", Text="Zimbabwe"}}, Model.Country)%> </td>

</tr>

<tr>

<td align="right"> * Phone Number

</td>

<td>

<%= Html.TextBox("PhoneNumber", Model.PhoneNumber) %> </td>

</tr>

</table>

</td>

</tr>

<tr>

<td>

<%= Html.RadioButton("ShipAddressRadioButton","ToThis", true) %> Ship to this address

<br />

<%= Html.RadioButton("ShipAddressRadioButton", "ToDifferent")%> Ship to different address

</td>

</tr>

<tr>

<td>

<a href="<%= Url.RouteUrl(new RouteValueDictionary(new { controller = "Cart", action = "Index" })) %>">< Back</a>

</td>

<td>

<input type="submit" value="Continue" /> </td>

</tr>

</table> <% } %> </asp:Content>

74

ПРИЛОЖЕНИЕ 5. Представление BillingInfo.iPhone.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/_templates/Base.iPhone.Master"

Inherits="System.Web.Mvc.ViewPage<MainBL.Address>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> BillingInfo

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <% using (Html.BeginForm("SubmitBillInfo", "Checkout"))

{ %> <li>

<table width="84%"> <tr>

<th>

Billing Information </th>

</tr>

<tr>

<td>

<%= Html.ValidationSummary() %> </td>

</tr>

<tr>

<td>

<table>

<tr>

<td>

* First Name

<%= Html.TextBox("FirstName", Model.FirstName)%> </td>

</tr>

<tr>

<td>

* Last Name

<%= Html.TextBox("LastName", Model.LastName)%> </td>

</tr>

<tr>

<td>

* Email Address

<%= Html.TextBox("Email", Model.Email)%> </td>

</tr>

<tr>

<td>

* Address

<%= Html.TextBox("AddressLine1", Model.AddressLine1)%> </td>

</tr>

<tr>

<td>

<%= Html.TextBox("AddressLine2", Model.AddressLine2)%> </td>

</tr>

<tr>

<td>

* City

<%= Html.TextBox("City", Model.City)%> </td>

</tr>

<tr>

<td>

* State / Province

<%= Html.TextBox("State", Model.State) %> </td>

</tr>

<tr>

75

<td>

* Zip / Postal Code

<%= Html.TextBox("Zip", Model.Zip)%> </td>

</tr>

<tr>

<td>

* Country

<%= Html.DropDownList("Country", new

List<SelectListItem>(){

new SelectListItem(){ Value="", Text=""},

new SelectListItem(){ Value="AF", Text="Afghanistan"}, new SelectListItem(){ Value="AL", Text="Albania"},

new SelectListItem(){ Value="RU", Text="Russia"}, new SelectListItem(){ Value="ZW", Text="Zimbabwe"}},

Model.Country)%>

</td>

</tr>

<tr>

<td>

* Phone Number

<%= Html.TextBox("PhoneNumber", Model.PhoneNumber) %> </td>

</tr>

</table>

</td>

</tr>

<tr>

<td>

<%= Html.RadioButton("ShipAddressRadioButton", "ToThis", true, new { style="width:auto;" })%>

Ship to this address <br />

<%= Html.RadioButton("ShipAddressRadioButton", "ToDifferent", new { style = "width:auto;" })%>

Ship to different address </td>

</tr>

<tr>

<td>

</td>

</tr>

<tr>

<td>

<a href="<%= Url.RouteUrl(new RouteValueDictionary(new {

controller = "Cart",

action = "Index" })) %>">< Back</a>                   

<input type="submit" value="Continue" style="width: 50%;" /> </td>

</tr>

</table>

</li> <% } %>

</asp:Content>

76

ПРИЛОЖЕНИЕ 6. Генерируемый HTML для полновесного браузера

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1"> <title>BillingInfo </title>

<link href="/Content/common.css" rel="stylesheet" type="text/css" /> </head>

<body>

<div class="page"> <div id="header">

<div id="title"> <a href="/">

<h1>

Storus Magazine</h1>

</a>

</div>

<div id="logindisplay">

[ <a href="/Account/LogOn">Log On</a> ] </div>

<div id="headermenu">

<a href="#">My Account</a> <a href="/Cart/Index">My Cart(0?)</a> <a href="/Checkout/Index">

Checkout</a>

</div>

<div style="float: right; padding: 3px">

<input id="SearchTextBox" name="SearchTextBox" type="text" value="Enter Search Keyword ..." />

<input type="submit" value="GO" /> </div>

</div>

<div id="menucontainer"> <ul id="menu">

<li><a href="/c26/Category-Name-1">Category Name 1</a></li> <li><a href="/c27/Category-Name-2">Category Name 2</a></li> <li><a href="/c28/Category-Name-3">Category Name 3</a></li> <li><a href="/">Home</a></li>

<li><a href="/Home/About">About</a></li> </ul>

</div>

<div id="main">

<form action="/Checkout/SubmitBillInfo" method="post"> <table width="100%">

<tr>

<th>

Your Checkout Progress </th>

<th>

Billing Information </th>

</tr>

<tr>

<td style="vertical-align: top;"> <b>Billing Address</b><br /> Shipping Address<br /> Shipping Method<br /> Payment Method<br />

<p>

</p>

</td>

<td rowspan="2">

<table border="0" cellpadding="0" cellspacing="0"

width="100%">

<tr>

<td align="right"> * First Name

</td>

<td>

77

<input id="FirstName" name="FirstName" type="text"

value="" />

</td>

</tr>

<tr>

<td align="right"> * Last Name

</td>

<td>

<input id="LastName" name="LastName" type="text"

value="" />

</td>

</tr>

<tr>

<td align="right"> * Email Address

</td>

<td>

<input id="Email" name="Email" type="text"

value="" />

</td>

</tr>

<tr>

<td align="right"> * Address

</td>

<td>

<input id="AddressLine1" name="AddressLine1"

type="text" value="" />

</td>

</tr>

<tr>

<td>

</td>

<td>

<input id="AddressLine2" name="AddressLine2"

type="text" value="" />

</td>

</tr>

<tr>

<td align="right"> * City

</td>

<td>

<input id="City" name="City" type="text" value=""

/>

</td>

</tr>

<tr>

<td align="right">

* State / Province </td>

<td>

<input id="State" name="State" type="text"

value="" />

</td>

</tr>

<tr>

<td align="right">

* Zip / Postal Code </td>

<td>

<input id="Zip" name="Zip" type="text" value="" /> </td>

</tr>

<tr>

<td align="right"> * Country

</td>

<td>

78

<select id="Country" name="Country"> <option value=""></option>

<option value="RU">Russia</option> </select>

</td>

</tr>

<tr>

<td align="right"> * Phone Number

</td>

<td>

<input id="PhoneNumber" name="PhoneNumber"

type="text" value="" />

</td>

</tr>

</table>

</td>

</tr>

<tr>

<td>

<input checked="checked" id="ShipAddressRadioButton" name="ShipAddressRadioButton"

type="radio" value="ToThis" /> Ship to this address

<br />

<input id="ShipAddressRadioButton" name="ShipAddressRadioButton" type="radio" value="ToDifferent" />

Ship to different address </td>

</tr>

<tr>

<td>

<a href="/Cart/Index">< Back</a> </td>

<td>

<input type="submit" value="Continue" /> </td>

</tr>

</table>

</form>

</div>

<div>

<h1>

Storus Magazine Footer</h1>

</div>

</div>

</body>

</html>

79

ПРИЛОЖЕНИЕ 7. Использование платежного шлюза Authorize.Net

protected Order SubmitToAuthorize(Order order)

{

//Словарь для расшифровки получаемых с шлюза сообщений

Dictionary<string, string> errorDecode = new Dictionary<string, string>(); errorDecode.Add("4", "The code returned from the processor indicating that the

card used needs to be picked up.");

. . .

errorDecode.Add("100", "Applicable only to eCheck.Net. The value specified in the x_echeck_type field is invalid.");

string strPost; //Секретные ключи

string testMerchantKey = "7h47qLB222F9"; string testTransactionKey = "6rWUm9Z755sz44aR";

order = OrderBL.UpdateInvoiceNumber(order.OrderID, CalculateOrderNumber(order.OrderID));

//Формирование строки запроса

strPost = ("x_login=" + testMerchantKey + "&x_tran_key=" + testTransactionKey); strPost += ("&x_method=CC&x_type=AUTH_CAPTURE");

strPost += ("&x_amount=" + order.Total.ToString());

strPost += ("&x_cust_id=" + order.CustomerID.ToString());

strPost += ("&x_first_name=" + order.BillingAddress.FirstName); strPost += ("&x_last_name=" + order.BillingAddress.LastName);

strPost += "&x_address=" + order.BillingAddress.AddressLine1; strPost += "&x_city=" + order.BillingAddress.City;

strPost += "&x_state=" + order.BillingAddress.State; strPost += "&x_zip=" + order.BillingAddress.Zip;

strPost += ("&x_country=" + order.BillingAddress.Country); strPost += ("&x_phone=" + order.BillingAddress.PhoneNumber); strPost += ("&x_email=" + order.BillingAddress.Email);

strPost += ("&x_ship_to_first_name=" + order.ShippingAddress.FirstName); strPost += ("&x_ship_to_last_name=" + order.ShippingAddress.LastName);

strPost += "&x_ship_to_address=" + order.ShippingAddress.AddressLine1; strPost += "&x_ship_to_city=" + order.ShippingAddress.City;

strPost += "&x_ship_to_state=" + order.ShippingAddress.State; strPost += "&x_ship_to_zip=" + order.ShippingAddress.Zip;

strPost += ("&x_ship_to_country=" + order.ShippingAddress.Country);

strPost += ("&x_customer_ip=" + Request.ServerVariables["REMOTE_ADDR"]); strPost += ("&x_invoice_num=" + order.InvoiceNumber);

strPost += ("&x_delim_data=TRUE&x_delim_char=|&x_relay_response=FALSE"); strPost += ("&x_card_num=" + Session["CreditCardNumber"].ToString()); strPost += ("&x_exp_date=" + Session["ExpirationMonth"].ToString() +

Session["ExpirationYear"].ToString());

strPost += ("&x_test_request=TRUE&x_version=3.1");

//Формирование запроса

System.IO.StreamWriter myWriter = null;

string url = "https://secure.authorize.net/gateway/transact.dll"; url = "https://test.authorize.net/gateway/transact.dll";

System.Net.WebRequest objRequest = System.Net.HttpWebRequest.Create(url); objRequest.Method = "POST";

objRequest.ContentLength = strPost.Length;

80

objRequest.ContentType = "application/x-www-form-urlencoded";

try

{

//Осуществление запроса

myWriter = new System.IO.StreamWriter(objRequest.GetRequestStream()); myWriter.Write(strPost);

}

catch (Exception)

{

//Обработка ошибок

}

finally

{

//Закрытие соединения myWriter.Close();

}

System.Net.HttpWebResponse objResponse = (System.Net.HttpWebResponse)objRequest.GetResponse();

System.IO.StreamReader sr = new System.IO.StreamReader(objResponse.GetResponseStream());

string result_ = sr.ReadToEnd();

// Close and clean up the StreamReader sr.Close();

//Обработка реультатов запроса

string[] arrResult = result_.Split('|'); if (double.Parse(arrResult[0]) == 1)

{

order.TransactionID = arrResult[6];

}

else

{

string errorMessage = "";

if (errorDecode.Keys.Contains(arrResult[2])) errorMessage = errorDecode[arrResult[2]];

else

errorMessage = arrResult[3];

throw new Exception(errorMessage);

}

return order;

}

81

Соседние файлы в папке Примеры дипломов