2015年10月15日 星期四

接線圖



C# winForm --- Aform 開起其他程式[ Bform.exe ]並傳送參數;

Aform 開起其他程式[ Bform.exe ]並傳送參數;

1. 被開啟的程式[ Bform.exe ]
    Program.cs  內容須修改為可接受參數;
    static class Program
    {
        /// <summary>
        /// 應用程式的主要進入點。
        /// </summary>
        static System.Threading.Mutex _mutex;
        [STAThread]
        static void Main(string[] args)
        {
            //是否可以打開新進程
            bool createNew;
            Attribute guid_attr = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute));
            string guid = ((GuidAttribute)guid_attr).Value;
            _mutex = new System.Threading.Mutex(true, guid, out createNew);
            if (false == createNew)
            {
                //發現重複進程
            }
            _mutex.ReleaseMutex();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (args.Length == 0)
            {
                Application.Run(new Bform());
            }
            else
            {
                Application.Run(new Bform(args[0].ToString()));
            }
        }
    }
/////////////////////////////////
 
   Bform程式需新增

        public Bform(string P) ///定義字串參數P;
        {
            InitializeComponent();
            if (P != "")     ///判斷有沒有參數;
            {
                label1.Text = P;
            }
            else
            {
                label1.Text = "";
            }
        }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2. 執行端程式 [ Aform.exe ] 在按鍵中加入;
       private void button_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("Bform.exe", "ABC");
        }

         ////System.Diagnostics.Process.Start("程式.exe", "參數");


範例檔案







C# winForm 儲存文字檔[ .txt ]的格式定義為[ Unicode ]

FileStream fs = new FileStream(@"C:\test.txt", System.IO.FileMode.OpenOrCreate);

StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Unicode);


sw.Write("メールマガジン「.NETプログラミング研究」では");
sw.Flush();
sw.Close();
fs.Close();

C# winForm 子母視窗互傳參數的方式!!

Form1 開啟 Form2 並傳參數

1. 先在Form2 新增參數名稱及接收的方式
   ex:
   string _type;
   public void _Type 
        {
            get
            {
                return _type;
            }
            set
            {
                _type = value;
            }
        }

2. 在Form1 寫開啟 Form2 及傳參數

private void btn_Click(object sender, EventArgs e)  
        {
            Form2 fm = new Form2();
            fm._Type = "0";
            //fm._Table = masterDGV.CurrentRow.Cells[0].Value.ToString();
            //fm._Shop = _shopid;
            //fm._Date = DateTime.Now.ToString("yyyyMMdd HH:mm:ss");

            fm.ShowDialog();
        }

///////////////////////////////////////////////////////////////////////////////////////////

Form2 子視窗關閉,將參數回傳 主視窗 Form1
1. 先在Form1 開啟子視窗時定義 Owner = this;
    以及接收的參數及方式!
   string _strValue;
   public void _StrValue 
        {
            get
            {
                return _strValue;
            }
            set
            {
                _strValue = value;
            }
        }


private void btnShow_Click(object sender, EventArgs e)  
     {
            Form2 fm = new Form2();
            fm.Owner = this;
            //fm._Table = masterDGV.CurrentRow.Cells[0].Value.ToString();
            //fm._Shop = _shopid;
            //fm._Date = DateTime.Now.ToString("yyyyMMdd HH:mm:ss");

            fm.ShowDialog();
            TextBox1.text=_strValue;  //關閉表單後返回參數填入TextBox1;
     }


2. 在Form2 寫關閉視窗時回傳的方法

private void btnClose_Click(object sender, EventArgs e)  
    {
      Form1 F1 = (Form1)this.Owner;
      F1.StrValue = "Form2返回";;
      this.Close();

    }




2015年9月8日 星期二

C# 將DataTable寫入文字檔


