所謂的程式打擂台就是把資料庫撈出來的"排好序的資料",一筆一筆的根據不同的變數,

會寫到不同的XML檔案,如果那個變數都是A的話,就繼續累積XML裡的項目,但是一但變數

變成B時,就先把A累積的XML項目寫到XML裡面,再從新累積B的XML項目

while (dr.Read())
{
F_Site_ID = dr["F_Site_ID"].ToString();
F_Type = dr["F_Type"].ToString();
F_ID = dr["F_ID"].ToString();
F_Title = dr["F_Title"].ToString();
F_URL = dr["F_URL"].ToString();
F_Target = dr["F_Target"].ToString();
F_Icon = (byte[])dr["F_Icon"];
F_Icon_Type = dr["F_Icon_Type"].ToString();
F_Path = dr["F_Path"].ToString();
F_Path = F_Path.Replace(@"/", @"\");

//以下為打擂台方法!!!創資料夾和檔案
//NowFile一開始是空字串
if (F_Path != NowFile)
{
if (NowFile != "")
{
TempXML = TempXML.Replace("you_can_replace_me", mystr);

StreamWriter sw = new StreamWriter(SavePath + NowFile + "xml\\" + FlashName + ".xml", false, System.Text.Encoding.UTF8);
sw.Write(TempXML);
sw.Flush();
sw.Close();
TempXML = mysb.ToString();
mystr = "";
}

DirectoryInfo dir = new DirectoryInfo(SavePath + F_Path);
DirectoryInfo dirImage = new DirectoryInfo(SavePath + F_Path + "Image");
DirectoryInfo dirXML = new DirectoryInfo(SavePath + F_Path + "xml");

dir.Create();
dirImage.Create();
dirXML.Create();
NowFile = F_Path;
}


//把圖片存到路徑去,F_Icon是二進位檔
File.WriteAllBytes(SavePath + F_Path + "Image\\" + F_ID + "." + F_Icon_Type, F_Icon);

//XML裡要取代的字串累加起來
string WebPath = F_Path + "Image\\" + F_ID + "." + F_Icon_Type;
WebPath = WebPath.Replace(@"\", @"/");

//第一個FlashStr是從XML讀進來的字串
//像是"Hello {0},I am {1}",然後再被string.Format後面
//的值依序取代掉{0}和{1}那些
mystr += string.Format(FlashStr, WebPath, F_URL, F_Target, F_Title);
mystr += Environment.NewLine; ;
}



//這裡是上面的While跑完後,再把最後的部分寫出到XML才完整
if (NowFile != "")
{
TempXML = TempXML.Replace("you_can_replace_me", mystr);


StreamWriter sw = new StreamWriter(SavePath + NowFile + "xml\\" + FlashName + ".xml", false, System.Text.Encoding.UTF8);
sw.Write(TempXML);
sw.Flush();
sw.Close();
}

arrow
arrow
    全站熱搜

    welkingunther 發表在 痞客邦 留言(0) 人氣()