wordpress default themes Twenty Ten pre overflow

WordPress默認的主題Twenty Ten,過長的代碼行超出到邊欄,很難看,修改如下:

文件:Twenty Ten: 样式表 (style.css)

10
11
12
13
14
15
16
17
pre {
 background: #f7f7f7;
 color: #222;
 line-height: 18px;
 margin-bottom: 18px;
 padding: 1.5em;
 overflow: hidden;
}

加上這行就OK了: overflow: hidden;

 

发表在 Program | 标签为 , | 留下评论

C# winform datatable export to excel xml format

C# winform 從datatable導出到excel的XML格式

原來是參考這裡:

http://stackoverflow.com/questions/2401067/export-gridview-into-excel-in-windowsformsapplication

應用之後,發現一些問題,有一些BUG,以致導出不成功,或是一些日期或數字格式不對.

改後的代碼如下:

1.類代碼:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ExcelXml
{
 public class ExcelWriter : IDisposable
 {
 private XmlWriter _writer;

 public enum CellStyle { General, Number, Currency, DateTime, ShortDate };

 public void WriteStartDocument()
 {
 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 _writer.WriteProcessingInstruction("mso-application", "progid=\"Excel.Sheet\"");
 _writer.WriteStartElement("ss", "Workbook", "urn:schemas-microsoft-com:office:spreadsheet");
 WriteExcelStyles();
 }

 public void WriteEndDocument()
 {
 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 _writer.WriteEndElement();
 }

 private void WriteExcelStyleElement(CellStyle style)
 {
 _writer.WriteStartElement("Style", "urn:schemas-microsoft-com:office:spreadsheet");
 _writer.WriteAttributeString("ID", "urn:schemas-microsoft-com:office:spreadsheet", style.ToString());
 _writer.WriteEndElement();
 }

 private void WriteExcelStyleElement(CellStyle style, string NumberFormat)
 {
 _writer.WriteStartElement("Style", "urn:schemas-microsoft-com:office:spreadsheet");

 _writer.WriteAttributeString("ID", "urn:schemas-microsoft-com:office:spreadsheet", style.ToString());
 _writer.WriteStartElement("NumberFormat", "urn:schemas-microsoft-com:office:spreadsheet");
 _writer.WriteAttributeString("Format", "urn:schemas-microsoft-com:office:spreadsheet", NumberFormat);
 _writer.WriteEndElement();

 _writer.WriteEndElement();

 }

 private void WriteExcelStyles()
 {
 _writer.WriteStartElement("Styles", "urn:schemas-microsoft-com:office:spreadsheet");

 WriteExcelStyleElement(CellStyle.General);
 WriteExcelStyleElement(CellStyle.Number, "General Number");
 WriteExcelStyleElement(CellStyle.DateTime, "General Date");
 WriteExcelStyleElement(CellStyle.Currency, "Currency");
 WriteExcelStyleElement(CellStyle.ShortDate, "Short Date");

 _writer.WriteEndElement();
 }

 public void WriteStartWorksheet(string name)
 {
 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 _writer.WriteStartElement("Worksheet", "urn:schemas-microsoft-com:office:spreadsheet");
 _writer.WriteAttributeString("Name", "urn:schemas-microsoft-com:office:spreadsheet", name);
 _writer.WriteStartElement("Table", "urn:schemas-microsoft-com:office:spreadsheet");
 }

 public void WriteEndWorksheet()
 {
 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 _writer.WriteEndElement();
 _writer.WriteEndElement();
 }

 public ExcelWriter(string outputFileName)
 {
 XmlWriterSettings settings = new XmlWriterSettings();
 settings.Indent = true;
 _writer = XmlWriter.Create(outputFileName, settings);
 }

 public void Close()
 {
 if (_writer == null) throw new NotSupportedException("Already closed.");

 _writer.Close();
 _writer = null;
 }

 public void WriteExcelColumnDefinition(int columnWidth)
 {
 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 _writer.WriteStartElement("Column", "urn:schemas-microsoft-com:office:spreadsheet");
 _writer.WriteStartAttribute("Width", "urn:schemas-microsoft-com:office:spreadsheet");
 _writer.WriteValue(columnWidth);
 _writer.WriteEndAttribute();
 _writer.WriteEndElement();
 }

 public void WriteExcelUnstyledCell(string value)
 {
 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 _writer.WriteStartElement("Cell", "urn:schemas-microsoft-com:office:spreadsheet");
 _writer.WriteStartElement("Data", "urn:schemas-microsoft-com:office:spreadsheet");
 _writer.WriteAttributeString("Type", "urn:schemas-microsoft-com:office:spreadsheet", "String");
 _writer.WriteValue(value);
 _writer.WriteEndElement();
 _writer.WriteEndElement();
 }

 public void WriteStartRow()
 {
 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 _writer.WriteStartElement("Row", "urn:schemas-microsoft-com:office:spreadsheet");
 }

 public void WriteEndRow()
 {
 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 _writer.WriteEndElement();
 }

 public void WriteExcelStyledCell(object value, CellStyle style)
 {
 try
 {
 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 _writer.WriteStartElement("Cell", "urn:schemas-microsoft-com:office:spreadsheet");
 _writer.WriteAttributeString("StyleID", "urn:schemas-microsoft-com:office:spreadsheet", style.ToString());
 _writer.WriteStartElement("Data", "urn:schemas-microsoft-com:office:spreadsheet");
 switch (style)
 {
 case CellStyle.General:
 _writer.WriteAttributeString("Type", "urn:schemas-microsoft-com:office:spreadsheet", "String");
 break;
 case CellStyle.Number:
 _writer.WriteAttributeString("Type", "urn:schemas-microsoft-com:office:spreadsheet", "Number"); // 與原例子不同,自己加的,未驗證
 break; // 與原例子不同,自己加的,未驗證
 case CellStyle.Currency:
 _writer.WriteAttributeString("Type", "urn:schemas-microsoft-com:office:spreadsheet", "Number");
 break;
 case CellStyle.ShortDate:
 case CellStyle.DateTime:
 _writer.WriteAttributeString("Type", "urn:schemas-microsoft-com:office:spreadsheet", "DateTime");
 break;
 }
 _writer.WriteValue(value);
 //  tag += String.Format("{1}\"><ss:Data ss:Type=\"DateTime\">{0:yyyy\\-MM\\-dd\\THH\\:mm\\:ss\\.fff}</ss:Data>", value,

 _writer.WriteEndElement();
 _writer.WriteEndElement();
 }
 catch (Exception e)
 {
 System.Windows.Forms.MessageBox.Show(e.Message);
 }
 }

 public void WriteExcelAutoStyledCell(object value)
 {
 try
 {

 if (_writer == null) throw new NotSupportedException("Cannot write after closing.");

 //write the <ss:Cell> and <ss:Data> tags for something
 if (value is Int16 || value is Int32 || value is Int64 || value is SByte ||
 value is UInt16 || value is UInt32 || value is UInt64 || value is Byte)
 {
 WriteExcelStyledCell(value, CellStyle.Number);
 }
 else if (value is Single || value is Double || value is Decimal) //we'll assume it's a currency
 {
 //WriteExcelStyledCell(value, CellStyle.Currency);      //原例子
 WriteExcelStyledCell(value, CellStyle.Number); // 與原例子不同,自己改的,未驗證
 }
 else if (value is DateTime)
 {

 //check if there's no time information and use the appropriate style
 WriteExcelStyledCell(value, ((DateTime)value).TimeOfDay.CompareTo(new TimeSpan(0, 0, 0, 0, 0)) == 0 ? CellStyle.ShortDate : CellStyle.DateTime);
 }
 else
 {

 WriteExcelStyledCell(value, CellStyle.General);
 }
 }
 catch (Exception e)
 {
 System.Windows.Forms.MessageBox.Show(e.Message);
 }
 }

 #region IDisposable Members

 public void Dispose()
 {
 if (_writer == null)
 return;

 _writer.Close();
 _writer = null;
 }

 #endregion
 }

}

