public void EditHourdata(string 員工編號, DateTime 日期) { this.Text = "工時資料編輯"; btnSend.Visible = false; 員工編號 = 員工編號.Replace("'", "''"); DataRow[] rows = DatabaseSet.員工Table.Select("編號 = '" + 員工編號 + "'"); if (rows.Length > 0) { _editLaborRow = rows[0] as DatabaseSet.員工Row; } else { throw new SWLHMSException("找不到員工編號 " + 員工編號 + " 的資料"); } cbbLine.SelectedValue = _editLaborRow.產線; cbxLaborNumber.DisplayMember = "編號"; cbxLaborNumber.ValueMember = "編號"; cbxLaborName.DisplayMember = "姓名"; cbxLaborName.ValueMember = "姓名"; bsLabor.DataSource = _editLaborRow; dtpDate.Value = 日期; LoadOldHourData(); UpdateRemainHour(); }
private void btnStoreLabor_Click(object sender, EventArgs e) { string newLaborNumber = tbxLaborNumber.Text; string newLaborName = tbxLaborName.Text; decimal newLaborWage = decimal.Parse(tbxLaborWage.Text); string newLaborLine = cbxLaborLine.SelectedValue.ToString(); try { if (this.EditState == EditStateType.Edit) { if (bsLabor.Current != null) { DatabaseSet.員工Row row = (bsLabor.Current as DataRowView).Row as DatabaseSet.員工Row; row.FillRow(newLaborNumber, newLaborName, newLaborWage, newLaborLine); 員工TableAdapter.Instance.Update(row);; } } else if (this.EditState == EditStateType.New) { DatabaseSet.員工Row newRow = DatabaseSet.員工Table.New員工Row(); newRow.FillRow(newLaborNumber, newLaborName, newLaborWage, newLaborLine); DatabaseSet.員工Table.Rows.Add(newRow); 員工TableAdapter.Instance.Update(newRow); } this.EditState = EditStateType.None; } catch (ConstraintException) { MessageBox.Show("已存在員工 (" + newLaborNumber + ")" + newLaborName + ",請指定其他編號"); } catch (Exception ex) { Global.ShowError(ex); } finally { if (this.EditState == EditStateType.Edit) { tbxLaborNumber.DataBindings[0].ReadValue(); tbxLaborName.DataBindings[0].ReadValue(); tbxLaborWage.DataBindings[0].ReadValue(); cbxLaborLine.DataBindings[0].ReadValue(); } } }
private void btnDelLabor_Click(object sender, EventArgs e) { try { if (bsLabor.Current != null) { DatabaseSet.員工Row row = (bsLabor.Current as DataRowView).Row as DatabaseSet.員工Row; string newLaborNumber = row.編號; string newLaborName = row.姓名; if (MessageBox.Show("確定刪除 員工 (" + newLaborNumber + ") " + newLaborName + " 及其所有相關資料?", "刪除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { row.Delete(); 員工TableAdapter.Instance.Update(row); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }