المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : AboutWinform



C# Programming
07-02-2009, 12:40 PM
Programusing System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace PrizeLotteryAdmin
{
static class Program
{
///
/// ??????????
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LoginForm login = new LoginForm();
login.ShowDialog();
if (login.DialogResult.Equals(DialogResult.OK))
{
login.Close();
Application.Run(new MainForm());
}

}
}
}

NewAwardFormusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PrizeLotteryBLL;
using System.Text.RegularExpressions;
using System.IO;

namespace PrizeLotteryAdmin
{
public partial class NewAwardForm : Form
{
public NewAwardForm(MainForm mainForm)
{
InitializeComponent();
this.MForm = mainForm;
}
public MainForm MForm;
private void btnOk_Click(object sender, EventArgs e)
{
if (Valid())
{
if (this.tbxName.Text != null && this.tbxName.Text.Trim().Length != 0)
{
LotteryOperatorBLL lobll = new LotteryOperatorBLL();
string path = Path.Combine(Application.StartupPath, @"Config\SettingConfig.xml");
if (lobll.IsExistGradeName(path, this.tbxName.Text))
{
MessageBox.Show("???????!");
}
else
{
GradeSetting gs = new GradeSetting();
gs.Count = Convert.ToInt32(this.tbxCount.Text);
gs.Name = this.tbxName.Text;
gs.Probability=Convert.ToDouble(this.tbxProbability.Text)/100;
gs.Desc = this.tbxDesc.Text;
gs.Value = 1;
this.Close();
lobll.AddConfig(path, gs);
MForm.BuildAwardTable();
}
}
else
{
MessageBox.Show("??????!");
this.tbxName.Focus();
}
}
}
private bool Valid()
{
bool rtnValue = false;

string countString = this.tbxCount.Text;
string probabilityString = this.tbxProbability.Text;
string name = this.tbxName.Text;
string desc = this.tbxDesc.Text;
if (!ValidReg(@"\d{1,"+Math.Max(countString.Length,1)+"}", countString))
{
MessageBox.Show("??????????!");
this.tbxCount.Focus();
}
else if (!ValidReg(@"[.\d]{1,"+Math.Max(probabilityString.Length,1)+"}", probabilityString))
{
MessageBox.Show("??????????!");
this.tbxProbability.Focus();
}
else if (Convert.ToDouble(probabilityString) > 100 || Convert.ToDouble(probabilityString) < 0)
{
MessageBox.Show("????????0-100?????!");
this.tbxProbability.Focus();
}
else if (name.Trim().Length < 0)
{
MessageBox.Show("???????!");
this.tbxName.Focus();
}
else if (desc.Trim().Length < 0)
{
MessageBox.Show("???????!");
this.tbxDesc.Focus();
}
else
{
rtnValue = true;
}

return rtnValue;
}
private bool ValidReg(string reg, string value)
{
bool rtnValue = false;

rtnValue= Regex.IsMatch(value, reg);

return rtnValue;
}

private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}


NewAwardForm.designer.cs
namespace PrizeLotteryAdmin
{
partial class NewAwardForm
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;

///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button();
this.tbxName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.tbxDesc = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.tbxCount = new System.Windows.Forms.TextBox();
this.tbxProbability = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnCancel
//
this.btnCancel.******** = new System.Drawing.Point(190, 154);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 5;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnOk
//
this.btnOk.******** = new System.Drawing.Point(51, 154);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 23);
this.btnOk.TabIndex = 4;
this.btnOk.Text = "OK";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// tbxName
//
this.tbxName.******** = new System.Drawing.Point(92, 44);
this.tbxName.Name = "tbxName";
this.tbxName.Size = new System.Drawing.Size(197, 21);
this.tbxName.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.******** = new System.Drawing.Point(27, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(59, 12);
this.label1.TabIndex = 4;
this.label1.Text = "????:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.******** = new System.Drawing.Point(27, 20);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(59, 12);
this.label2.TabIndex = 8;
this.label2.Text = "????:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.******** = new System.Drawing.Point(161, 20);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(59, 12);
this.label3.TabIndex = 10;
this.label3.Text = "????:";
//
// tbxDesc
//
this.tbxDesc.******** = new System.Drawing.Point(92, 71);
this.tbxDesc.Multiline = true;
this.tbxDesc.Name = "tbxDesc";
this.tbxDesc.Size = new System.Drawing.Size(197, 66);
this.tbxDesc.TabIndex = 3;
//
// label4
//
this.label4.AutoSize = true;
this.label4.******** = new System.Drawing.Point(27, 74);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(59, 12);
this.label4.TabIndex = 12;
this.label4.Text = "????:";
//
// tbxCount
//
this.tbxCount.******** = new System.Drawing.Point(92, 17);
this.tbxCount.Name = "tbxCount";
this.tbxCount.Size = new System.Drawing.Size(63, 21);
this.tbxCount.TabIndex = 0;
//
// tbxProbability
//
this.tbxProbability.******** = new System.Drawing.Point(226, 17);
this.tbxProbability.Name = "tbxProbability";
this.tbxProbability.Size = new System.Drawing.Size(39, 21);
this.tbxProbability.TabIndex = 1;
//
// label5
//
this.label5.AutoSize = true;
this.label5.******** = new System.Drawing.Point(271, 20);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(11, 12);
this.label5.TabIndex = 16;
this.label5.Text = "%";
//
// NewAwardForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
this.ClientSize = new System.Drawing.Size(313, 192);
this.Controls.Add(this.label5);
this.Controls.Add(this.tbxProbability);
this.Controls.Add(this.tbxCount);
this.Controls.Add(this.tbxDesc);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.tbxName);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "NewAwardForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "NewAwardForm";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.TextBox tbxName;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tbxDesc;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox tbxCount;
private System.Windows.Forms.TextBox tbxProbability;
private System.Windows.Forms.Label label5;
}
}