Thursday, January 28, 2010

Program.cs

using System;
using System.Collections.Generic;
using System.Windows.Forms;

//51aspx
namespace PowerTalkClient
{
static class Program
{
///
/// 应用程序的主入口点。
///

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new LoginFrm());
// Application.Run(new PowerTalk());
}
}
}

Page.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using YYTetris.Piece;
using System.Windows.Threading;

namespace YYTetris
{
public partial class Page : UserControl
{
UIControl _control;

public Page()
{
InitializeComponent();

this.Loaded += new RoutedEventHandler(Page_Loaded);
}

void Page_Loaded(object sender, RoutedEventArgs e)
{
uc.Focus();

_control = new UIControl();
_control.GameOver += new EventHandler(_control_GameOver);
uc.DataContext = _control;

foreach (Block block in _control.Container)
{
canvasBox.Children.Add(block);
}

foreach (Block block in _control.NextContainer)
{
canvasBoxPrev.Children.Add(block);
}
}

void _control_GameOver(object sender, EventArgs e)
{
gameOver.Visibility = Visibility.Visible;
play.Content = "开始游戏";
}

private void uc_KeyDown(object sender, KeyEventArgs e)
{
if (_control.GameStatus != GameStatus.Play) return;

if (e.Key == Key.Left)
{
_control.MoveToLeft();
}
else if (e.Key == Key.Right)
{
_control.MoveToRight();
}
else if (e.Key == Key.Up)
{
_control.Rotate();
}
else if (e.Key == Key.Down)
{
_control.MoveToDown();
}
}

private void start_Click(object sender, RoutedEventArgs e)
{
if (play.Content.ToString() == "开始游戏")
{
if (_control.GameStatus == GameStatus.Over)
{
_control.Clear();
gameOver.Visibility = Visibility.Collapsed;
_control.Score = 0;
_control.Level = 0;
_control.RemoveRowCount = 0;
}

_control.Play();
play.Content = "暂停游戏";
}
else
{
_control.Pause();
play.Content = "开始游戏";
}
}
}
}

Helper.cs

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace YYTetris
{
public class Helper
{
public static Color GetColor(string color)
{
try
{
if (string.IsNullOrEmpty(color))
return Colors.Black;

if (color.Length == 7)
{
byte r = (byte)(Convert.ToUInt32(color.Substring(1, 2), 16));
byte g = (byte)(Convert.ToUInt32(color.Substring(3, 2), 16));
byte b = (byte)(Convert.ToUInt32(color.Substring(5, 2), 16));

return Color.FromArgb(255, r, g, b);
}
else
{
return Colors.Black;
}
}
catch
{
return Colors.Black;
}
}
}
}

YYTetris.sln

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YYTetris", "YYTetris\YYTetris.csproj", "{F99D7F07-3BEA-4FD1-8682-927AF941429F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YYTetris.Web", "YYTetris.Web\YYTetris.Web.csproj", "{C6F90CA1-BC62-40B1-BD8D-4D1152FC0106}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F99D7F07-3BEA-4FD1-8682-927AF941429F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F99D7F07-3BEA-4FD1-8682-927AF941429F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F99D7F07-3BEA-4FD1-8682-927AF941429F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F99D7F07-3BEA-4FD1-8682-927AF941429F}.Release|Any CPU.Build.0 = Release|Any CPU
{C6F90CA1-BC62-40B1-BD8D-4D1152FC0106}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6F90CA1-BC62-40B1-BD8D-4D1152FC0106}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6F90CA1-BC62-40B1-BD8D-4D1152FC0106}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6F90CA1-BC62-40B1-BD8D-4D1152FC0106}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

edit all GridView rows once

Practical projects in peacetime, in order to reduce round-trip to submit data, you can edit the GridView once all the rows, thereby greatly enhancing the user experience using the product. Here's what one editor to explain all the data in GridView row. In the following example, the database using the "ASP.NET 2.0 application development technology," a book Site \ App_Data \ under ASPNET20Book.mdb database. Examples of the data update the data source use SqlDataSource control's UpdateCommand property, but this method also applies to stored procedures, SQL statements and so on.

C#
<%@ Page Language="C#" Debug="true" %>





同时编辑 GridView的 多行



DataKeyNames="id" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"
OnRowCreated="GridView1_RowCreated">























ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ASPNET20Book.mdb;Persist Security Info=True"
ProviderName="System.Data.OleDb" SelectCommand="SELECT * FROM [Student]"
UpdateCommand="Update [Student] Set Title = @Title,Gender = @Gender,ClassName=@ClassName Where id=@id">







Note: For SQL Server databases, parameter names without @. Another Note: The different database types and different data sources, UpdateCommand = "Update [Student] Set Title = @ Title, Gender = @ Gender, ClassName = @ ClassName Where id = @ id" written and SqlDataSource1.UpdateParameters.Add (new Parameter ( "@ Title", TypeCode.String, ((TextBox) gvr.FindControl ( "txtTitle")). Text)); the wording may differ.

SQL Server Version

<%@ Page Language="C#" Debug="true" %>





同时编辑 GridView的 多行



DataKeyNames="id" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound"
OnRowCreated="GridView1_RowCreated">























ConnectionString="Persist Security Info=False;User ID=sa;Password=;Initial Catalog=Book;Server=."
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Student]"
UpdateCommand="Update [Student] Set Title = @Title,Gender = @Gender,ClassName=@ClassName Where id=@id">