private void btnSave_Click(object sender, EventArgs e) { MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult resultDialog = MessageBox.Show("ยืนยันการบันทึกข้อมูล ?", "message", buttons, MessageBoxIcon.Warning); if (resultDialog == DialogResult.No) { return; } CvSystemCommonProperty data = new CvSystemCommonProperty(); data.IP_ADDRESS = CommonClassLibraryGlobal.IP; data.NAME_ADDRESS = CommonClassLibraryGlobal.HOST_NAME; data.SYSTEM_ID = frmSystem.SYSTEM_ID; data.USER_CREATE = CommonClassLibraryGlobal.OPERATOR_ID; data.USER_UPDATE = CommonClassLibraryGlobal.OPERATOR_ID; foreach (Control toolBox in this.Controls) { if (toolBox is SettingSpec_Text_Value_Without_Panel) { SettingSpec_Text_Value_Without_Panel tool = (SettingSpec_Text_Value_Without_Panel)toolBox; if (!SettingSpec_Text_Value_Without_Panel.checkData(tool)) { return; } else { PropertyInfo prop = null; prop = data.GetType().GetProperty(toolBox.Name, BindingFlags.Public | BindingFlags.Instance); if (null != prop && prop.CanWrite) { prop.SetValue(data, tool.TextBoxValue); } else { CommonClassLibraryGlobal.showError("ไม่สามารถเก็บค่าตัวแปรได้ '" + toolBox.Name + "' กรุณาติดต่อโปรแกรมเมอร์"); return; } } } } if (_cvSystemCommonController.Insert(data)) { CommonClassLibraryGlobal.showSuccess("แก้ไขข้อมูลสำเร็จ"); return; } else { CommonClassLibraryGlobal.showSuccess("แก้ไขข้อมูลไม่สำเร็จ กรุณาลองใหม่อีกครั้ง"); return; } }
private void btnClear_Click(object sender, EventArgs e) { MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show("ยืนยันการล้างข้อมูล ?", "message", buttons, MessageBoxIcon.Warning); if (result == DialogResult.No) { return; } foreach (Control toolBox in this.Controls) { if (toolBox is SettingSpec_Text_Value_Without_Panel) { SettingSpec_Text_Value_Without_Panel tool = (SettingSpec_Text_Value_Without_Panel)toolBox; tool.clearToDefault(); } } }
private void setOldValue(CvSystemCommonProperty data) { foreach (Control toolBox in this.Controls) { if (toolBox is SettingSpec_Text_Value_Without_Panel) { SettingSpec_Text_Value_Without_Panel tool = (SettingSpec_Text_Value_Without_Panel)toolBox; tool.TextBoxValue = GetPropValue(data, tool.Name.ToString()).ToString(); //var propInfo = data.GetType().GetProperty(tool.Name); //if (propInfo != null) //{ // propInfo.SetValue(info, value, null); //} } } }