2013年3月29日

[Visual Studio 2012 Express] 開啟 *.config 檔案時,發生 "Value does not fall within the expected range" 的決解方式

是情是這樣發生的,
我有一個自己測試用的專案,放在 SkyDrive 自動同步的目錄中,
在我的兩台電腦中,他很方便,可以自動的幫我同步,
有一天,我改完程式,把 Notebook 蓋起來直接下班,
 Notebook 打開後,發現他當機重開,
之後再開起這個專案裡的 *.config 檔的時候,他就一直賞我下面這個訊息。










關鍵字搜尋了一下,
都是說要還原 Visual Studio 的設定,但,這不合理!
因為我別的專案是正常的,只有這個怪怪的。

後來找到有人有提供的解決方法:
http://forums.asp.net/post/5138757.aspx

沒錯!就是砍掉 *.suo 這個隱藏檔就好了。
這個檔案會儲存上次開啟專案時的一些狀態,
例如中斷點的設定,開了哪些程式 ... 等等。
推測,應該是因為不正常關機,造成 *.suo 損壞所導致的。


很多時候,刪掉 *.suo 、 *.user 可以決解一些問題,
所以我一向都建議不要把這後副檔名的檔案 commit 到版本控管的 Server 上。



2013年3月21日

[.Net] 決解 Visual Studio 2012 Express NuGet 無法載入的問題

不知道有沒有人遇過這樣的問題,反正我是遇到了 Orz
安裝 Visual Studio 2012 Express 一切正常,
但是,
開起已經有使用 NuGet 的專案時,出現:
未正確載入套件 'NuGet.Tools.NuGetPackage, NuGet.Tools ......'











加入一個新的專案有用到 NuGet 的時候會出現:
這個範本嘗試載入元組件 'NuGet.VisualStudio.Interop ......'








以上是發病的症狀,
我安裝的環境是 Windows Server 2012 Evaluation 英文版,
加 Visual Studio 2012 Express (Web、Desktop、Phone SDK),
不管我怎麼移除再重新加入都沒用,






後來就手動在 command line 下執行
vsixinstaller /uninstall:NuPackToolsVsix.Microsoft.67e54e40-0ae3-42c5-a949-fddf5739e7a5
執行完成後會出現以下的畫面:












咦 ~ 一次移除三個,推想這案情不單純,因為之前移除的時候都只有針對 for Web 的版本做的,我猜有可能是因為安裝時,不知道什麼原因,造成他們彼此之間不一致所導致的問題。

"NuPackToolsVsix.Microsoft.67e54e40-0ae3-42c5-a949-fddf5739e7a5"
這串 ID 可以從:

C:\Program Files (x86)\NuGet\Visual Studio 2012\NuGet.Tools.vsix

這個檔案裡面取得,先把 NuGet.Tools.vsix 的副檔名改成 .zip 再解壓縮後,
裡面的 extension.vsixmanifest 檔案中可以看到






最後,要再把 NuGet.Tools.vsix 安裝回來,
只要在 Command Line 下,上述的目錄中執行以下命令即可。
vsixinstaller NuGet.Tools.vsix

2012年12月3日

[iCalendar] 如何用 .ics 檔預約或更新 Outlook 行事曆

細節要參考 RFC2445, 2446, 2447 關於 VEVENT 的設定

RFC 2446:

iCalendar Transport-Independent Interoperability Protocol (iTIP)
specifies how calendaring systems use iCalendar objects
to interoperate with other calendar systems. It does so in a general
way so as to allow multiple methods of communication between systems.
Subsequent documents specify interoperable methods of communications
between systems that use this protocol.

iTIP 在描述的是行事曆與行事曆之間利用 iCalendar objects 的溝通方式,
舉例:
A 行事曆的 User PUBLISH 一個 VEVENT 給 B 行事曆的某個 User。
A 行事曆的 User REQUEST 一個 VEVENT 給 B 行事曆的某個 User 更新先前 PUBLISH 的 VEVENT。
B 行事曆的 User COUNTER (改變的建議)一個 VEVENT 給 A 行事曆的召集人。

而這邊的需求比較簡單,我們只需要統一的一個召集人,發出會通知(或更新)給所有參與人即可,
所以只需要用到 VEVENT REQUEST ,

