Wei-Meng Lee - C# 2008 Programmer's Reference

Здесь есть возможность читать онлайн «Wei-Meng Lee - C# 2008 Programmer's Reference» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2009, ISBN: 2009, Издательство: Wiley Publishing, Inc., Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

C# 2008 Programmer's Reference: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «C# 2008 Programmer's Reference»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

C# 2008 Programmers Reference provides a concise and thorough reference on all aspects of the language. Each chapter contains detailed code samples that provide a quick and easy way to understand the key concepts covered.

C# 2008 Programmer's Reference — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «C# 2008 Programmer's Reference», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

//---draws the signature---

private void DrawSignature(string value) {

_lines = new List>();

//---split into individual lines---

string[] lines = value.Split('\n');

//---for each individual line---

for (int i = 0; i <= lines.Length - 2; i++) {

//---split into individual points---

string[] ps = lines[i].Split('|');

_points = new List();

//---for each point---

for (int j = 0; j <= ps.Length - 2; j++) {

string[] xy = ps[j].Split(',');

_points.Add(new Point(

(Convert.ToDouble(xy[0])),

Convert.ToDouble(xy[1])));

}

_lines.Add(_points);

}

//---draws the signature---

for (int line = 0; line <= _lines.Count - 1; line++) {

_points = (List)_lines[line];

for (int i = 1; i <= _points.Count - 1; i++) {

Line sline = new Line() {

X1 = _points[i - 1].X,

Y1 = _points[i - 1].Y,

X2 = _points[i].X,

Y2 = _points[i].Y,

StrokeThickness = 2,

Stroke = new SolidColorBrush(Colors.Black)

};

SigPad.Children.Add(sline);

}

}

}

Code the MouseLeftButtonDownevent handler for the Loadbutton so that the series of signature lines can be loaded from isolated storage:

//---Load button---

void btnLoad_MouseLeftButtonDown(

object sender, MouseButtonEventArgs e) {

IsolatedStorageFile isoStore =

IsolatedStorageFile.GetUserStoreForApplication();

IsolatedStorageFileStream isoStream =

new IsolatedStorageFileStream("IsoStoreFile.txt",

FileMode.Open, isoStore);

StreamReader reader = new StreamReader(isoStream);

//---read all lines from the file---

string lines = reader.ReadToEnd();

//---draws the signature---

DrawSignature(lines);

txtStatus.Text = "Signature loaded!";

reader.Close();

isoStream.Close();

}

Code the MouseLeftButtonDownevent handler for the Clearbutton so that the signature can be cleared from the drawing pad:

//---Clear button---

void btnClear_MouseLeftButtonDown(

object sender, MouseButtonEventArgs e) {

_lines = new List>();

_points = new List();

//---iteratively clear all the signature lines---

int totalChild = SigPad.Children.Count - 2;

for (int i = 0; i <= totalChild; i++) {

SigPad.Children.RemoveAt(1);

}

txtStatus.Text = "Signature cleared!";

}

Press F5 to test the application. You can now sign and then save the signature. You can also load the saved signature (see Figure 19-72).

Figure 1972 Saving the Signature to Web Services One of these signatures isnt - фото 442

Figure 19-72

Saving the Signature to Web Services

One of these signatures isn't a lot of good unless you can send it to a Web Service. This section shows you how to do that.

Using the same project created in the previous section, add a new Web Site project to the current solution (see Figure 19-73).

Figure 1973 Select ASPNET Web Site and name the project SignatureWebSite - фото 443

Figure 19-73

Select ASP.NET Web Site, and name the project SignatureWebSite.

Add a new Web Service item to the Web Site project, and use its default name of WebService.asmx(see Figure 19-74).

Figure 1974 In the WebServicecsfile add the following lines using System - фото 444

Figure 19-74

In the WebService.csfile, add the following lines:

using System;

using System.Collections;

using System.Linq;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Xml.Linq;

using System.IO;

using System.Web.Script.Services;

///



/// Summary description for WebService ///

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

public class WebService : System.Web.Services.WebService {

...

...

}

Define the following two web methods:

[WebMethod]

public bool SaveSignature(string value) {

try {

File.WriteAllText(Server.MapPath(".") +

@"\Signature.txt", value);

return true;

} catch (Exception ex) {

return false;

}

}

[WebMethod]

public string GetSignature() {

string fileContents;

fileContents = File.ReadAllText(

Server.MapPath(".") + @"\Signature.txt");

return fileContents;

}

The SaveSignature()function saves the values of the signature into a text file. The GetSignature()function reads the content of the text file and returns the content to the caller.

In the Signatureproject, add a service reference (see Figure 19-75).

Figure 1975 Click the Discover button and then OK see Figure 1976 Figure - фото 445

Figure 19-75

Click the Discover button and then OK (see Figure 19-76).

Figure 1976 In Pagexamlcs modify the Save button as follows Save - фото 446

Figure 19-76

In Page.xaml.cs, modify the Save button as follows:

//---Save button---

void btnSave_MouseLeftButtonDown(

object sender, MouseButtonEventArgs e) {

try {

ServiceReference1.WebServiceSoapClient ws = new

Signature.ServiceReference1.WebServiceSoapClient();

//---wire up the event handler when the web service returns---

ws.SaveSignatureCompleted += new

EventHandler(ws_SaveSignatureCompleted);

//---calls the web service method---

ws.SaveSignatureAsync(GetSignatureLines());

} catch (Exception ex) {

txtStatus.Text = ex.ToString();

}

}

Here, you send the signature to the Web service asynchronously. When the Web Service call returns, the ws_SaveSignatureCompletedevent handler will be called.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «C# 2008 Programmer's Reference»

Представляем Вашему вниманию похожие книги на «C# 2008 Programmer's Reference» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «C# 2008 Programmer's Reference»

Обсуждение, отзывы о книге «C# 2008 Programmer's Reference» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x