Local 測試完畢後,接下來就要發佈到 Server 上。
專按按右鍵,選擇 Publish,選擇其中的 IIS, FTP, etc
decimal d = 0;
string s = "123.456";
if (decimal.TryParse(s, out d))
MessageBox.Show(d.ToString("N1"));
else
MessageBox.Show(s);
/// <summary>
/// MROUND 函數為:傳回四捨五入為所需倍數的數字。EX.MROUND(7,5)=>5 MROUND(8,5)=>10
/// </summary>
/// <param name="number">原始數值</param>
/// <param name="multiple">倍數因子 (計算0.5的倍數就傳0.5)</param>
/// <returns>計算後的結果,效果等同 Excel MROUND 公式</returns>
public static decimal GetMROUND(decimal number, double multiple)
{
return Math.Round(number / (decimal)multiple, MidpointRounding.AwayFromZero) * (decimal)multiple;
}
// 取得組件資訊內的版本 AssemblyName.GetAssemblyName(System.Windows.Forms.Application.ExecutablePath).Version.ToString();
// 判斷是否為發行版本 (否則 Debug 執行時會出錯)
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
MessageBox.Show(System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString());
}
string address = @"(79988)臺南市仁德區保安里99鄰保安路9段99號~90@!?+=-\|%$^#*&{}[]";
string pattern = @"[\d\W_]";
string replacement = "";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(address, replacement);private DateTimePicker cellDateTimePicker;初始化 Form1() 時加入
this.cellDateTimePicker = new DateTimePicker(); this.cellDateTimePicker.ValueChanged += new EventHandler(cellDateTimePicker_ValueChanged); //this.cellDateTimePicker.CloseUp += new EventHandler(cellDateTimePicker_CloseUp); this.cellDateTimePicker.Format = DateTimePickerFormat.Short; this.cellDateTimePicker.ShowCheckBox = true; this.cellDateTimePicker.Checked = true; this.cellDateTimePicker.Visible = false; this.dgvCertificate.Controls.Add(cellDateTimePicker);在 ValueChanged 事件加入對應方法 (cellDateTimePicker_ValueChanged),一些屬性設定。 最後將 DateTimePicker 加入 DataGridView 的 Controls 內 撰寫 cellDateTimePicker_ValueChanged
void cellDateTimePicker_ValueChanged(object sender, EventArgs e)
{
if (cellDateTimePicker.Checked)
{
//cellDateTimePicker.Format = DateTimePickerFormat.Short;
//cellDateTimePicker.CustomFormat = null;
dgvCurrent.CurrentCell.Value = cellDateTimePicker.Value.ToString("yyyy/MM/dd"); //convert the date as per your format
}
else
{
//cellDateTimePicker.Checked = false; // 採用checkbox,清除值要取消勾選
//cellDateTimePicker.Format = DateTimePickerFormat.Custom;
//cellDateTimePicker.CustomFormat = " ";
//cellDateTimePicker.forma
dgvCurrent.CurrentCell.Value = " ";
}
cellDateTimePicker.Visible = false;
}
在 DataGridView 的 CellBeginEdit 事件內加入判斷,對應的儲存格才用DateTimePicker取代
private void dgvCertificate_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
dgvCurrent = dgvCertificate;
// 如果欄位是證照日期就用之前宣告的 cellDateTimePicker 取代
// 也可以用 e.ColumnIndex == 1 判斷,用 Name 避免欄位移動又得修改
if ("certificate_CER_DATE".Equals(dgvCertificate.Columns[e.ColumnIndex].Name))
{
Rectangle tempRect = dgvCertificate.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
cellDateTimePicker.Location = tempRect.Location;
cellDateTimePicker.Width = tempRect.Width;
string s = dgvCurrent.CurrentCell.Value.ToString();
cellDateTimePicker.Value = (!"".Equals(s) && !"0001/1/1 上午 12:00:00".Equals(s)) ? DateTime.Parse(s) : DateTime.Today;
cellDateTimePicker.Checked = (!"".Equals(cellDateTimePicker.Value) && !"0001/1/1 上午 12:00:00".Equals(cellDateTimePicker.Value)) ? true : false;
cellDateTimePicker.Visible = true; //這行要放在所有設定之後
}
}
編輯結束後隱藏 DateTimePicker
private void dgvCertificate_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if ("certificate_CER_DATE".Equals(dgvCertificate.Columns[e.ColumnIndex].Name))
{
cellDateTimePicker.Visible = false;
}
//MessageBox.Show(dgvCertificate.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()+
// dgvCertificate.Rows[e.RowIndex].Cells[e.ColumnIndex].FormattedValue.ToString());
}