一個 VEVENT REQUEST 的 .ics 格式如下:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//RDU Software//NONSGML HandCal//EN
METHOD:REQUEST
BEGIN:VEVENT
DESCRIPTION:描述寫這邊
DTSTART:20121225T080000
DTEND:20121225T170000
DTSTAMP:20121129T093257
SEQUENCE:1
SUMMARY:標題寫這邊
UID:guid
STATUS:CONFIRMED
ORGANIZER:mailto:your@mail
END:VEVENT
END:VCALENDAR


基本上如果只要發佈(PUBLISH),就不需要用 ORGANIZER(rfc2446上說需要,但測試結果可有可無),
但 PUBLISH 不能更新原有的行事曆,
如果要更新就要用 REQUEST ,用 REQUEST 就要有 ORGANIZER。
要更新一個原有的行事曆,
必須要注意以下幾點:
1. UID:唯一識別代碼,前者和後者要一致
2. DTSTAMP: 產生 ics 的時間後者要比前者大
3. SEQUENCE: 要遞增,一樣後者要比前者大( SEQUENCE 從 1 開始,往後遞增)
4. ORGANIZER: 要填入符合 email 格式的內容

以上四點在 microsoft outlook 2007 中,2 和 3 有檢查後者一定要比前者大,
第 4 項貝沒有檢查一定要一樣(因為可以變更召集人),
但是一定要有 email 格式的內容,
這裡要注意召集人如果是自己(沒有設召集人,outlook預設是自己)的話,
就沒辦法更新( 這個超重要,試了很久才試出來 XD )。



METHOD 的部份定義在: http://tools.ietf.org/html/rfc2446#page-7

The ITIP methods
Method Description
PUBLISH Used to publish a calendar entry to one or more Calendar Users. There is no interactivity between the publisher and any other calendar user. An example might include a baseball team publishing its schedule to the public.
REQUEST Used to schedule a calendar entry with other Calendar Users. Requests are interactive in that they require the receiver to respond using the Reply methods. Meeting Requests, Busy Time requests and the assignment of VTODOs to other Calendar Users are all examples. Requests are also used by the "Organizer" to update the status of a calendar entry.
REPLY A Reply is used in response to a Request to convey "Attendee" status to the "Organizer". Replies are commonly used to respond to meeting and task requests.
ADD Add one or more instances to an existing VEVENT, VTODO, or VJOURNAL.
CANCEL Cancel one or more instances of an existing VEVENT, VTODO, or VJOURNAL.
REFRESH The Refresh method is used by an "Attendee" to request the latest version of a calendar entry.
COUNTER The Counter method is used by an "Attendee" to negotiate a change in the calendar entry. Examples include the request to change a proposed Event time or change the due date for a VTODO.
DECLINECOUNTER Used by the "Organizer" to decline the proposed counter-proprosal.



另外關於 content type ,截錄一下rfc2447的說明:

2.4 Content Type
   A MIME body part containing content information that conforms to this
   document MUST have an [RFC-2045] "Content-Type" value of
   "text/calendar". The [RFC-2045] "Content-Type" header field must also
   include the type parameter "method". The value MUST be the same as
   the value of the "METHOD" calendar property within the iCalendar
   object.  This means that a MIME message containing multiple iCalendar
   objects with different method values must be further encapsulated
   with a "multipart/mixed" MIME entity. This will allow each of the
   iCalendar objects to be encapsulated within their own "text/calendar"
   MIME entity.


2012年11月8日

[IIS] URL Rewrite 設定備忘

備忘:
我有一個網站,網站內容是純 html、js 組成的,但 js 會呼叫 services 做事,
我們希望 services 可以被 hosted 在別的 server 上,但我們同時也希望,
js 裡面在寫呼叫 services 的事,不需要管 services 的 server 在哪裡。
於是我們在這個網站上,設了一個反向 Proxy 做 URLRewrite ,
把特定的路徑 request 都導向另一台 Server 。