public void SaveToCSV(DataTable oTable, string FilePath)
        {
            string data = "";
            int i =0;
            StreamWriter wr = new StreamWriter(FilePath, false, System.Text.Encoding.Default);
            foreach (DataRow row in oTable.Rows)
            {
                foreach (DataColumn column in oTable.Columns)
                {
                    data += row[column].ToString().Trim() + "," ;  // 欄位間加入逗號 ;
                }
                data = data.TrimEnd(',') ;  //取消最後一個逗號 ;
                i++;
                if (i < dt.Rows.Count)
                {
                     data += "\r\n";
                }
                wr.Write(data);
                data = "";
             
            }
            data += "\r\n";

            wr.Dispose();
            wr.Close();
        }

C# 取得檔案的位置及檔案名稱.並將內容寫入文字檔中的指定位置

按下button彈出檔案總管,尋找檔案,按下確定.
取得檔案的位置及檔案名稱.

private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog file = new OpenFileDialog();
            file.ShowDialog();
            textBox1.Text = file.FileName; // 將檔案位置及名稱顯示在textBox上
        }


//將textBox1的內容寫入文字檔中的指定位置。

//api.writeConfigFileValue("SQLData", "uid", textBox1.Text);

2015年9月7日 星期一

SQL 語法( 統一發票明細表 )

SELECT Y.NumBase, Y.CloseWorkDate, Y.InvNO, Y.sumInvoiceTotal, N.FlagNO
FROM (SELECT min(SUBSTRING(Invoice.No, 3, 8) / 250) AS NumBase, Orders.CloseWorkDate, MIN(Invoice.No)
+ ' ~ ' + MAX(Invoice.No) AS InvNO,
SUM((CASE WHEN Invoice.Flag = 'Y' THEN Invoice.Total ELSE (CASE WHEN Flag = 'N' THEN - Invoice.Total
ELSE 0 END) END)) AS sumInvoiceTotal
FROM Orders INNER JOIN
Invoice ON Orders.ID = Invoice.OrderID AND Orders.ShopID = Invoice.ShopID
WHERE (Orders.ShopID = 'h003') AND (SUBSTRING(Orders.CloseWorkDate, 1, 6) = LEFT('20150801', 6)) AND
(Invoice.Flag = 'Y' OR Invoice.Flag = 'O')
 GROUP BY    Orders.CloseWorkDate, SUBSTRING(Invoice.No, 3, 8) / 250) AS Y INNER JOIN
(SELECT Orders_1.CloseWorkDate, (SUBSTRING(Invoice_1.No, 3, 8) / 250) AS NumBase,

(SELECT SUBSTRING(i.No, 3, 8) + ',' + '' AS Expr1
FROM Invoice AS i INNER JOIN
Orders AS o ON i.OrderID = o.ID AND i.ShopID = o.ShopID
WHERE (Orders_1.CloseWorkDate = o.CloseWorkDate) AND (o.ShopID = 'h003') 
AND (SUBSTRING(i.No, 3, 8)/250)=(SUBSTRING(Invoice_1.No, 3, 8) / 250) AND 
(LEFT(o.CloseWorkDate, 6) = LEFT('20150801', 6)) AND (RIGHT(i.No, 1) = '#') FOR 
XML PATH('')) AS FlagNO

FROM Orders AS Orders_1 INNER JOIN
Invoice AS Invoice_1 ON Orders_1.ID = Invoice_1.OrderID AND Orders_1.ShopID = Invoice_1.ShopID
WHERE  (Orders_1.ShopID = 'h003') AND (LEFT(Orders_1.CloseWorkDate, 6) = LEFT('20150801', 6))
GROUP BY    Orders_1.CloseWorkDate,SUBSTRING(Invoice_1.No, 3, 8) / 250) AS N ON Y.CloseWorkDate = N.CloseWorkDate
AND  Y.NumBase = N.NumBase
ORDER BY   Y.CloseWorkDate

2015年8月19日 星期三

C# webForm 確定刪除 confirm!!

在 LinkButton的 onclientclick 加入  return confirm('確定刪除盤點單?');


<asp:LinkButton ID="removeButton" runat="server"  onclick="removeButton_Click"
                        onclientclick="return confirm('確定刪除盤點單?');" >刪除盤點單</asp:LinkButton>

C# winForm 確定刪除~確認視窗

