1.http 上传
private string HttpPostNew(string Url, string postDataStr)
{
byte[] postBytes = Encoding.GetEncoding("utf-8").GetBytes(postDataStr);
HttpWebRequest request = WebRequest.Create(Url) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = postBytes.Length;
Stream myRequestStream = request.GetRequestStream();
myRequestStream.Write(postBytes, 0, postBytes.Length);
myRequestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
2.sqlite 数据库助手
public class SQLiteHelper
{
SQLiteConnection m_dbConnection;
public SQLiteHelper()
{
string connectionstr = string.Format(@"Data Source=" + System.Environment.CurrentDirectory.ToString() + "//PWRSModelDB.db");
m_dbConnection = new SQLiteConnection(connectionstr);
if (m_dbConnection.State == ConnectionState.Closed)
m_dbConnection.Open();
}
public DataTable SelectALL(string sql)
{
DataTable ds = new DataTable();
try
{
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataAdapter sdp = new SQLiteDataAdapter(command);
sdp.Fill(ds);
sdp.Dispose();
return ds;
}
catch (Exception e)
{
return ds;
}
}
public bool insert_update_delete_Data(string sql)
{
try
{
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
}
}
3.分割字符
string[] arrTemp = "abc,abcd,abcdef,abcdefg,abcdefgh".Split(',');
4.Cskin窗体设定
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(63)))), ((int)(((byte)(65)))));
this.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(63)))), ((int)(((byte)(65)))));
this.CaptionBackColorBottom = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(63)))), ((int)(((byte)(65)))));
this.CaptionBackColorTop = System.Drawing.Color.FromArgb(((int)(((byte)(49)))), ((int)(((byte)(51)))), ((int)(((byte)(53)))));
this.CaptionFont = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.ClientSize = new System.Drawing.Size(1920, 1200);
this.InnerBorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(63)))), ((int)(((byte)(65)))));
this.Name = "MianForm";
this.Text = " Sokan";
this.TitleCenter = true;
this.TitleColor = System.Drawing.Color.White;
this.ResumeLayout(false);
5.线程间无效操作
CheckForIllegalCrossThreadCalls = false;