コード例 #1
0
        private void btnSaveContract_Click(object sender, EventArgs e)
        {
            if (tbContractNumber.Text.Equals("") || dtpContractDate.Text.Equals(" "))
            {
                MessageBox.Show("Please fill the mandatory fields!", "MISSING MANDATORY FIELDS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Contract newContract = new Contract();
                newContract.BookingNumber  = booking.BookingNumber;
                newContract.ContractNumber = tbContractNumber.Text;
                newContract.ContractDate   = dbUtil.FormatDate(dtpContractDate.Value);

                int receiptNumber;
                if (tbReceiptNumber.Text != null && Int32.TryParse(tbReceiptNumber.Text, out receiptNumber))
                {
                    newContract.ReceiptNumber = receiptNumber;
                }
                else if (tbReceiptNumber.Text.Equals(String.Empty))
                {
                    newContract.ReceiptNumber = null;
                }
                else
                {
                    MessageBox.Show("Receipt number must be numerical value!", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.contractInfoChnaged = false;
                    contract = null;
                }

                if (dtpReceiptIssueDate.Text.Equals(" "))
                {
                    newContract.ReceiptIssueDate = null;
                }
                else
                {
                    newContract.ReceiptIssueDate = dbUtil.FormatDate(dtpReceiptIssueDate.Value);
                }

                if (contractInfoChnaged && contract == null)
                {
                    if (broker.AddContract(newContract) != 13)
                    {
                        MessageBox.Show("Contract added to this booking!", "SUCCESS!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.contract             = newContract;
                        btnDeleteContract.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show("Contract cannot be created!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    this.contractInfoChnaged = false;
                }
                else if (contractInfoChnaged && contract != null)
                {
                    if (broker.UpdateContract(newContract) != 13)
                    {
                        MessageBox.Show("Contract updated!", "SUCCESS!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.contract             = newContract;
                        btnDeleteContract.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show("Contract cannot be updated!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    this.contractInfoChnaged = false;
                }
                else
                {
                    MessageBox.Show("No changes have been made!", "DATA NOT MODIFIED", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }