/// <summary> /// 从OutLook中取出用户 /// </summary> /// <param name="fields"></param> /// <param name="ds"></param> /// <returns></returns> public static Boolean getMailAddressFromOUTLOOK(string[] fields, ref DataSet ds) { try { // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); //Get the MAPI namespace. Outlook.NameSpace oNS = oApp.Session; //Get the AddressLists collection. Outlook.AddressLists oALs = oNS.AddressLists; //Loop through the AddressLists collection. Outlook.AddressList oAL; for (int i = 1; i <= oALs.Count; i++) { oAL = (Outlook.AddressList)oALs.GetEnumerator().Current; // oALs.GetEnumerator().MoveNext(); } }//end of try block catch (System.Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); return(false); //MessageBox.Show("outllok " + ex.Message); } //end of catch return(true); } //end of Email Method
//************************************************************************ /// <summary> /// 指定したLocalNameに一致するすべて子孫の要素リストを格納しているHashtableを返します /// </summary> /// <param name="strLocalName">ローカルネーム</param> /// <param name="hashtable">テーブル</param> /// <returns>boolを戻す</returns> //************************************************************************ public bool GetElementsByName(string strLocalName, ref Hashtable hashtable) { bool bReturn = true; try { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(m_strXmlFile); XmlNodeList xmlNodeList = xmlDocument.GetElementsByTagName(strLocalName); foreach (XmlNode node in xmlNodeList) { if (strLocalName.ToLower() == "button") { NdnButtonProperty buttonProperty = new NdnButtonProperty(); buttonProperty.strName = node.Attributes["name"].InnerText; buttonProperty.strValue = node.Attributes["value"].InnerText; buttonProperty.bEnabled = node.Attributes["enabled"].InnerText == "true"; buttonProperty.bVisible = node.Attributes["visible"].InnerText == "true"; hashtable.Add(node.Attributes["name"].InnerText, buttonProperty); } else { hashtable.Add(node.Attributes["name"].InnerText, node.Attributes["value"].InnerText); } } } catch (Exception err) { bReturn = false; // NdnPublicFunction.WriteLog("", err.Message); NCLogger.GetInstance().WriteExceptionLog(err); } return(bReturn); }
//************************************************************************ /// <summary> /// 指定のデータベースのコネクションを開く /// </summary> /// <returns>データベースのコネクションを返す</returns> //************************************************************************ private static SqlConnection OpenConnection() { try { // データベース接続パラメータを取得 string m_strConnectionString = GetConnectionString(); s_conn = new SqlConnection(m_strConnectionString); // DBオープン s_conn.Open(); NCLogger.GetInstance().WriteDebugLog("Sql Connection is opened."); } catch (SqlException oex) { s_conn = null; NCLogger.GetInstance().WriteExceptionLog(oex); throw new NdnException("CM0410W"); } catch (Exception err) { s_conn = null; NCLogger.GetInstance().WriteExceptionLog(err); throw new NdnException("CM0410W"); } return(s_conn); }
/// <summary> /// 合并PDF文件 /// </summary> /// <param name="destinationFile"></param> /// <param name="sourceFiles"></param> /// <returns></returns> public static Boolean MergeFiles(string destinationFile, string[] sourceFiles) { try { int f = 0; // we create a reader for a certain document PdfReader reader = new PdfReader(sourceFiles[f]); // we retrieve the total number of pages int n = reader.NumberOfPages; //Console.WriteLine("There are " + n + " pages in the original file."); // step 1: creation of a document-object Document document = new Document(reader.GetPageSizeWithRotation(1)); // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationFile, FileMode.Create)); // step 3: we open the document document.Open(); PdfContentByte cb = writer.DirectContent; PdfImportedPage page; int rotation; // step 4: we add content while (f < sourceFiles.Length) { int i = 0; while (i < n) { i++; document.SetPageSize(reader.GetPageSizeWithRotation(i)); document.NewPage(); page = writer.GetImportedPage(reader, i); rotation = reader.GetPageRotation(i); if (rotation == 90 || rotation == 270) { cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height); } else { cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0); } //Console.WriteLine("Processed page " + i); } f++; if (f < sourceFiles.Length) { reader = new PdfReader(sourceFiles[f]); // we retrieve the total number of pages n = reader.NumberOfPages; //Console.WriteLine("There are " + n + " pages in the original file."); } } // step 5: we close the document document.Close(); } catch (Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); return(false); } return(true); }
/// <summary> /// get received mail from out llok /// </summary> public static ArrayList getMailFromOutlook() { ArrayList ret = new ArrayList(); String filters = "[email protected];[email protected]"; try { // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.NameSpace outlookNS = oApp.GetNamespace("MAPI"); Outlook.MAPIFolder inboxFolder = outlookNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); foreach (object obj in inboxFolder.Items) { Outlook.MailItem item = obj as Outlook.MailItem; if (item != null && item.Body != null && item.Body != "") { String mailaddress = NCPop3Mail.GetmailAddress(item.Body); mailaddress = NCPop3Mail.filter(mailaddress, filters); if (mailaddress != null && mailaddress != "") { String[] mails = mailaddress.Split(';'); foreach (String mail in mails) { if (mail.Trim() != "") { ret.Add(mail); } } } } if (item != null && item.HTMLBody != null && item.HTMLBody != "") { String mailaddress = NCPop3Mail.GetmailAddress(item.HTMLBody); mailaddress = NCPop3Mail.filter(mailaddress, filters); if (mailaddress != null && mailaddress != "") { String[] mails = mailaddress.Split(';'); foreach (String mail in mails) { if (mail.Trim() != "") { ret.Add(mail); } } } } } oApp = null; }//end of try block catch (System.Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); }//end of catch return(ret); }
/// <summary> /// 下载文件 /// </summary> /// <param name="url"></param> /// <param name="downFile"></param> /// <param name="username"></param> /// <param name="password"></param> public Boolean download(string url, string downFile, string username, string password) { Boolean ret = true; try { //ダウンロードするファイルのURI Uri u = new Uri(url); //FtpWebRequestの作成 System.Net.FtpWebRequest ftpReq = (System.Net.FtpWebRequest) System.Net.WebRequest.Create(u); //ログインユーザー名とパスワードを設定 ftpReq.Credentials = new System.Net.NetworkCredential(username, password); //MethodにWebRequestMethods.Ftp.DownloadFile("RETR")を設定 ftpReq.Method = System.Net.WebRequestMethods.Ftp.DownloadFile; //要求の完了後に接続を閉じる ftpReq.KeepAlive = false; //ASCIIモードで転送する ftpReq.UseBinary = true; //PASSIVEモードを無効にする ftpReq.UsePassive = false; //FtpWebResponseを取得 System.Net.FtpWebResponse ftpRes = (System.Net.FtpWebResponse)ftpReq.GetResponse(); //ファイルをダウンロードするためのStreamを取得 System.IO.Stream resStrm = ftpRes.GetResponseStream(); //ダウンロードしたファイルを書き込むためのFileStreamを作成 System.IO.FileStream fs = new System.IO.FileStream( downFile, System.IO.FileMode.Create, System.IO.FileAccess.Write); //ダウンロードしたデータを書き込む byte[] buffer = new byte[1024]; while (true) { int readSize = resStrm.Read(buffer, 0, buffer.Length); if (readSize == 0) { break; } fs.Write(buffer, 0, readSize); } fs.Close(); resStrm.Close(); //閉じる ftpRes.Close(); } catch (Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); ret = false; } return(ret); }
//************************************************************************ /// <summary> /// プロシージャを実行して、オブジェクトを返す /// </summary> /// <param name="strSPName">プロシージャの名称</param> /// <param name="list">DBアクセスパラメータリスト</param> /// <param name="objReturn">戻るのオブジェクト</param> /// <returns>正常の場合はtrueを返す、それ以外の場合はfalse。</returns> //************************************************************************ public bool ExecSp(string strSPName, ArrayList list, ref object objReturn, string ConnStr) { bool bReturn = false; SqlConnection conn = (SqlConnection)SQLDataConnection.GetConnection(ConnStr); SqlCommand dbCommand = new SqlCommand(strSPName, conn); SQLTransaction trans = new SQLTransaction(conn); if (trans.IsBegin()) { dbCommand.Transaction = (SqlTransaction)trans.GetCurrentTransaction(); } dbCommand.CommandType = CommandType.StoredProcedure; dbCommand.CommandTimeout = 36000; SqlParameter SqlParam = null; try { if (list != null) { IEnumerator Enumerator; Enumerator = list.GetEnumerator(); NcPara para; while (Enumerator.MoveNext()) { para = (NcPara)Enumerator.Current; if (Equals(para.OutPut, true)) { SqlParam = dbCommand.Parameters.Add(GetSqlParameter(para.Key, (SqlDbType)para.Type, para.Size, para.Value, para.OutPut)); } else { dbCommand.Parameters.Add(GetSqlParameter(para.Key, (SqlDbType)para.Type, para.Size, para.Value, para.OutPut)); } } } dbCommand.ExecuteNonQuery(); if (SqlParam != null && objReturn != null) { objReturn = SqlParam.Value; } bReturn = true; } catch (Exception err) { // NdnPublicFunction.WriteLog(m_strLogFileName, err.Message); NCLogger.GetInstance().WriteExceptionLog(err); } finally { dbCommand.Parameters.Clear(); } return(bReturn); }
//************************************************************************ /// <summary> /// 指定のXMLファイルのデータを読み取り /// </summary> /// <param name="strSection">セクション</param> /// <param name="strChildSection">サブセクション</param> /// <param name="strAttr1">属性1</param> /// <param name="strValue1">バリュー1</param> /// <param name="strAttr2">属性2</param> /// <param name="strValue2">バリュー2</param> /// <returns>boolを返す</returns> //************************************************************************ public bool ReadXmlData(string strSection, string strChildSection, string strAttr1, string strValue1, string strAttr2, ref string strValue2) { bool bReturn = false; FileInfo fileInfo = null; XmlNode xmlNode; XmlAttributeCollection xmlAttributeCollection; try { fileInfo = new FileInfo(m_strXmlFile); if (fileInfo.Exists) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(m_strXmlFile); xmlNode = xmlDocument.DocumentElement; foreach (XmlNode iNode in xmlNode.ChildNodes) { if (iNode.LocalName.Equals(strSection)) { if (iNode.FirstChild.LocalName.Equals(strChildSection)) { xmlAttributeCollection = iNode.FirstChild.Attributes; XmlAttribute xmlAttribute = xmlAttributeCollection[strAttr1]; if (xmlAttribute.Value.Equals(strValue1)) { xmlAttribute = xmlAttributeCollection[strAttr2]; strValue2 = xmlAttribute.Value; break; } } } } if (strValue2 == null) { bReturn = false; } else { bReturn = true; } } } catch (Exception err) { NCLogger.GetInstance().WriteExceptionLog(err); // NdnPublicFunction.WriteLog("", err.Message); } return(bReturn); }
} //end of Email Method //method to send email to HOTMAIL public static Boolean sendEMailThroughHotMail(String sender, String password, String subject, String body, String htmlbody, List <String> attachmentfiles, List <String> recipients) { Boolean ret = true; try { //Mail Message MailMessage mM = new MailMessage(); //Mail Address mM.From = new MailAddress(sender); //receiver email id foreach (String recipient in recipients) { mM.To.Add(recipient); } //subject of the email mM.Subject = subject; //deciding for the attachment foreach (String attachmentfile in attachmentfiles) { mM.Attachments.Add(new Attachment(attachmentfile)); } if (!String.IsNullOrEmpty(htmlbody)) { //add the body of the email mM.Body = htmlbody; mM.IsBodyHtml = true; } else { //add the body of the email mM.Body = body; mM.IsBodyHtml = false; } //SMTP client SmtpClient sC = new SmtpClient("smtp.live.com"); //port number for Hot mail sC.Port = 587; //credentials to login in to hotmail account sC.Credentials = new System.Net.NetworkCredential(sender, password); //enabled SSL sC.EnableSsl = true; //Send an email sC.Send(mM); }//end of try block catch (Exception ex) { ret = false; //MessageBox.Show("Hotmail " + ex.Message); NCLogger.GetInstance().WriteExceptionLog(ex); } //end of catch return(ret); } //end of Email Method
} //end of Yahoo Email MethodHotMail //Method to send email from YAHOO!! public static Boolean sendEMailThroughAOL(String sender, String password, String subject, String body, String htmlbody, List <String> attachmentfiles, List <String> recipients) { Boolean ret = true; try { //mail message MailMessage mM = new MailMessage(); //Mail Address mM.From = new MailAddress(sender); foreach (String recipient in recipients) { mM.To.Add(recipient); } //subject of the email mM.Subject = subject; //deciding for the attachment foreach (String attachmentfile in attachmentfiles) { mM.Attachments.Add(new Attachment(attachmentfile)); } if (!String.IsNullOrEmpty(htmlbody)) { //add the body of the email mM.Body = htmlbody; mM.IsBodyHtml = true; } else { //add the body of the email mM.Body = body; mM.IsBodyHtml = false; } //SMTP SmtpClient SmtpServer = new SmtpClient(); //your credential will go here SmtpServer.Credentials = new System.Net.NetworkCredential(sender, password); //port number to login yahoo server SmtpServer.Port = 587; //yahoo host name SmtpServer.Host = "smtp.aol.com"; //Send the email SmtpServer.Send(mM); }//end of try block catch (Exception ex) { ret = false; NCLogger.GetInstance().WriteExceptionLog(ex); //MessageBox.Show("AOL " + ex.Message); } //end of catch return(ret); } //end of AOLEmail Method
//************************************************************************ /// <summary> /// プロシージャを実行して、データセットを返す /// </summary> /// <param name="strSPName">プロシージャの名称</param> /// <param name="list">DBアクセスパラメータリスト</param> /// <param name="dataSet">戻るのデータセット</param> /// <param name="strTable">テーブルの名前</param> /// <returns>正常の場合はtrueを返す、それ以外の場合はfalse。</returns> //************************************************************************ public bool ExecSp(string strSPName, ArrayList list, ref DataSet dataSet, string strTable, string ConnStr) { bool bReturn = false; if (dataSet == null) { dataSet = new DataSet(); } SqlConnection conn = (SqlConnection)SQLDataConnection.GetConnection(ConnStr); SqlCommand dbCommand = new SqlCommand(strSPName, conn); SQLTransaction trans = new SQLTransaction(conn); if (trans.IsBegin()) { dbCommand.Transaction = (SqlTransaction)trans.GetCurrentTransaction(); } dbCommand.CommandType = CommandType.StoredProcedure; SqlDataAdapter dbAdapter = null; try { if (list != null) { IEnumerator Enumerator; Enumerator = list.GetEnumerator(); NcPara para; while (Enumerator.MoveNext()) { para = (NcPara)Enumerator.Current; dbCommand.Parameters.Add(GetSqlParameter(para.Key, (SqlDbType)para.Type, para.Size, para.Value, para.OutPut)); } } //アダプターの構成 dbAdapter = new SqlDataAdapter(dbCommand); dbAdapter.Fill(dataSet, strTable); bReturn = true; } catch (Exception err) { // NdnPublicFunction.WriteLog(m_strLogFileName, err.Message); NCLogger.GetInstance().WriteExceptionLog(err); } finally { dbCommand.Parameters.Clear(); dbAdapter.Dispose(); } return(bReturn); }
/// <summary> /// 取得本系统产品编号 /// </summary> /// <returns></returns> public static string getProductID(string product) { try { string deviceId = Toolkit.GetDeviceID(); string productId = Encrypto(deviceId + product); return(productId); } catch (Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); } return(null); }
/// <summary> /// 发布信息 /// </summary> /// <param name="appKey"></param> /// <param name="appSecret"></param> public static Boolean PublishTencent(string appKey, string appSecret, string content, string pic) { OAuth oauth = new OAuth(appKey, appSecret); //获取请求Token if (oauth.GetRequestToken(null)) { NCLogger.GetInstance().WriteDebugLog("获取Request Token成功。值如下:"); NCLogger.GetInstance().WriteDebugLog(String.Format("TokenKey={0}", oauth.Token)); NCLogger.GetInstance().WriteDebugLog(String.Format("TokenSecret={0}", oauth.TokenSecret)); NCLogger.GetInstance().WriteDebugLog("正在请求授权, 请在授权后,将页面提示的授权码码输入下面并继续……"); Process.Start("https://open.t.qq.com/cgi-bin/authorize?oauth_token=" + oauth.Token); Console.Write("授权码:"); string verifier = Console.ReadLine(); string name; if (oauth.GetAccessToken(verifier, out name)) { NCLogger.GetInstance().WriteDebugLog("获取Access Token成功。值如下:"); NCLogger.GetInstance().WriteDebugLog(String.Format("TokenKey={0}", oauth.Token)); NCLogger.GetInstance().WriteDebugLog(String.Format("TokenSecret={0}", oauth.TokenSecret)); NCLogger.GetInstance().WriteDebugLog(String.Format("微博帐户名={0}", name)); } else { NCLogger.GetInstance().WriteDebugLog(String.Format("获取Access Token时出错,错误信息: {0}", oauth.LastError)); } } else { NCLogger.GetInstance().WriteDebugLog(String.Format("获取Request Token时出错,错误信息: {0}", oauth.LastError)); } if (oauth.LastError != null) { return(false); } Twitter twitter = new Twitter(oauth); var data = twitter.Add(content, pic, "127.0.0.1"); if (data.Ret == 0) { //删除刚发的微博 //data = twitter.Delete(((TweetOperateResult)data).TweetId); return(true); } //Console.WriteLine(data.Ret); //Console.Read(); return(false); }
/// <summary> /// 取得PDF页数 /// </summary> /// <param name="strFileName"></param> /// <returns></returns> public static int CountPageNo(string strFileName) { try { // we create a reader for a certain document PdfReader reader = new PdfReader(strFileName); // we retrieve the total number of pages return(reader.NumberOfPages); } catch (Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); } return(0); }
/// <summary> /// 许可检查 /// </summary> public static Boolean checkLic(string Lic, string system_id) { try { string deviceId = Toolkit.GetDeviceID(); string lic = GetMd5HashValue(Encoding.Default.GetBytes("highway" + deviceId + "kl" + system_id)); if (lic == Lic) { return(true); } } catch (Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); } return(false); }
/// <summary> /// SetData_ データ作成または更新 /// </summary> /// <param name="LoginID">ユーザID</param> /// <param name="dataid">データID</param> /// <param name="fieldlist">フィールドリスト</param> /// <param name="tablename">テーブル名</param> /// <param name="wheresql">WHERE文</param> /// <param name="valuesql">VALUE文</param> /// <param name="newdataid">新規するときのID</param> /// <returns>成功場合TRUE</returns> public bool SetData_(int LoginID, int dataid, string fieldlist, string tablename, string wheresql, string valuesql, out int newdataid, string Connstr) { NCLogger.GetInstance().WriteDebugLog("GetDataList_"); NCLogger.GetInstance().WriteDebugLog("tablename=" + tablename); NCLogger.GetInstance().WriteDebugLog("wheresql=" + wheresql); NCLogger.GetInstance().WriteDebugLog("valuesql=" + valuesql); bool bReturn = false; newdataid = dataid; try { ArrayList list = new ArrayList(); NcPara para = new NcPara("@iOPID", SqlDbType.Int, 16, LoginID); list.Add(para); para = new NcPara("@iCIP", SqlDbType.Int, 16, 0); list.Add(para); para = new NcPara("@iDATAID", SqlDbType.Int, 16, dataid); list.Add(para); para = new NcPara("@iFLDL", SqlDbType.Char, 1000, fieldlist); list.Add(para); para = new NcPara("@iTBLNM", SqlDbType.Char, 30, tablename); list.Add(para); para = new NcPara("@iWSQL", SqlDbType.Char, 7000, wheresql); list.Add(para); para = new NcPara("@iVSQL", SqlDbType.Char, 7000, valuesql); list.Add(para); para = new NcPara("@oRCD", SqlDbType.Int, 16, newdataid, true); list.Add(para); object refobj = new object(); // modified by zhengjun 20071114 for error no.5 start //bReturn = m_dataBase.ExecSp("dbo.SetData", list, ref refobj, Connstr); bReturn = m_dataBase.ExecSp("SetData", list, ref refobj, Connstr); // modified by zhengjun 20071114 for error no.5 end if (bReturn) { newdataid = int.Parse(refobj.ToString()); } } catch (Exception exp) { NCLogger.GetInstance().WriteExceptionLog(exp); } return(bReturn); }
//************************************************************************ /// <summary> /// XMLロード /// </summary> //************************************************************************ public XmlDocument LoadXml() { XmlDocument xmlDocument = null; try { xmlDocument = new XmlDocument(); xmlDocument.Load(m_strXmlFile); } catch (Exception err) { NCLogger.GetInstance().WriteExceptionLog(err); // NdnPublicFunction.WriteLog("", err.Message); xmlDocument = null; } return(xmlDocument); }
/// <summary> /// 从产品ID取得硬件ID /// </summary> /// <returns></returns> public static string getHardIDFromProductId(string productID, string product) { try { String hardId = Decrypto(productID); if (hardId.LastIndexOf(product) > -1) { return(hardId.Substring(0, hardId.LastIndexOf(product))); } else { return(null); } } catch (Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); } return(null); }
/// <summary> /// GetDataList_ データまたはデータ一覧取得方法 /// </summary> /// <param name="LoginID">ユーザID</param> /// <param name="dataid">データID</param> /// <param name="fieldlist">フィールドリスト</param> /// <param name="tablename">テーブル名前</param> /// <param name="wheresql">WHERE文</param> /// <param name="ordersql">ORDER文</param> /// <param name="dataSet">データセット</param> /// <returns>成功の場合TURE</returns> public bool GetDataList_(int LoginID, int dataid, string fieldlist, string tablename, string wheresql, string ordersql, ref DataSet dataSet, string Connstr) { NCLogger.GetInstance().WriteDebugLog("GetDataList_"); NCLogger.GetInstance().WriteDebugLog("tablename=" + tablename); NCLogger.GetInstance().WriteDebugLog("fieldlist=" + fieldlist); NCLogger.GetInstance().WriteDebugLog("wheresql=" + wheresql); NCLogger.GetInstance().WriteDebugLog("ordersql=" + ordersql); bool bReturn = false; try { ArrayList list = new ArrayList(); NcPara para = new NcPara("@iOPID", SqlDbType.Int, 16, LoginID); list.Add(para); para = new NcPara("@iCIP", SqlDbType.Int, 16, 0); list.Add(para); para = new NcPara("@iDATAID", SqlDbType.Int, 16, dataid); list.Add(para); para = new NcPara("@iFLDL", SqlDbType.Char, 1000, fieldlist); list.Add(para); para = new NcPara("@iTBLNM", SqlDbType.Char, 30, tablename); list.Add(para); para = new NcPara("@iWSQL", SqlDbType.Char, 1000, wheresql); list.Add(para); para = new NcPara("@iOSQL", SqlDbType.Char, 100, ordersql); list.Add(para); para = new NcPara("@oRCD", SqlDbType.Int, 16, null, true); list.Add(para); // modified by zhengjun 20071114 for error no.5 start //bReturn = m_dataBase.ExecSp("dbo.GetDataList", list, ref dataSet, tablename, Connstr); bReturn = m_dataBase.ExecSp("GetDataList", list, ref dataSet, tablename, Connstr); // modified by zhengjun 20071114 for error no.5 end } catch (Exception exp) { NCLogger.GetInstance().WriteExceptionLog(exp); } return(bReturn); }
//************************************************************************ /// <summary> /// データベースのコネクションを閉じる /// </summary> //************************************************************************ public static void CloseConnection() { try { if (s_conn != null) { //DBクローズ s_conn.Close(); NCLogger.GetInstance().WriteDebugLog("Sql Connection is closed."); } } catch { } finally { //初期値を設定 s_conn = null; } }
/// <summary> /// 分割PDF文件 /// </summary> /// <param name="sourcePdfPath"></param> /// <param name="outputPdfPath"></param> /// <param name="startPage"></param> /// <param name="endPage"></param> public static Boolean ExtractPages(string sourcePdfPath, string outputPdfPath, int startPage, int endPage) { PdfReader reader = null; Document sourceDocument = null; PdfCopy pdfCopyProvider = null; PdfImportedPage importedPage = null; try { // Intialize a new PdfReader instance with the contents of the source Pdf file: reader = new PdfReader(sourcePdfPath); // For simplicity, I am assuming all the pages share the same size // and rotation as the first page: sourceDocument = new Document(reader.GetPageSizeWithRotation(startPage)); // Initialize an instance of the PdfCopyClass with the source // document and an output file stream: pdfCopyProvider = new PdfCopy(sourceDocument, new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create)); sourceDocument.Open(); // Walk the specified range and add the page copies to the output file: for (int i = startPage; i <= endPage; i++) { importedPage = pdfCopyProvider.GetImportedPage(reader, i); pdfCopyProvider.AddPage(importedPage); } sourceDocument.Close(); reader.Close(); } catch (Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); return(false); } return(true); }
} //end of Email Method /// <summary> /// 从SQLServer取得用户 /// </summary> /// <param name="server">服务器</param> /// <param name="uid">用户</param> /// <param name="pwd">密码</param> /// <param name="database">数据库</param> /// <param name="tablename">表</param> /// <param name="fields">字段名</param> /// <param name="mails">已有邮件</param> /// <param name="ds">返回数据</param> /// <returns></returns> public static Boolean getUserFromSqlserver(string server, string uid, string pwd, string database, string tablename, string[] fields, ref DataSet ds) { string connStr = String.Format("Data Source={0};Initial Catalog={3};User ID={1};Password={2}", server, uid, pwd, database); SqlConnection conn = new SqlConnection(connStr); try { conn.Open(); string sql = @"IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_mail]') AND type in (N'U')) BEGIN CREATE TABLE t_mail (mail varchar(100)) END"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); sql = "select " + string.Join(",", fields) + " from " + tablename + " where " + fields[0] + " not in (select mail from t_mail)"; DataTable data = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(sql, conn); SqlCommandBuilder cb = new SqlCommandBuilder(da); da.Fill(data); foreach (DataRow row in data.Rows) { string mail = row[fields[0]].ToString(); sql = "INSERT INTO t_mail VALUES ('" + mail + "')"; cmd.CommandText = sql; cmd.ExecuteNonQuery(); } ds.Tables.Clear();; ds.Tables.Add(data); conn.Close(); } catch (Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); return(false); } return(true); }
/// <summary> /// MD5 /// </summary> /// <param name="dataBytes"></param> /// <returns></returns> public static string GetMd5HashValue(byte[] dataBytes) { try { MD5CryptoServiceProvider servProvider = new MD5CryptoServiceProvider(); byte[] md5Bytes = servProvider.ComputeHash(dataBytes); StringBuilder sb = new StringBuilder(32); foreach (byte md5Data in md5Bytes) { sb.Append(md5Data.ToString("X2")); } return(sb.ToString()); } catch (Exception e) { //string logMsg = "MD5计算失败!"; NCLogger.GetInstance().WriteExceptionLog(e); } return(null); }
//************************************************************************ /// <summary> /// 指定したファイルが存在するかどうかを確認します。 /// </summary> /// <param name="fileName">確認するファイル。</param> /// <returns>path に既存のファイル名が格納されている場合は true 。それ以外の場合は false 。</returns> //************************************************************************ public static bool IsExistFile(string fileName) { bool isExsit = false; try { string strIniPath = ""; GetIniPath(ref strIniPath); string fullPath = strIniPath + "\\" + fileName; NCLogger.GetInstance().WriteDebugLog("EKK.ini path:" + fullPath); isExsit = File.Exists(fullPath); if (!isExsit) { fullPath = Directory.GetCurrentDirectory() + "\\" + fileName; isExsit = File.Exists(fullPath); } } catch (Exception) { isExsit = false; } return(isExsit); }
//************************************************************************ /// <summary> /// データベースでトランザクションを開始する /// </summary> /// <returns>正常の場合はtrueを返す、それ以外の場合はfalse。</returns> //************************************************************************ public bool Begin() { bool bReturn = false; try { if (s_conn != null) { if (s_transaction == null) { s_transaction = s_conn.BeginTransaction(); NCLogger.GetInstance().WriteDebugLog("Transaction is started."); } bReturn = true; } } catch (Exception exp) { NCLogger.GetInstance().WriteExceptionLog(exp); } return(bReturn); }
/// <summary> /// 从MySQL取得用户 /// </summary> /// <param name="server">服务器</param> /// <param name="uid">用户</param> /// <param name="pwd">密码</param> /// <param name="database">数据库</param> /// <param name="tablename">表</param> /// <param name="fields">字段名</param> /// <param name="mails">已有邮件</param> /// <param name="ds">返回数据</param> /// <returns></returns> public static Boolean getUserFromMySql(string server, string uid, string pwd, string database, string tablename, string[] fields, ref DataSet ds) { string connStr = String.Format("server={0};uid={1};pwd={2};database={3}", server, uid, pwd, database); MySqlConnection conn = new MySqlConnection(connStr); try { conn.Open(); string sql = "CREATE TABLE t_mail (mail varchar(100)) IF not EXISTS t_mail"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); sql = "select " + string.Join(",", fields) + " from " + tablename + " where " + fields[0] + " not in (select mail from t_mail)"; DataTable data = new DataTable(); MySqlDataAdapter da = new MySqlDataAdapter(sql, conn); MySqlCommandBuilder cb = new MySqlCommandBuilder(da); da.Fill(data); foreach (DataRow row in data.Rows) { string mail = row[fields[0]].ToString(); sql = "INSERT INTO t_mail VALUES ('" + mail + "')"; cmd.CommandText = sql; cmd.ExecuteNonQuery(); } ds.Tables.Clear();; ds.Tables.Add(data); conn.Close(); } catch (Exception ex) { NCLogger.GetInstance().WriteExceptionLog(ex); return(false); } return(true); }
//************************************************************************ /// <summary> /// 新しいXMLファイルを作成 /// ノードはNULL場合、新しいXMLファイルに追加する /// ノードはNOTNULL場合、新しいXMLファイルを作成する /// </summary> /// <param name="strRoot">ルート</param> /// <param name="strSection">セクション</param> /// <param name="strName">ネーム</param> /// <param name="strValue">バリュー</param> /// <returns>boolを返す</returns> //************************************************************************ public bool CreateXmlFile(string strRoot, string strSection, string strName, string strValue) { bool bReturn = false; XmlTextWriter writer = null; try { writer = new XmlTextWriter(m_strXmlFile, System.Text.Encoding.Unicode); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement(strRoot); if (strSection != null) { writer.WriteStartElement(strSection); writer.WriteAttributeString("name", strName); writer.WriteAttributeString("value", strValue); } writer.WriteEndElement(); } catch (Exception err) { // NdnPublicFunction.WriteLog("", err.Message); NCLogger.GetInstance().WriteExceptionLog(err); } finally { if (writer != null) { writer.Close(); } } return(bReturn); }
//************************************************************************ /// <summary> /// トランザクションを保留中の状態からコミットする /// </summary> /// <returns>正常の場合はtrueを返す、それ以外の場合はfalse。</returns> //************************************************************************ public bool Commit() { bool bReturn = false; try { if (s_transaction != null) { s_transaction.Commit(); NCLogger.GetInstance().WriteDebugLog("Transaction is commited."); bReturn = true; } } catch (Exception exp) { NCLogger.GetInstance().WriteExceptionLog(exp); } finally { s_transaction = null; } return(bReturn); }
//method to send email to outlook public static Boolean sendEMailThroughOUTLOOK(String subject, String body, String htmlbody, List <String> attachmentfiles, List <String> recipients) { Boolean ret = true; try { // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); if (String.IsNullOrEmpty(htmlbody)) { // Set HTMLBody. //add the body of the email oMsg.Body = body; //Add an attachment. int iPosition = (int)oMsg.Body.Length + 1; int iAttachType = (int)Outlook.OlAttachmentType.olByValue; //now attached the file foreach (String attachmentfile in attachmentfiles) { String sDisplayName = Path.GetFileName(attachmentfile); oMsg.Attachments.Add(attachmentfile, iAttachType, iPosition, sDisplayName); } } else { // Set HTMLBody. //add the body of the email oMsg.HTMLBody = htmlbody; //Add an attachment. int iPosition = (int)oMsg.HTMLBody.Length + 1; int iAttachType = (int)Outlook.OlAttachmentType.olByValue; //now attached the file foreach (String attachmentfile in attachmentfiles) { String sDisplayName = Path.GetFileName(attachmentfile); oMsg.Attachments.Add(attachmentfile, iAttachType, iPosition, sDisplayName); } } //Subject line oMsg.Subject = subject; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; // Change the recipient in the next line if necessary. foreach (String recipient in recipients) { Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient); oRecip.Resolve(); //oRecip = null; } // Send. oMsg.Send(); // Clean up. oRecips = null; oMsg = null; oApp = null; }//end of try block catch (System.Exception ex) { ret = false; NCLogger.GetInstance().WriteExceptionLog(ex); } //end of catch return(ret); } //end of Email Method
//************************************************************************ /// <summary> /// メッセージXMLファイルからメッセージ情報を取得し、配列にセットする。 /// </summary> //************************************************************************ private static void ReadXml(String language) { try { String m_documentPath = NCConst.CONFIG_FILE_DIR + NCConst.MESSAGE_FILE_NAME; if (language != null && language != "" && language != "en") { m_documentPath += "." + language + NCConst.MESSAGE_FILE_EXT; } else { m_documentPath += NCConst.MESSAGE_FILE_EXT; } //XMLリーダを初期化 XmlTextReader reader = new XmlTextReader(m_documentPath); try { //ループでXMLファイル情報を取得する while (reader.Read()) { //ノードタイプを判断する switch (reader.NodeType) { //XMLタグの場合 case XmlNodeType.Element: if (reader.LocalName == "Message") { if (reader.MoveToFirstAttribute()) { do { //メッセージIDを取得 if (reader.Name == "id") { m_msgId[m_count] = reader.Value; } //エリアスを取得 if (reader.Name == "alias") { m_msgAlias[m_count] = reader.Value; } //メッセージを取得 if (reader.Name == "msg") { m_msg[m_count] = reader.Value; } //出力形式を取得 if (reader.Name == "output") { m_msgOutput[m_count] = reader.Value; } //通知対象を取得 if (reader.Name == "notice") { m_msgNotice[m_count] = reader.Value; } } while(reader.MoveToNextAttribute()); m_count = m_count + 1; } } break; //テキストの場合 case XmlNodeType.Text: break; //終了タグの場合 case XmlNodeType.EndElement: break; } } } catch (Exception err) { //取得失敗時、配列を初期化する m_msgId = null; m_msgAlias = null; m_msg = null; m_msgOutput = null; m_msgNotice = null; m_msgId = new string[600]; m_msgAlias = new string[600]; m_msg = new string[600]; m_msgOutput = new string[600]; m_msgNotice = new string[600]; m_count = 0; NCLogger.GetInstance().WriteExceptionLog(err); } finally { reader.Close(); reader = null; } } finally { } }