SHOWcode

2020年4月1日 星期三

C# 檔案操作法


C# 檔案操作方法



Directory.Exists(FILENAME); //是否有檔案

Directory.Delete(FILENAME); //刪除檔案

Directory.CreateDirectory(FILENAME); //創建檔案

System.IO.File.Move(FILENAME, FILENAME); //移動檔案


文字檔.txt String.Split(';') 轉陣列

文字檔.txt String.Split(';') 轉陣列


string_str.txt = aaa;bbb;ccc;ddd
try{

 System.IO.StreamReader sr = new System.IO.StreamReader("string_str.txt");

 string[] connect_string = sr.ReadToEnd().Split(';');

 string01 = connect_string[0].ToString();

 string02= connect_string[1].ToString();

 string03= connect_string[2].ToString();

 string04= connect_string[3].ToString();

 sr.Close();

 }catch
 {

 MessageBox.Show("Error");

 }


C# DataRow[] TO String

#region 輸入的VALUES

 string str_values = "";

 DataTable data_pigname = survive_data.DefaultView.ToTable(true, new string[] { "類別" });
 
 for (int i = 0; i < data_pigname.Rows.Count; i++){

   string str_mydata = "";

   str_values += " { name: '" + data_pigname.Rows[i][0] + "', data: [";

    for (int j = 1; j <= 12; j++){

      string str_my = ddl_time.SelectedItem.Text.Trim() + "/" + j.ToString().PadLeft(2, '0');

                    //.PadLeft(補0)

                    DataRow[] data_pignow = survive_data.Select("年月 = '" + str_my + "'and 類別 = '" + data_pigname.Rows[i][0] + "'");

                    if (data_pignow.Length != 0){
      str_mydata += data_pignow[0]["本月結存數"].ToString() + ",";

     }else{

                        str_mydata += "0,";

                    }


                }
   str_values += str_mydata.Substring(0, str_mydata.Length - 1) + "] },";

    }

    survive_actual = str_values.Substring(0, str_values.Length - 1);

  #endregion

MySQL獲取所有分類和每個分類的前N條記錄


原址:https://www.itread01.com/p/1133452.html

SELECT A1.*
FROM tb_sensor_values AS A1
INNER JOIN (
SELECT A.m_no,A.d_time
FROM tb_sensor_values AS A
LEFT JOIN tb_sensor_values AS B
ON A.m_no = B.m_no
AND A.d_time <= B.d_time
GROUP BY A.m_no,A.d_time
HAVING COUNT(B.d_time) <= 3
) AS B1
ON A1.m_no = B1.m_no
AND A1.d_time = B1.d_time
ORDER BY A1.m_no,A1.d_time DESC

Jenkins-mail

參考:http://www.linuxea.com/1767.html 前置作業略過~有空再補 Mailer Plugin post { success { emailext ( subject: &...