Win Form保存資料時,如何透過updatecomponent的AfterApply事件截取存檔的錯誤訊息?
這種情況下是無法回傳信息到Client的,除非是系統出錯了,發生停止存檔才會回應訊息,如果是為了捕捉Server端所發生的錯誤,則可以通過throw new Exception的方式傳資訊回到Client,在Client的InfoDataSet有ApplyError事件可取得e.Exception.InnerException.Message就是Server的錯誤訊息。
如何在DefaultValidate中自訂動態的Validate訊息?
DefaultValidate只要在自定義方法中增加一行程式就可以了,比如:
public bool MyCheck(object val)
{
if(不符合條件)
{
(defaultValidate1.FieldItems[index] as FieldItem).WarningMsg = "Your Message";
// index是指第幾個欄位
return false;
}
else
return true;
}
如何設置某筆資料不可修改(如己確認的資料)?
1. ibsMaster設定AutoDisableControl
2. Navigator的BeforeItemClick事件:
if(e.ItemName=="Edit")
{
if((ibsMaster.Current as DataRowView).Row["AB001"].ToString() == "Y")
{
e.Cancel = true;
}
}
這樣就不會進入Edit狀態了。
Windows的表單,如何在Apply時撿查自訂的條件,並使存檔無效?
可以在InfoNavigator的BeforeItemClick事件中去檢查,如果有異常可以用e.Cancel來取消存檔。
if (e.ItemName == "Apply")
{
if (not 你的條件)
e.Cancel = true; // 取消動作
}
如何做到資料庫欄位限制只能輸入整數值,不能為小數,若為非整數資料會報錯誤訊息?
Windows可以通過KeyPress的處理來避免,比如在TextBox的Validating的事件寫程式處理,若是infoDataGridView可以在GridView的CellValidating事件中判斷。當然也可以用DefaultValidate來處理,這個也比較簡單可靠,還可以使用VS自身的MaskedTextBox。
有三個TextBox,其中一個欄位的值等於另兩個欄位的值的相乘,請問這要在什麼事件裏寫合適?
可對兩個欄位的TextBox中的TextChanged或者leave事件中來設計,如下:
private void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox3.Text=Convert.ToDecimal(TextBox1.Text)*Convert.ToDecimal(TextBox2.Tex);
}
為何貼上MultiLanguage後,無法在MultiLanguage中自動取得各元件的文字屬性內容?
在使用MultiLanguage元件時,需要將Form的Localizable的屬性設為True,這樣可以把設計者新增的元件自動產生到本元件的設定內容中。
請問 VB.NET Client如何 call ServerMethod?
例如:Server端的module為S001.dll,裏面有一個Server Method名稱為TestMethod
同步的情況:
Dim param(2) As Object
param(1) = "param1"
param(2) = "param2"
Dim obj = Srvtools.CliUtils.CallMethod("S001", "TestMethod", param)
異步的情況:
Public Sub CallBack(ByVal obj1() As Object)
MsgBox(obj1(0).ToString + " --" + obj1(1))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim obj1(2) As Object
obj1(1) = "1"
obj1(2) = "2"
Srvtools.CliUtils.AsyncCallMethod("sTDORDER", "MyCount", obj1, AddressOf CallBack)
End Sub
Win Form如何進行偵錯?
在Solution下將EEPNetClient設定為啟動項。
打開EEPNetServer的情況下,點選工具列上的綠色 按鈕,此時EEPNetServer會自動啟動。
此時,EEPNetClient會自動打開這樣Client的除錯即可開始。
Win Form下,要如何知道A/P Server的時間
有一個系統變數: "_ServerToDay"可以使用,會抓Server最新日期:
string serverdate=CliUtils.GetValue("_ServerToday");
ServerTime的取法:
object[] myRet = CallMethod("GLModule", "GetServerTime", new object[] { });
if (myRet != null && (int)myRet[0] == 0)
{
ServerDate = (string)myRet[1];
ServerTime = (string)myRet[2];
}
如何在win form上設計附件上傳的功能
OpenFileDialog為vs自帶元件
openFileDialog1.ShowDialog(); // 請再Form上貼入這個元件
string f = openFileDialog1.FileName; // 取FileName
string serverfile = "xxxx"; //自已命名
CliUtils.UpLoad(f, ServerFile); //上傳到a/p server上.
** 注意, filename與pathname要自行規劃.
在Windows中,如何使用預設的程式打開存在的檔案?
在Windows的檔案總管中都可以直接點選檔案即可呼叫預設的程式來打開,因此在EEP2006中,我們可以用以下的方式來完成同樣的任務:
System.Diagnostics.Process.Start(TextBox1.Text); //用預設的程式打開指定檔案.
在frmClientMain TreeView Menu是否可以自動顯示還有子項目(+),不要等點選後才出現,要如何設定?
可以自行修改TreeView顯示的層數,打開frmClientMainExtend.cs,修改TreeViewLevel的值,重新編譯EEPNetClient即可。
要如何比對使用者填入的密碼與資料庫中加密後的密碼是否一致?
以下的方法是取得密碼加密的字串:
string enPwd = sUserPwd;
if (sUserPwd != "")
{
char[] p = new char[] { };
bool q = Encrypt.EncryptPassword(sUserId, sUserPwd, 10, ref p, false);
enPwd = new string(p);
}
可以直接用enPwd與從User表中取得的密碼直接比較,如果相等表示輸入的密碼正確。
隱藏副檔中的某一個欄位的時機點,如欄位B根據欄位A的值來決定是否顯示?
可以在A欄位綁定完成時處理,如
public Form1()
{
InitializeComponent();
InfoTextBoxA.DataBindings["Text"].BindingComplete += delegate(object sender, BindingCompleteEventArgs e)
{
if (InfoTextBoxA.Text == "A")//如果滿足條件
{
InfoTextBoxB.Visible = true;
}
else
{
InfoTextBoxB.Visible = false;
}
}
}
WinForm要如何讀取文字檔?
FileStream fs = File.Open("文字檔路徑");
StreamReader sr = new StreamReader(fs);
String str = sr.ReadLine();//讀取一行
str = sr.ReadToEnd();//讀取所有
需要添加System.IO的引用。
日期可以由 2007/8/9 改成 2007/08/09 的顯示格式嗎?
string newvalue = DateTime.Parse("2007/8/9").ToString("yyyy/MM/dd");
如果是gridview的column的話,可以設定Column的DefaultCellStyle屬性的Format為yyyy/MM/dd。
在WinForm裡面如何取得一個全局的變量?
在frmClientMain.cs裡面定義了一個全局的靜態變量,
public static string SHOP_CODE = "1";
可以在Form裡這麼做:
using System.Reflection;
Type T = MdiParent.GetType();
FieldInfo F = T.GetField("SHOP_CODE");
String S = (String)F.GetValue(MdiParent);
MessageBox.Show(S);
如何實現,同一台機器不能同時run兩個EEPNetClient?
程式: frmClientMain.cs
在static void Main()中加入下列程式即可:
System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName("EEPNetClient");
if (ps.Length >1)
{
MessageBox.Show("EEPNetClient Can not run once! ");
Return;
}
在Client端運行時,出現“從字元字串轉換到datetime時,轉換失敗”的錯誤?
由於客戶機器的默認時間格式不一致造成的,可以修改代碼來確保不受到影響,例如:
sql = "SELECT * From orders where orderdate = '" + date + "'";
改為:
sql = "SELECT * From orders where orderdate = '" + date.ToString("yyyy/MM/dd") + "'";
如何在EEP Window Form內呼叫IE並將HTTP位址字串傳入,以跳出IE來連結WEB?
using System.Diagnostics;
string url = "http://www.infolight.com.tw";
Process.Start("iexplore.exe", url);