2.應用代碼:

/// <summary>
/// 生成EXCEL報表
/// </summary>
///
public static void ExcelExport(DataTable data, String fileName, bool openAfter)
{
 //export a DataTable to Excel
 DialogResult retry = DialogResult.Retry;
 object value = null;
 DateTime d = new DateTime();
 int i = 0;
 bool isdate = false;
 string field_name = "";

 var formats = new[] { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-M-d", "yyyy-M-d HH:mm:ss", };
 //嚴格匹配日期格式.
 //string s = "2012-4-5-6";
 //if (DateTime.TryParseExact(s, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out d))
 //        MessageBox.Show(d.ToString("yyyy-MM-dd HH:mm:ss"));
 //else MessageBox.Show("Error date!");

 //string da = "1:12";
 ////(([0-1][0-9])|([2][0-3])):([0-5][0-9])        (([0-1][0-9])|([2][0-3])):([0-5][0-9])
 //System.Text.RegularExpressions.Regex dateRegex = new System.Text.RegularExpressions.Regex(@"^(([0-1]{0,1}[0-9])|([2][0-3])):([0-5][0-9])");
 ////System.Text.RegularExpressions.Regex dateRegex = new System.Text.RegularExpressions.Regex(@"^(([0-1][0-9])|([2][0-3])):([0-5][0-9])");
 //if (dateRegex.IsMatch(da))
 //{
 //        MessageBox.Show("It's Time!");
 //}
 while (retry == DialogResult.Retry)
 {
 try
 {
 using (ExcelWriter writer = new ExcelWriter(fileName))
 {
 writer.WriteStartDocument();

 // Write the worksheet contents
 writer.WriteStartWorksheet("Sheet1");

 //Write header row
 writer.WriteStartRow();
 foreach (DataColumn col in data.Columns)
 writer.WriteExcelUnstyledCell(col.Caption);
 writer.WriteEndRow();

 //write data
 foreach (DataRow row in data.Rows)
 {
 i = 0;
 writer.WriteStartRow();
 foreach (object o in row.ItemArray)
 {
 field_name = row.Table.Columns[i].ToString();
 if (field_name.Contains("date"))
 isdate = true;
 else
 isdate = false;
 i++;

 Type b = o.GetType();
 if (b.Name == "DBNull")
 value = "";
 else if (b.Name == "String" && o.ToString().Contains("\0"))
 value = o.ToString().Replace("\0","");
 //else if (DateTime.TryParse(o.ToString(), out  d))
 else if ( isdate && DateTime.TryParseExact(o.ToString(), formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out d))
 {
 if (d.Year >= 1900)
 {

 if (o.ToString().Length > 10)
 value = d;
 else if (o.ToString().Length < 10 && o.ToString().Contains(":"))
 //value = d.TimeOfDay;  //导出到EXCEL的格式有问题
 value = o;
 else if (isdate)
 value = d.Date;
 else
 value = o;

 }
 else
 value = o;
 }
 else
 value = o;
 string c = o.ToString();
 writer.WriteExcelAutoStyledCell(value);
 }
 writer.WriteEndRow();
 }

 // Close up the document
 writer.WriteEndWorksheet();
 writer.WriteEndDocument();
 writer.Close();
 if (openAfter)
 OpenFile(fileName);
 retry = DialogResult.Cancel;
 }
 }
 catch (Exception myException)
 {
 retry = MessageBox.Show(myException.Message, "Excel Export", MessageBoxButtons.RetryCancel, MessageBoxIcon.Asterisk);
 }
 }
}

關於日期格式,按字段名中,包含”"date”字符串的,才轉換.

時間沒有處理.

 

 

发表在 Program | 标签为 , | 留下评论

MS SQL SERVER字符串生成時間比較

MS SQLSERVER字符串生成時間比較

字段time2 為字符串的時間,如 0:20.
SELECT     *
FROM    table2
where cast(’2012-04-12 ‘+ time2 as datetime) < cast(’2012-04-12 ‘+’0:30′ as datetime)

发表在 Program | 标签为 | 留下评论

D8數字話機無法撥打外線

某一內線號碼,用的是NEC 數字話機,本應是按”9″後加撥外線就可以了,現在出現問題:

1.其它字頭都沒有問題,單是按”9″出街有問題,跟蹤得知,沒有取到外線路由就斷開了.

2.重新設定等級,沒有解決.

3.把號碼刪除後重做,故障依舊.

4.把電話線撥掉再插上,依舊.

最後,在PABX上,把數字板關了再開,恢復正常.

发表在 PABX | 标签为 | 留下评论

SQL 查询表格中所有记录的最新记录

SQL 查询表格中所有记录的最新记录:

http://topic.csdn.net/u/20071027/12/ab7278f9-8dd0-4c37-9b39-25564613080f.html

1.
select a.* from table1 a
left join
(select name,max(time)as time from table1 group by name)b
on a.name=b.name and a.time=b.time

2.
select a.* from table1 a
where not exists(select 1 from table1 where a.name=name and time<a.time)

SQL 按多个字段内容查询最新记录

http://topic.csdn.net/u/20090403/02/c7540c96-6498-4f4b-9c09-6ecfde28f7bd.html

1.
declare @t table(id int,   name varchar(10),   Time1 datetime,     Time2 datetime)
insert @t select 1,’AA’,’2008-5-10′,’2009-1-1′
insert @t select 2,’AA’,’2008-11-5′,null
insert @t select 3,’BB’,’2008-5-10′,’2009-2-14′
insert @t select 4,’BB’,’2008-8-23′,’2009-1-5′
insert @t select 5,’BB’,’2008-9-14′,’2009-4-1′
insert @t select 6,’CC’,’2009-2-22′,null
insert @t select 7,’CC’,’2008-10-10′,’2009-1-10′

select * from @t t where not exists(
))

select * from @t t where not exists(select 1 from @t where name=t.name and (time1>t.time1 or time2>t.time2))

用not exists会高效点,特别是数据量大的时候.

2.

大体上看了下楼主的问题,没有细读各位回帖,我觉得,首先应该将(逻辑)思路搞清楚,那么,剩下的就仅仅是sql的堆砌了。
ok,根据楼主的意思,我个人的意见描述如下:
1.将每条记录的time1与time2字段比较,取出较大值,作为一个新的虚拟列:
select case when time1>time2 then time1 else time2 newtime from table
2.然后,对上面sql生成的“视图”再按照name分组取最大的newtime值即可
参考sql:
select name,max(newtime)
from
(
select case when time1>time2 then time1 else time2 newtime from table
)

发表在 Program | 标签为 | 留下评论