//private void CheckAlias(devRow row) //{ // if (DBNull.Value.Equals(aliasColumn) || aliasColumn.) //} /// <summary> /// Do column's value validation here. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DevDataTable_ColumnChangedEvent(object sender, System.Data.DataColumnChangeEventArgs e) { devRow row = e.Row as devRow; if (e.Column.ColumnName == tyColumn.ColumnName) { CheckType(row); } if (e.Column.ColumnName == roColumn.ColumnName) { CheckAddress(row); } if (e.Column.ColumnName == ipColumn.ColumnName) { CheckIP(row); } if (e.Column.ColumnName == idColumn.ColumnName) { CheckIPCamID(row); } if (e.Column.ColumnName == pwColumn.ColumnName) { CheckIPCamPassword(row); } }
private void CheckIP(devRow row) { DataColumn dataColumn = ipColumn; if (!IsValidIPAddress(row.ip)) { string errMsg = "格式錯誤"; row.SetColumnError(dataColumn, errMsg); return; } row.SetColumnError(dataColumn, null); }
private void CheckAddress(devRow row) { DataColumn dataColumn = roColumn; if (Regex.Match(row.ro, @"^\w{2}-\w{2}-\w{2}-\w{2}-\w{2}-\w{2}$").Length == 0) { string errMsg = "格式錯誤"; row.SetColumnError(dataColumn, errMsg); return; } row.SetColumnError(dataColumn, null); }
private void CheckIPCamPassword(devRow row) { DataColumn dataColumn = pwColumn; if (row.ty == (Byte)DeviceType.IP_CAM) { if (row.IspwNull() || string.IsNullOrEmpty(row.pw)) { string errMsg = "IP Cam Password 不可為空"; row.SetColumnError(dataColumn, errMsg); return; } } row.SetColumnError(dataColumn, null); }
private void CheckIPCamID(devRow row) { DataColumn dataColumn = idColumn; if (row.ty == (Byte)DeviceType.IP_CAM) { if (row.IsidNull() || string.IsNullOrEmpty(row.id)) { string errMsg = "IP Cam ID 不可為空"; row.SetColumnError(dataColumn, errMsg); return; } } row.SetColumnError(dataColumn, null); }
private void CheckType(devRow row) { DataColumn dataColumn = tyColumn; if (row.ty == (Byte)DeviceType.Control_Server) { int DeviceCount = (int)this.Compute("Count(ty)", String.Format("ty = {0}", (Byte)DeviceType.Control_Server)); if (DeviceCount > 1) { string errMsg = "控制伺服器只能有一臺"; row.SetColumnError(dataColumn, errMsg); return; } } row.SetColumnError(dataColumn, null); }
void DevDataTable_RowChanged(object sender, System.Data.DataRowChangeEventArgs e) { switch (e.Action) { case System.Data.DataRowAction.Add: case System.Data.DataRowAction.Change: devRow row = e.Row as devRow; CheckType(row); CheckAddress(row); CheckIP(row); CheckIPCamID(row); CheckIPCamPassword(row); if (!row.HasErrors) { lastInputIP = row.ip; lastInputSubnetMask = row.sm; lastInputGateway = row.gw; } break; } }