using System.Diagnostics;

public void WriteToWindowsEvent(string aSource,string aMessage){

  if(!EventLog.SourceExists(aSource)){
    EventLog.CreateEventSource(aSource,"Project");
  }
  EventLog oLog = new EventLog("Project");
  oLog.Source = aSource;
  oLog.WriteEntry(aMessage ,EventLogEntryType.Error);
 
}

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

using System.Web.Mail;


MailMessage objMail = new MailMessage();

objMail.From = strMailFrom;
objMail.To = strTo;
objMail.Cc = strCC;
            
objMail.Bcc = strBCC;
objMail.Subject = strSubject;
            
objMail.Body = strBody;
objMail.BodyFormat = MailFormat.Html;

            
SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSettings["SmtpServer"];
SmtpMail.Send(objMail);

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

要使用以下的Class,你需要先引用 Microsoft Visual J# .NET Class Library,從引用(Add Reference)中,找到 "vjslib" 並引用它。

using java.io;
using java.util.zip;

public void CompressFile(string ZipFileName,string[] EntryFileName)
{
// Output stream
FileOutputStream fos = new FileOutputStream(ZipFileName);
// Tie to zip stream
ZipOutputStream zos = new ZipOutputStream(fos);
foreach(string strFileInput in EntryFileName)
{
  // Stream with source file
  FileInputStream fis = new FileInputStream(strFileInput);
  // It's our entry in zip
  string strFileNameWithoutPath=strFileInput;
  if(strFileInput.IndexOf(@"\")!=-1) //把路徑去掉,避免壓縮好的檔案包含完整路徑
    strFileNameWithoutPath=strFileInput.Substring(strFileInput.LastIndexOf(@"\")+1);

  ZipEntry ze = new ZipEntry(strFileNameWithoutPath);
  zos.putNextEntry(ze);
  sbyte[] buffer = new sbyte[1024];
  int len;
  // Read and write until done
  while((len = fis.read(buffer)) >= 0)
  {
    zos.write(buffer, 0, len);
  }
  fis.close();
}
 
// Close everything
zos.closeEntry();
zos.close();
fos.close();
}

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

Excel.Application objExcel_App = new Excel.Application();
Excel.Workbook objExcel_WB = (Excel.Workbook) objExcel_App.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel.Worksheet objExcel_WS = objExcel_WB.Worksheets[1] as Excel.Worksheet;
Excel.Range objExcel_RG = null;

try
{
objExcel_WS.Name = "Test Report";

// 設定第一列Excel內容
ArrayList alRow = new ArrayList();
object[] objRow = {"A","B","C","D"};
alRow.Add(objRow);

objExcel_RG = objExcel_WS.get_Range("A1","D1");    
objExcel_RG.GetType().InvokeMember("Value",BindingFlags.SetProperty,null,objExcel_RG,
     alRow.ToArray(typeof(object)) as object[]);


// 設定Excel格式
objExcel_RG.Font.Bold = true;
objExcel_RG.Font.Name = "Arial";
objExcel_RG.Font.Size = 10;

objExcel_RG.Font.Color = 255; //字型顏色
objExcel_RG.Interior.Color =
System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow); //背景顏色
objExcel_RG.VerticalAlignment = Excel.XlVAlign.xlVAlignTop; //垂直對齊
objExcel_RG.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;//水平對齊
objExcel_RG.EntireRow.AutoFit(); //自動調整列高
objExcel_RG.EntireColumn.AutoFit(); //自動調整欄寬

objExcel_WS.get_Range("A1", "B1").Merge(false); //設定A1:B1儲存格合併
objExcel_WS.get_Range("C:C",Type.Missing).NumberFormatLocal
= "@";  //設定C欄儲存格格式為文字
objExcel_WS.get_Range("D:D",Type.Missing).NumberFormatLocal
= "yyyy/MM/dd";  //設定C欄儲存格格式


Array.Clear(objColumnTemp,0,objColumnTemp.Length);              

objExcel_WS.SaveAs(strFilePath,Type.Missing,Type.Missing,Type.Missing
           ,Type.Missing,Type.Missing,Type.Missing
                    ,Type.Missing,Type.Missing);
                    
objExcel_App.Workbooks.Close();

}
catch(Exception exp)
{
    throw exp;
}
finally
{
      objExcel_App.Quit();
      System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcel_RG);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcel_WS);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcel_WB);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcel_App);
      GC.Collect();
}

objExcel_WS.get_Range(pricingUtil.ConvertToExcelColumn(iCol)+":"+pricingUtil.ConvertToExcelColumn(iCol),Type.Missing).NumberFormatLocal = "@";objExcel_WS.get_Range(pricingUtil.ConvertToExcelColumn(iCol)+":"+pricingUtil.ConvertToExcelColumn(iCol),Type.Missing).NumberFormatLocal = "@";

felixhuang 發表在 痞客邦 留言(3) 人氣()

想把Select的資料,直接轉換成Insert的SQL語法,到另一台電腦的DB執行嗎? 可以使用免費的工具程式 SQL Dumper

比如 : Select * From Table1 直接轉成 =>
         Insert Into Table1('A1','A2','A3',....)
         Insert Into Table1('B1','B2','B3',....)
         Insert Into Table1('C1','C2','C3',....)
         ........

SQL Dumper

 

SQL Server Dumper 下載官網 : http://www.ruizata.com/

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