C#
文章平均质量分 64
zexu82
这个作者很懒,什么都没留下…
展开
-
get current project path
string path = AppDomain.CurrentDomain.BaseDirectory/*This is the best option all round. It will give you the base directory for class libraries, including those in ASP.NET applications.*/string s原创 2013-08-14 22:42:54 · 798 阅读 · 0 评论 -
custom format Property of business object for the data binding
This normally used for a generated business object. (nettier)get the business object. create a new Property Display Name, which based on property FirstName and Surname:The first line is importan原创 2011-08-03 00:55:40 · 390 阅读 · 0 评论 -
devexpress xtrareport
Create custom summary in End User Designer (script) (windows form) /////////////////////////////////////////////// select a label (sho原创 2011-09-30 19:09:28 · 1996 阅读 · 0 评论 -
xtraReport save to DB
// create the DatabaseReportStorage class which used to override the save, save as function. using System;using System.Collections.Ge原创 2011-10-04 01:23:05 · 2182 阅读 · 0 评论 -
constructor
// create constructor in its own class// use : A.GetCurrent(); create new if it not exist, if it exist, return it.Clas原创 2011-10-14 01:13:31 · 382 阅读 · 0 评论 -
ConnectionStringManager (build, edit connectionString in app.config file)
using riteweigh.core.interfaces;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Con原创 2011-09-23 17:11:59 · 549 阅读 · 0 评论 -
create custom Membership provider
// The first one must have connection string in the App.conig// first, inherits from Membership class (SqlMembershipProvider, or MemershipProvider ( this is an abstract class)) using System;原创 2011-06-17 00:39:00 · 504 阅读 · 0 评论 -
system setting manager, save or get system values from database
1. use Dictionary to get the system setting values from database; (name: string;;; value could be any type)2. create a public Property原创 2011-08-11 23:49:36 · 1138 阅读 · 0 评论 -
enum
enum DayOfWeek : byte{ Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}// Da原创 2011-01-13 02:17:00 · 285 阅读 · 0 评论 -
listbox bind datasource, refresh data
1, set the binding source, select the datasource from system business objectthis.listBox1.DataSource = this.iLicenseKeyBindingSource;thi原创 2011-08-04 19:53:25 · 1794 阅读 · 2 评论 -
c# , App.config
// c#if (!string.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["Interval"])) { string sValue = System.Configuration.ConfigurationSettings.AppSettings["Interval"]原创 2011-01-05 02:03:00 · 1208 阅读 · 0 评论 -
import export data from DataTable
CSV 1. return a stringpublic string ToStringAsCSV (DataTable dt, string delimited) { string text = ""; StringWriter sw = new StringWriter(); //原创 2011-08-16 23:50:55 · 1144 阅读 · 0 评论 -
Creating a Cookie Aware WebClient
C# has an object called WebClient that makes it easier to execute POSTs and GETs. But is doesn't handle the cookie.the follow class handle the cookies: public class CookieAwareWebClient : WebCli转载 2012-02-01 18:08:08 · 988 阅读 · 0 评论 -
sample transaction code
1.TransactionManager tran = DataRepository.Provider.CreateTransaction();tran.BeginTransaction();bool success = false;try{ // Save your data // do some inserts / updates / e原创 2011-01-13 01:28:00 · 589 阅读 · 0 评论 -
generate radom word
public abstract class RandomWordHelper { public static string GetRandomWord(int length, WordType wordType) { string alphabet = null; switch (wordType)原创 2013-01-15 17:45:34 · 301 阅读 · 0 评论 -
calculate all controls size and position in the form when the form resize
// class with calculate size and position of control.class UIElement { // those properties get the Control current size, font, position public Control Control { get; set; } publi原创 2012-09-25 18:30:22 · 403 阅读 · 0 评论 -
nettier Data Access Code
// query DepartmentQuery query = new DepartmentQuery(); query.Append(DepartmentColumn.DepartmentName, textBox_addDep.Text.Trim()); //AppendEquals - (if parameter with space, it wi原创 2011-05-24 22:08:00 · 602 阅读 · 0 评论 -
manully create, edit DataTable
/////////////////////// 1DataTable myTable;// Create an array for the values.object[] newRow = new object[3];// Set the values of the array.newRow[0] = "Hello";newRow[1] = "World";转载 2011-01-14 22:57:00 · 744 阅读 · 0 评论 -
nettier deepload
CustomerService service = new CustomerService(); var customer = service.GetByCustomerId(customerId); if (customer != null) { // 1原创 2012-04-23 17:16:29 · 515 阅读 · 0 评论 -
nettier business object validation code
protected override void AddValidationRules() { //Validation rules based on database schema. // string validate ValidationRules.AddRule(CommonRules.Str原创 2011-08-11 22:37:23 · 500 阅读 · 0 评论 -
ObjectDatasource and IDataErrorInfo with WinForms
1. create the form.2. create the Business-object Customer, implement the IDataErrorInfousing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Compon转载 2011-07-21 17:44:56 · 1528 阅读 · 0 评论 -
Custom data binding, window form
// custom ObjectPublic Class Customer{ // class to get set a string to format of (key=value;key=value;...;...;) private NVParser parser = new NVParser(); public Customer() { parser.原创 2012-05-01 00:44:12 · 391 阅读 · 0 评论 -
window form input validation && errorProvider
public contructor() { button.Enabled = false; textBox_IP.Tag = false; textBox_num.Tag = false;转载 2011-01-13 02:01:00 · 319 阅读 · 0 评论 -
C# listbox remove selected items
<br />while( list.SelectedIndices.Count > 0 )<br />{<br /> list.Items.RemoveAt(list.SelectedIndices[0]);<br />}转载 2010-12-02 17:55:00 · 1207 阅读 · 0 评论 -
window form 下拉菜单的动态加载
<br /><br />// Get the selected item in the combobox KeyValuePair<string, string> selectedPair = (KeyValuePair<string, string>)cboData.S转载 2010-12-01 19:43:00 · 1313 阅读 · 0 评论 -
TableLayoutPanel
<br />// Create TableLayoutPanel<br />TableLayoutPanel tlp = new TableLayoutPanel();<br /> <br />// Set the BorderStyle to Inset<br />tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;<br /> <br />// Grid has two columns<br />tlp.ColumnCount = 2;原创 2011-01-10 03:31:00 · 1313 阅读 · 0 评论 -
windows service event log
<br />record all window service information <br /> <br />start -> control panel -> administrative tools -> event viewer<br /> <br />C#<br /> <br />try<br />{}<br />catch (Exception e)<br />{<br /> <br /><br />System.Diagnostics.EventLog.WriteEntry("service转载 2011-01-10 03:37:00 · 544 阅读 · 0 评论 -
Cross-thread InvalidOperationException
C # not allowed the component be accessed by the thread which doesn't create it.it will cause error Cross-thread InvalidOperationException原创 2011-01-10 03:26:00 · 507 阅读 · 0 评论 -
process.start (shut down pc)
public static void shutDownPC(string _ip_name, int _delay, string _message, bool _allow_cancel) { try { string cmd = @"-m //" + _ip_name + " -s -t " + _delay; if (_message.Length != 0)原创 2011-01-13 02:29:00 · 324 阅读 · 0 评论 -
FormClosing event
<br /><br />点击 [關閉] 按鈕 (表單右上角帶有 X 的按鈕) or form.close() 时触发。<br />Closing 事件發生在表單正要關閉時.<br />當表單關閉時,將釋放物件內建立的所有資源.<br />取消 关闭:<br />// event <br />private void Form1_FormClosing(object sender, System.ComponentModel.CancelEventArgs e)<br />{<br /> // C转载 2011-01-10 03:21:00 · 489 阅读 · 0 评论 -
convert from to (byte [] array)
//convert from (byte[] len = 2) to a (short) staticint toShort(byte[] b, int startPos){// 0x00 0x11 [0x22 0x33] 0x44 0x55 short ret = (short) ((b[startPos] // [0x22] [0x33]// 0x22 //原创 2010-12-16 00:39:00 · 1041 阅读 · 0 评论 -
socket UDP
//receive UDP package publicclass Program{ privateconstint listenPort = 11000; publicstaticvoid Main(){Socket s = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram,ProtocolType.Udp);IPEndPoint ipep = new IPEndPoint(IPAddress.IPv6Any, listen原创 2010-12-16 00:56:00 · 409 阅读 · 0 评论 -
socket TCP
//receive TCP message classProgram{ staticvoid Main(string[] args){ constint PORT = 1979;// check the system support ipv6//if (!Socket.OSSupportsIPv6)//{原创 2010-12-16 00:46:00 · 333 阅读 · 0 评论 -
动态加载 usercontrol
private UserControl currentUserControl; private void button1_Click(object sender, System.EventArgs e) { if (this.currentUserControl != null) { this.panel1.Controls.Remove(currentUserControl); this.currentUserControl = null; } this.转载 2010-12-03 01:49:00 · 612 阅读 · 0 评论 -
windows service path, current application file path
// find current application file path at runtime:string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);// window service can not find file problem// window service default path is "C:/WINDOWS/system32", or %原创 2011-01-11 23:16:00 · 875 阅读 · 0 评论 -
log4.net
log4.net app.config and c# code转载 2011-01-17 22:46:00 · 774 阅读 · 0 评论 -
JSON - DataContractJsonSerializer
// convert JSON CLASS转载 2011-01-20 21:00:00 · 424 阅读 · 0 评论 -
nullable value
int? var = 5;int? result1 = var * 2;int result2 = (int) var * 2;int result3 = var*2 ?? 18; // if var is null, ?? set result3 = 1原创 2011-08-31 18:23:51 · 391 阅读 · 0 评论 -
form.AutoSize
Form.AutoSize is working on runtime, not working on design view, other controls.AutoSize is working on the design view. Form.AutoSize原创 2011-08-03 00:03:34 · 511 阅读 · 0 评论 -
GridView binding datasource
GridViewbinding datasourceAutoGenerateColumns = true;DataSource -> select the datasource; // IBindingDatasourceColumns -> add or r原创 2011-05-05 16:44:00 · 487 阅读 · 0 评论