예제 #1
0
        private void btnDel_Click(object sender, EventArgs e)
        {
            //他に社員登録されているときは削除不可とする
            string SqlStr;

            SqlStr  = " where ";
            SqlStr += "(受注.社員ID = " + txtCode.Text.ToString() + ")  ";

            OleDbDataReader dr;

            Control.受注 Jyuchu = new Control.受注();
            dr = Jyuchu.FillBy(SqlStr);

            //該当社員の受注データが登録されているときは削除不可とする
            if (dr.HasRows == true)
            {
                MessageBox.Show(txtName.Text.ToString() + "の受注データ登録が存在します", txtName.Text.ToString() + "は削除できません", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dr.Close();
                Jyuchu.Close();
                return;
            }

            dr.Close();
            Jyuchu.Close();

            //得意先に担当者登録されているときは削除不可とする
            SqlStr  = " where ";
            SqlStr += "(得意先.担当社員コード = " + txtCode.Text.ToString() + ")  ";

            Control.得意先 tokui = new Control.得意先();

            dr = tokui.FillBy(SqlStr);

            if (dr.HasRows == true)
            {
                MessageBox.Show(txtName.Text.ToString() + "の担当得意先が存在します", txtName.Text.ToString() + "は削除できません", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dr.Close();
                tokui.Close();
                return;
            }

            dr.Close();
            tokui.Close();

            //削除確認
            if (MessageBox.Show("削除します。よろしいですか?", "削除確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            //データ削除
            Control.社員 Shain = new Control.社員();
            if (Shain.DataDelete(Convert.ToInt32(txtCode.Text.ToString())) == true)
            {
                MessageBox.Show("削除されました", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Shain.Close();

            DispClear();

            //データを 'darwinDataSet.社員' テーブルに読み込みます。
            this.社員TableAdapter.Fill(this.darwinDataSet.社員);
        }