^s/(.*) 表示 s 這個目錄所以有網址都要 rewrite 。
("^"是指一開始,因為後面馬上接 "/",所以就是 "s" 這個目錄,

圖二中 {R:1} 表示上面表示式中 "(.*)" match 到的字串,{R:0}則表示含 "s/"。
(圖一)
(圖二)

參考資料:http://www.microsoft.com/taiwan/technet/iis/expand/URLRewrite.aspx



2012年10月9日

[EasyFlow] 增加TipTop XML 傳來之欄位


原因:
   TipTop 的請購單,備註是放在單身中,USER 反映簽核時不夠明顯,也無法輸入太多字

改善:
1.在 TipTop APMT420 中的自訂欄位,新增一欄備註( pmkud01),設定此欄位要傳到 EasyFlow.

2.打開此表單的 EasyFlow XML檔 (路徑 EFNET \ WS \ EFNETService \ TTXMLDoc \ Draw \ apmt420.xml )
       在<Grid name="gr5261" width="52" height="7">的最後插入
     
<Label text="備註" posY="0" posX="69" gridWidth="8" sizePolicy="dynamic"/>
<FormField name="pmk_file.pmkud01" colName="pmkud01" sqlType="VARCHAR(255)" fieldId="999" sqlTabName="pmk_file"
      tabIndex="999">
<ButtonEdit width="10" action="controlp" image="zoom" posY="0" posX="81" gridWidth="12" scroll="1"
      sample="MMMMMM000000" comment="備註[pmkud01]"/>
</FormField>


3. 修改此EasyFlow表單的HTML(路徑 EFNET \ src \ TEI \ TEIAPMT420)
         在TABLE的最下面新增

<tr>
<td width="90" id="pmkud01_1" nowrap="true" align="right" class="normalFormCaption">備註</td><td nowrap="true" width="100">
<table style="margin:0px;padding:0px;" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><span id="pmkud01_2" class="normalSpan"></span></td>
</tr>
</table>
</td>
</tr>

成果:



[EasyFlow] DropDownList 下拉式選單的加工

加工一:在SQL Command加上其他較複雜的SQL語法

原因:
      因為在 EasyFlow 表單設計中的DropDownList選單中的 SQL Command 無法用 SQL 的
      ORDER BY  or HAVING 之類的語法, 所以必須手動加在 CS 檔中.
作法:  
      找到 ” #region 重新取得 select selectXXXXX下拉選項 ”,修改 string tSQL 後面的  SQL 語法



#region 重新取得selectcategory2下拉選項 
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]  
public string ajaxGetselectcategory2Item(string pselectcategory1Val)  
{  
 string strReturn = ""; string tSQL = @"select distinct * from LMIT where FormCode='表單名稱' 
        and ItemNo='1' and Category=N'" +  pselectcategory1Val + "' order by 00";
 strReturn = createEasyFlowDataTable(tSQL, "Details", "Details");  
 return strReturn;  
}  
#endregion 重新取得selectcategory2下拉選項 

加工二:DropDownList 第一個選項是空白

作法:   
  要刪除這個空白的話,在if (!IsPostBack)中,找到這個下拉式選單,註解掉this.selectXXXXX.Items.Insert(0, new ListItem("", ""));
  在JS檔中的FunOnChange_ selectXXXXX 註解掉CreateOption("","請選擇", selectXXXXX DDL);即可

2012年10月8日

[EasyFlow] 自製 TipTop 放行單



原因:
         在 TipTop AXM520 中,沒有信用查核放行的單子可拋轉至 EasyFlow 簽核,且因 EasyFlow 版本為 .net ,鼎新將 CS 檔包成 DLL 檔了,沒有 Code ,故無法在出貨單拋轉至 EasyFlow 簽核完成時回寫 TipTop .
             
 故現行公司的做法是:
         需要放行時由相關人員填寫紙本的信用查核放行單,依核決權限簽核後,交由會計至下面欄位勾選允許放行.

流程改善:
1. 當需要放行時,負責的人員至 EasyFlow 開立信用查詢放行單,依核決權限簽核,
         當簽核完成後,更新 TipTop DB OGA903 欄位(改為Y)





2.    防呆:
a)送出前檢查: 須為出貨單 / 確認碼不為X:作廢 / 狀況碼不為9:作廢 / 信用額度查核放行不為Y / Gridview裡面的單號須為同一客戶且幣別相同
b)簽核完成後檢查:流程中是否有會計部門的員工
        c)輸入出貨單單號自動帶出該訂單之金額
