Exemple #1
0
        private void btnStoreLine_Click(object sender, EventArgs e)
        {
            string newLine     = tbxLine.Text;
            string newLineName = tbxLineName.Text;

            try
            {
                if (this.EditState == EditStateType.Edit)
                {
                    if (bsLine.Current != null)
                    {
                        DatabaseSet.產線Row row = (bsLine.Current as DataRowView).Row as DatabaseSet.產線Row;
                        row.FillRow(newLine, newLineName);

                        產線TableAdapter.Instance.Update(row);;
                    }
                }
                else if (this.EditState == EditStateType.New)
                {
                    DatabaseSet.產線Row newRow = DatabaseSet.產線Table.New產線Row();
                    newRow.FillRow(newLine, newLineName);
                    DatabaseSet.產線Table.Rows.Add(newRow);

                    產線TableAdapter.Instance.Update(newRow);
                }

                this.EditState = EditStateType.None;
            }
            catch (ConstraintException)
            {
                MessageBox.Show("已存在產線 " + newLine + ",請指定其他產線");
            }
            catch (Exception ex)
            {
                Global.ShowError(ex);
            }
            finally
            {
                if (this.EditState == EditStateType.Edit)
                {
                    tbxLine.DataBindings[0].ReadValue();
                    tbxLineName.DataBindings[0].ReadValue();
                }
            }
        }
Exemple #2
0
        private void btnDelLine_Click(object sender, EventArgs e)
        {
            try
            {
                if (bsLine.Current != null)
                {
                    DatabaseSet.產線Row row = (bsLine.Current as DataRowView).Row as DatabaseSet.產線Row;

                    string newLine     = row.產線;
                    string newLineName = row.代號;

                    if (MessageBox.Show("確定刪除 產線" + newLine + "(" + newLineName + ") 及其所有相關品號?", "刪除提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                    {
                        row.Delete();
                        產線TableAdapter.Instance.Update(row);
                    }
                }
            }
            catch (Exception ex)
            {
                產線TableAdapter.Instance.Fill(DatabaseSet.產線Table);
                MessageBox.Show(ex.Message);
            }
        }