private int GetCurrentActivity() { DataRow[] dataRows = adaScheduleDataSet1.Activity.Select("ScheduleId=" + _scheduleRow.ScheduleId, "Sequence ASC"); int currentActivity = -1; int count = dataRows.Length; for (int i = 0; i < count; i++) { ADAMobileDataSet.ActivityRow row = dataRows[i] as ADAMobileDataSet.ActivityRow; bool isExecuted = (!row.IsExecutionStartNull() && !row.IsExecutionEndNull()); if (currentActivity < 0) { if (!isExecuted) { currentActivity = i; break; } } } return(currentActivity); }
private void ShowWorkSystem(ADAMobileDataSet.ScheduleRow scheduleRow) { int scheduleId = scheduleRow.ScheduleId; _scheduleRow = scheduleRow; symbolListView1.Items.Clear(); DataRow[] dataRows = adaScheduleDataSet1.Activity.Select("ScheduleId=" + scheduleId, "Sequence ASC"); int count = dataRows.Length; int currentActivity = -1; for (int i = 0; i < count; i++) { ADAMobileDataSet.ActivityRow activityRow = dataRows[i] as ADAMobileDataSet.ActivityRow; SymbolListView.SymbolListItem item = new SymbolListView.SymbolListItem(); bool isExecuted = (!activityRow.IsExecutionStartNull() && !activityRow.IsExecutionEndNull()); item.Checked = isExecuted; if (currentActivity < 0) { if (!isExecuted) { currentActivity = i; } } if (!activityRow.IsSymbolIdNull()) { if (activityRow.SymbolRow != null && !activityRow.SymbolRow.IsImageNull()) { item.Image = ImageEngine.FromArray(activityRow.SymbolRow.Image); } if (activityRow.SymbolRow != null && !activityRow.SymbolRow.IsSoundNull()) { item.Sound = activityRow.SymbolRow.Sound; } } item.Text = string.Format("{0}:{1}", activityRow.Sequence, activityRow.Name); symbolListView1.Items.Add(item); } symbolListView1.SelectedIndex = currentActivity; symbolListView1.Invalidate(); menuItemCurrent.Enabled = (currentActivity >= 0); menuItemCurrent.Text = "Current"; this.Text = scheduleRow.Name; EnablePrevNextPageMenuItems(); }
private void ShowDetail(int index) { ActivityDetailForm detailForm = new ActivityDetailForm(); DataRow[] dataRows = adaScheduleDataSet1.Activity.Select("ScheduleId=" + _scheduleRow.ScheduleId, "Sequence ASC"); detailForm.ActivityRow = dataRows[index] as ADAMobileDataSet.ActivityRow; int currentActivity = GetCurrentActivity(); detailForm.IsCurrentActivity = (index == currentActivity); if (DialogResult.OK == detailForm.ShowDialog()) { if (detailForm.ActivityRow.RowState == DataRowState.Modified) { int nextActivity = GetCurrentActivity(); if (nextActivity >= 0 && currentActivity != nextActivity) { ADAMobileDataSet.ActivityRow activityRow = dataRows[nextActivity] as ADAMobileDataSet.ActivityRow; activityRow.ExecutionStart = DateTime.Now; } if (UpdateCurrentActivity()) { if (currentActivity != nextActivity) { RefreshViews(); } if (nextActivity >= 0) { ShowDetail(nextActivity); } else { UpdateWorkSystemInstance(); } } } else if (detailForm.ActivityRow.RowState == DataRowState.Added) { if (AddWorkSystemInstance(detailForm.ActivityRow)) { RefreshViews(); int nextActivity = GetCurrentActivity(); if (nextActivity >= 0) { ShowDetail(nextActivity); } } } } }
private void menuItemStart_Click(object sender, EventArgs e) { ADAMobileDataSet.ScheduleRow scheduleRow = _activityRow.ScheduleRowByFK_Activity_Schedule; if (scheduleRow.Type == (int)ScheduleType.WorkSystemModel) { ADAMobileDataSet.ScheduleDataTable scheduleTable = scheduleRow.Table as ADAMobileDataSet.ScheduleDataTable; ADAMobileDataSet.ScheduleRow newScheduleRow = scheduleTable.NewScheduleRow(); newScheduleRow.Type = (int)ScheduleType.WorkSystemInstance; newScheduleRow.SymbolId = scheduleRow.SymbolId; newScheduleRow.Name = scheduleRow.Name; newScheduleRow.IsActive = true; newScheduleRow.rowguid = Guid.NewGuid(); ADAMobileDataSet.UserDataTable userTable = scheduleTable.DataSet.Tables["User"] as ADAMobileDataSet.UserDataTable; if (userTable.Count > 0) { newScheduleRow.UserId = (int)userTable.Rows[0]["UserId"]; } scheduleTable.AddScheduleRow(newScheduleRow); ADAMobileDataSet.ActivityRow[] rows = scheduleRow.GetActivityRowsByFK_Activity_Schedule(); ADAMobileDataSet.ActivityDataTable activityTable = _activityRow.Table as ADAMobileDataSet.ActivityDataTable; foreach (ADAMobileDataSet.ActivityRow row in rows) { ADAMobileDataSet.ActivityRow newRow = activityTable.NewActivityRow(); newRow.ScheduleId = newScheduleRow.ScheduleId; newRow.Sequence = row.Sequence; newRow.Name = row.Name; newRow.SymbolId = row.SymbolId; newRow.rowguid = Guid.NewGuid(); activityTable.AddActivityRow(newRow); if (row == _activityRow) { _activityRow = newRow; } } } if (_activityRow.IsExecutionStartNull()) { _activityRow.ExecutionStart = DateTime.Now; } else { _activityRow.ExecutionEnd = DateTime.Now; } DialogResult = DialogResult.OK; }
private bool AddWorkSystemInstance(ADAMobileDataSet.ActivityRow activityRow) { bool result = true; Cursor.Current = Cursors.WaitCursor; try { //ADAMobileDataSet.UserDataTable userTable = adaScheduleDataSet1.User; //if (userTable.Count > 0 && _userName != null // && _userName.Length > 0 && userTable.Rows[0]["Name"] != _userName) //{ // userTable.Rows[0]["Name"] = _userName; // UserTableAdapter userAdapter = new UserTableAdapter(); // int number = userAdapter.Update(adaScheduleDataSet1.User); //} adaScheduleDataSet1.EnforceConstraints = false; ScheduleTableAdapter scheduleAdapter = new ScheduleTableAdapter(); scheduleAdapter.Init(); int ret = scheduleAdapter.Update(adaScheduleDataSet1.Schedule); ActivityTableAdapter activityAdapter = new ActivityTableAdapter(); activityAdapter.Init(); ret = activityAdapter.Update(adaScheduleDataSet1.Activity); adaScheduleDataSet1.EnforceConstraints = true; } catch (Exception ex) { ReportError(ex); result = false; } Cursor.Current = Cursors.Default; return(result); }