3.    <!--[endif]-->檢查後帶出相關資料:
a)客戶編號 / 客戶名稱 / 授信條件 / 付款條件 / 幣別 / 本幣金額
b)計算出原幣金額(單價*數量*匯率)
c)檢查通過才會出現送出的按鈕,檢查不通過會跳出視窗題是哪邊錯誤


#region 簽核流程結束時要處理的事情
protected override void AfterApprove()
{
if (this.BlnCaseClosed && this.AryFlowProperty.SerialSignResult == "2")
{
   //先判斷流程中是否有財會部的人
   string sql_EFdept = @"select * from resdd as D
        where resdd001='表單TABLE' and resdd002='"+this.StrSheetNo+"'
              and exists (
                select '"+"x"+"' from  resak X where X.resak001 =
                    D.resdd008 and (X.resak015 = 'FN3000')
             )";
DataSet set_EFdept = this.m_objDB.CreateRecordset(" use EFNETDB;" +
                   sql_EFdept, this.Session["strProcID"].ToString());
  DataTable temp_EFdept = set_EFdept.Tables[0];
  if (temp_EFdept.Rows.Count == 0)
  {
    //把ERROR存成TXT檔
  }
  else
  {
    StringBuilder builder = new StringBuilder();
    builder.Append(" use EFNETDB;");
    builder.Append(" select saleno ");
    builder.Append(" FROM 表單TABLEb ");
    //表單代號,表單編號
    builder.AppendFormat(" WHERE 表單TABLEb001='{0}' ", this.formID);
    builder.AppendFormat(" AND 表單TABLEb002='{0}' ", this.StrSheetNo);
    DataSet set_saleno=this.m_objDB.CreateRecordset(builder.ToString(),this.Session["strProcID"].ToString());
    DataTable temp_saleno = set_saleno.Tables[0];
    foreach (DataRow saleno_read in temp_saleno.Rows)
    {
       string sql_OGAFILE = @"UPDATE OPENQUERY(ORACLE,'
               select oga903 from TT.oga_file where oga01=''" + saleno_read["saleno"] + "''') SET OGA903='Y'";                      
this.m_objDB.ExecuteSQL(sql_OGAFILE.ToString(),this.Session["strProcID"].ToString());
     }
   }
 }





#region 按下檢查時要做的事情

protected void butcheck_Click(object sender, EventArgs e)
{
    //先清空textbox
    
    
    base.BtnCreateToolSendForm.Attributes.Add("style", "display:none");//隱藏送出的按鈕
    int rows_count = MasterObj.DetailObjs[0].NewRows.Count;//取得grid有幾列資料
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    string customer_1 = "";//客戶名稱
    string customer_no = "";//客戶編號
    string terms_payment = "";//付款條件
    int customer_i = 1;
    string currency_1 = "";//幣別
    double local_currency = 0.0;//本幣未稅金額NTD
    double org_currency = 0.0;//原幣未稅金額
    double credit = 0.0; //授信額度
    double rate = 0.0; //匯率
    string txt_saleno = "";//銷貨單號
    bool bPass = true;
    if (rows_count == 0)
    {
         MessageBox.Show("請先輸入訂單編號");
    }
    else
    {
        foreach (DscRow dscRow in MasterObj.DetailObjs[0].NewRows)
        {
            string sqlstring_TT = @"Select * From OPENQUERY(ORACLE, '
            select oga01 as 銷貨單號,oga03 as 客戶編號,oga032 as 客戶名稱,oga903 as 是否放行,oga55 as 狀況碼,
                    ogaconf as 核准碼,oga09 as 單據別,oag02 as 付款條件,oga24 as 匯率,
                    oga50 as 出貨金額,OCCG03 as 授信額度,oga23 as  幣別,oga50 as 原幣未稅金額,(
                              select sum(omb16) from TT.omb_file  
                                    where TT.oga_file.oga01=omb31
                            ) as 本幣未稅金額
            from TT.oga_file join TT.oag_file on oga32=oag01
                 join TT.occg_file on OCCG01=oga03
            where oga01=''" + dscRow["saleno"].Value.ToString() + "''')";

           DataSet set_TT = this.m_objDB.CreateRecordset(" use EFNETDB;" +sqlstring_TT,this.Session["strProcID"].ToString());
           DataTable dtTemp_TT = set_TT.Tables[0];
           if (dtTemp_TT.Rows.Count == 0)
           {
               sb.Append("查無'" + dscRow["saleno"].Value.ToString() + "'的訂單資料,請檢查訂單號碼是否錯誤\r\n");
                bPass = false;
          }
          else
          {
              foreach (DataRow s_read in dtTemp_TT.Rows)
              {
                if (s_read["單據別"].ToString().Trim() == "1")
                {
                  sb.Append("單號:" + s_read["銷貨單號"] + "是出貨通知單喔~請再確認\r\n");
                  bPass = false;         
                }
                else if (s_read["核准碼"].ToString().Trim()=="X")
                {
                  sb.Append("單號:" + s_read["銷貨單號"] + "核准碼是作廢'X',請再確認");
                  bPass = false;
                }
                else if (s_read["是否放行"].ToString().Trim()!= "N")
                {
                  sb.Append("單號:" + s_read["銷貨單號"] + "已放行,請再確認.\r\n");
                  bPass = false;
                }
                else
                {
                  if (customer_i == 1)
                {
                customer_1 = s_read["客戶名稱"].ToString();
                currency_1 = s_read["幣別"].ToString();
                double x = 0.0;
                bool flag_1 = double.TryParse(s_read["匯率"].ToString(), out x);
                bool flag_2 = double.TryParse(s_read["原幣未稅金額"].ToString(), out x);
                bool flag_3 = double.TryParse(s_read["授信額度"].ToString(), out x);
                if (flag_1 && flag_2 && flag_3)
                {
                   rate = double.Parse(s_read["匯率"].ToString());
                   org_currency = double.Parse(s_read["原幣未稅金額"].ToString());
                   credit = double.Parse(s_read["授信額度"].ToString());
                }
                customer_no = s_read["客戶編號"].ToString();
                terms_payment = s_read["付款條件"].ToString();
                local_currency = rate * org_currency;
                txt_saleno = s_read["銷貨單號"].ToString();
              }
              else
              {
               if (customer_1 != s_read["客戶名稱"].ToString())               {
                 sb.Append("單號:" + s_read["銷貨單號"] + "公司名稱與其他不同");
                 bPass = false;
               }
               if (currency_1 != s_read["幣別"].ToString())
               {
                 sb.Append("單號:" + s_read["銷貨單號"] + "幣別與其他不同.\r\n");
                 bPass = false;
               }
               if (txt_saleno == s_read["銷貨單號"].ToString())
               {
                 sb.Append("單號:" + s_read["銷貨單號"] + "重複.\r\n");
                 bPass = false;
               }
               org_currency = org_currency + (double.Parse(s_read["原幣未稅金額"].ToString()));
               local_currency = local_currency + (rate * (double.Parse(s_read["原幣未稅金額"].ToString())));
                            }
                        }
                    }
                }
                customer_i++;
            }
        }
string ErrorMsg = sb.ToString();
if (bPass && butcheck.ToolTip != "0")
{
  //Lucas 觸發 refresh 重新解悉流程
  string str_java = "document.getElementById('" +base.BtnCreateToolRefresh.ClientID + "').click();";
  Page.ClientScript.RegisterStartupScript(typeof(string), "jva", str_java, true);
  base.BtnCreateToolSendForm.Attributes.Add("style", "display");
  butcheck.ToolTip = "0";
  butcheck.Text = "已檢查";
  currencymoney.Text = org_currency.ToString();//原幣未稅金額
  orgmoney.Text = local_currency.ToString();
  customerno.Text = customer_no;
  overdue3.Text = terms_payment;
  credit3.Text = credit.ToString();
  }
  else
  {
     base.BtnCreateToolSendForm.Attributes.Add("style", "display:none");
     butcheck.ToolTip = "";
     MessageBox.Show("錯誤訊息如下:\r\n" + ErrorMsg);
  }
} 
#endregion
}