private void delButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("確定刪除?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                string sql;
                string cN;
                cN = Convert.ToString(DGV.CurrentRow.Cells[0].Value);

                sql = string.Format("delete from record where cardno='{0}' ",cN);
                dbCom.myselect(sql);

            }
        }

新增空的DataTable..並填入數據

static DataTable dt()
        {
            DataTable dt = new DataTable();

            //新增資料欄位;
            dt.Columns.Add("ID", typeof(String));
            dt.Columns.Add("Name", typeof(String));
            dt.Columns.Add("item", typeof(String));
            dt.Columns.Add("website", typeof(String));

            //加入資料;
            dt.Rows.Add(new object[] { "1001 ", " Ivan", "奇摩網頁", "http://tw.yahoo.com/" });
            dt.Rows.Add(new object[] { "1002 ", " Tony", "谷歌網頁", "http://www.google.com/" });
            dt.Rows.Add(new object[] { "1003 ", " Hunter", "中華電信", "http://www.hinet.net/" });

            //輸出DataTable;
            return dt;
        }

2015年8月11日 星期二

刪除相同字串

data.Text="2015-06-08";

string st;
st=data.Text.Replace( "-", "");
///st=20150608



標籤機


SIZE 32 mm,25 mm
GAP 3 mm,0
CLS
TEXT 15,0,"TST24.BF2",0,1,1,"單號:005"
TEXT 15,25,"TST24.BF2",0,1,1,"====================="
TEXT 15,75,"TST24.BF2",0,1,1,"薑汁汽水"
TEXT 15,100,"TST24.BF2",0,1,2,"薑汁汽水"
PRINT 1,1

2015年8月10日 星期一

C# 發送EMail

void sendMail(string failDate)
        {
            MailMessage mail = new MailMessage();
            NetworkCredential cred = new NetworkCredential("service@gmail.com", "密碼");
            //收件者

            mail.To.Add("is@gmail.com");
            //("is@gmail.com,shirley@gmail.com");//多收件人員
            //郵件主旨
            mail.Subject = "蜜糖cafe類別轉檔失敗_通知郵件[ " + failDate +" ]";
            //寄件者
            mail.From = new System.Net.Mail.MailAddress("service@gmail.com");
            mail.IsBodyHtml = true;
            //郵件內容
            mail.Body = "轉檔失敗日期 : " + failDate;
            //Attachment attachment = new Attachment(@"C:\檔案.txt");//夾帶附件

            //設定SMTP
            SmtpClient smtp = new SmtpClient("smtp.gmail.com");
            smtp.UseDefaultCredentials = false;
            smtp.EnableSsl = true;
            smtp.Credentials = cred;
            smtp.Port = 587;
            //送出Mail
            smtp.Send(mail);
        }

Brown Cafe MySQL

select * from base_machine where name like '%宜蘭大學%'
//*
select  * from ord_order_info
where machine_id=74 and accountDate='2015-07-31' and no >='1507310740311' order by no

//*


select * from ord_invoice where header_id in(
select  id from ord_order_info where machine_id=74 and accountDate='2015-07-31' and no >='1507310740311' order by no)


//*

select o.no,i.number,i.* from ord_order_info o,ord_invoice i where o.id=i.header_id AND
o.machine_id=74 and o.accountDate='2015-07-31' and o.no >='1507310740311'
order by o.no

///
select o.no,o.total,i.number,i.money,i.* from ord_order_info o,ord_invoice i where o.id=i.header_id AND
o.machine_id=56 and o.accountDate='2015-07-31'
order by o.no

///

select * from ord_order_info where no>='1507310340318' and no <='1507310340321'
select * from ord_invoice where number>='RH51031662' and number<='RH51031669'


update ord_invoice set money=324 where number='RH51474622'

update ord_invoice set number='RH51474635' where number='RH51474638' and money=108

delete from ord_invoice where number='RH51477609' and money=460
///
///
///select delete_order_by_id(67215);


///
#update ord_invoice set coupled=2,drawer=100500,establish=1,money=0,number='RH51142432',printedNumber='家福桂林店A機'
#,state=1,header_id=100671 where id=111955