2012年6月1日

.Net Project 共用Module Part1

最近和同事一起開發專案,雙方各自開發各別的AP
原先使用的架構如下:
說明:
1.在Visual Studio方案中,使用一空白專案,將一些共用的module全部放在其中
   此空白專案屬性設置為類別庫( DLL)
2.在此方案中所有專案均參考此空白專案,每隻AP均透過DLL去使用static method 或class
Issue:
原先系統上,已執行AP1~AP3的程式,但因AP2有需求需要做修改,在DLL 未被變動的情況下,AP2修改後即可Release程式
但若是有人修改了空白專案中的程式,此時AP2 所complie出來的dll檔內容會與原先在系統上執行的不同!且AP1~AP3程式均是放置在同一目錄下執行
如此一來,AP2的修改者必須將所有AP重新建置,並且做更新動作

為避免這類的情形發生,與同事討論後系統架構修改如下:
如圖中所示:
1.空白專案還是保留
2.AP1~AP3專案中,除對空白專案的參考
3.如此一來,每個專案僅需要參考自己所需要的.cs檔,而不需要再有一層dll去呼叫

先記錄到這,下次再說如何共用專案:)


2012年5月19日

學習設計模式中....

最近想要多瞭解一些Design Pattern的模式
來應用到工作上所開發的程式碼
或因應日後自己開發的一些AP
看了一下有二本書,應該都蠻適合入門的
一本是Oreilly Head First Design Pattern
另一本是由程杰所寫的大話設計模式
二本剛好都拿到電子書
開始來k一下囉

2011年11月4日

C# ListView 使用方式

1.建立一個Windows Form專案
2.拉入ListView 控制項
3.填入ListView的Header

程式碼如下:

                this.listView1.Clear();//清除ListView所有資料

            this.listView1.Columns.Add("AAA", 60, HorizontalAlignment.Left);
            this.listView1.Columns.Add("BBB", 100, HorizontalAlignment.Left);
            this.listView1.Columns.Add("CCC", 80, HorizontalAlignment.Left);
4.將ListView中的MultiSelect設為True
設定為true後,則可利用ctrl 來多選
若要取得在ListView中被選取的Item方法如下:

利用foreach迴圈 ,並宣告ListViewItem,使用Selected判斷是否被選取!

                    foreach (ListViewItem tmpLstView in listView1.Items)
                    {
                        if (tmpLstView.Selected == true)==>被選取為true
                        {
                            strList1 = strList1 + tmpLstView.Text + ",";
                            strWorkID1 = strWorkID1 + tmpLstView.SubItems[1].Text + ",";
                        }
                    }      
取得ListView中特定一項Item中的細項資料方法為:
 tmpLstView.SubItems[0].Text ==>取得AAA對應的值
 tmpLstView.SubItems[1].Text ==>取得BBB對應的值
 tmpLstView.SubItems[1].Text ==>取得ccc對應的值

PLC WriteDeviceRandom方法

在MX component Programming 中Act元件
提供了WriteDeviceRandom方法
需要填入的資料如下:
1.Device List
2.Total Write Device count
3.Device Value
假設現在要寫入的Device有D200,D208,D201
在C#中DEVICE要寫入的資料為:
string strTmp = "D200" + '\n' + "D208" + '\n' + "D201" + '\n'
在VB.Net中則為:
dim strTmp as string = "D200" + vblf + "D208" + vblf + "D201" + vblf

2011年10月27日

C# Read XML file


C# 利用system.xml 中的class讀取XML的方式:


要讀取的XML內容如下:

<transaction>==>Root
<sqlcmd command="Insert into GlassEQPHistory(BCNo,LineID,NodeNo,EQName,Repdatetime,Funkey,Workid,WorkNo,Worktype,Pid,Groupflag,Eng_unit1,Eng_unit2,Overbakeflag,panel_angle ,criteria,Asmtype,Viewflag,Gapflag,Asmfinish,Sealfinish,Aufinish,RubbPass,SealPass,AUPass,LcdpPass,ChamberPass,Pair_no,NonMatchflg,RubxConfirmFlag,RubxPackFlag )values('7','RBAB0100','4','Rubx','20101218015044','Receive Data','F50CC011CL01','FA88','0','799','9','0','0','0','0','6','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0')"/>
</transaction>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
namespace Csharp_Console_ReadXML
{
    class Program
    {
        static void Main(string[] args)
        {
         //   XmlTextReader xRD= new XmlTextReader("C:\\4_Receive Data_20101218015044.xml");
             利用XMLDocument讀取;        
             XmlDocument xDL = new XmlDocument();
            xDL.Load("C:\\4_Receive Data_20101218015044.xml"); //Load XML檔

           
            讀取單一Node,利用SingleNode方法取得
             XmlNode xSingleNode = xDL.SelectSingleNode("//sqlcmd");
             XmlAttributeCollection xAT = xSingleNode.Attributes; //讀出該Node所有的Attribute
             for (int i = 0; i < xAT.Count; i++)
             {
                 if (xAT.Item(i).Name == "command")
                     Console.WriteLine(xAT.Item(i).Value); //讀出我們想要的attribute內容
             }

    '------------------這是分隔線--------------------------------------------------
若要讀取多個NodeList,使用SelectNodes方法
            XmlNodeList NodeList = xDL.SelectNodes("//sqlcmd");

            foreach (XmlNode item_File in NodeList)
            {
                Console.WriteLine(item_File.Name);
                XmlAttributeCollection xAT = item_File.Attributes;

                for (int i = 0; i < xAT.Count; i++)
                {
                    if (xAT.Item(i).Name == "command")
                        Console.WriteLine(xAT.Item(i).Value);
                }

                Console.WriteLine(item_File.InnerText);
            }

       
            Console.ReadLine();
        }
    }
}


C# Use OpenFileDialog

使用OpenFileDialog的方式
1.先建立一個實體
2.定義較常使用的屬性
Code Sample:


            OpenFileDialog ofd1 = new OpenFileDialog();
            ofd1.Title = "請選擇檔案";
            ofd1.InitialDirectory = "D:";
            ofd1.Filter = "txt files (*.log)|*.txt|All files (*.*)|*.*";

            if (ofd1.ShowDialog(this) == DialogResult.OK)
            {

............略
             }

SQLExpress連線出現18452 錯誤訊息

解決方式網路上有人分享
再次記錄,增加自己記憶力
1.進入SQL Express使用Windows驗證模式登入
2.點選已登入的Server,按下右鍵選擇屬性
3.選擇安全性,並在"伺服性驗證"將原先的
Windows驗證模式,改為SQL Server與Windows驗證模式