Example #1
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            if (blockButtons)
            {
                return;
            }

            FrmCrewOnBoardEditor form = new FrmCrewOnBoardEditor();

            form.crewSignOn  = DateTimePicker.MinimumDateTime;
            form.crewSignOff = DateTimePicker.MinimumDateTime;

            var rslt = form.ShowDialog();

            if (rslt == DialogResult.OK)
            {
                string OnDateStr  = "";
                string OffDateStr = "";

                if (form.crewSignOn == DateTimePicker.MinimumDateTime)
                {
                    OnDateStr = "Null";
                }
                else
                {
                    OnDateStr = MainForm.DateTimeToQueryStr(form.crewSignOn);
                }

                if (form.crewSignOff == DateTimePicker.MinimumDateTime)
                {
                    OffDateStr = "Null";
                }
                else
                {
                    OffDateStr = MainForm.DateTimeToQueryStr(form.crewSignOff);
                }

                cmd.CommandText =
                    "insert into CREW_ON_BOARD (CREW_NAME,VESSEL_NAME,CREW_POSITION,DATE_ON,DATE_OFF) \n" +
                    "values('" + MainForm.StrToSQLStr(form.crewName) + "','" +
                    MainForm.StrToSQLStr(form.crewVessel) + "','" +
                    MainForm.StrToSQLStr(form.crewPosition) + "'," +
                    OnDateStr + "," + OffDateStr + ")";

                MainForm.cmdExecute(cmd);

                this.Cursor = Cursors.WaitCursor;

                try
                {
                    crewAdapter.Fill(DS, "CREW_ON_BOARD");
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Example #2
0
        private void EditCrewmember()
        {
            if (adgvCrew.Rows.Count == 0)
            {
                return;
            }

            if (blockButtons)
            {
                return;
            }

            FrmCrewOnBoardEditor form = new FrmCrewOnBoardEditor();

            form.crewName = adgvCrew.CurrentRow.Cells["CREW_NAME"].Value.ToString();

            if (adgvCrew.CurrentRow.Cells["VESSEL_GUID"].Value != null && adgvCrew.CurrentRow.Cells["VESSEL_GUID"].Value != System.DBNull.Value)
            {
                form.vesselGuid = MainForm.StrToGuid(adgvCrew.CurrentRow.Cells["VESSEL_GUID"].Value.ToString());
            }
            else
            {
                form.vesselGuid = MainForm.zeroGuid;
            }

            form.crewVessel   = adgvCrew.CurrentRow.Cells["VESSEL_NAME"].Value.ToString();
            form.crewPosition = adgvCrew.CurrentRow.Cells["CREW_POSITION"].Value.ToString();

            if (adgvCrew.CurrentRow.Cells["DATE_ON"].Value == null)
            {
                form.crewSignOn = DateTimePicker.MinimumDateTime;
            }
            else
            {
                form.crewSignOn = Convert.ToDateTime(adgvCrew.CurrentRow.Cells["DATE_ON"].Value);
            }

            if (adgvCrew.CurrentRow.Cells["DATE_OFF"].Value == null)
            {
                form.crewSignOff = DateTimePicker.MinimumDateTime;
            }
            else
            {
                form.crewSignOff = Convert.ToDateTime(adgvCrew.CurrentRow.Cells["DATE_OFF"].Value);
            }

            if (form.ShowDialog() == DialogResult.OK)
            {
                string OnDateStr  = "";
                string OffDateStr = "";

                if (form.crewSignOn == DateTimePicker.MinimumDateTime)
                {
                    OnDateStr = "Null";
                }
                else
                {
                    OnDateStr = MainForm.DateTimeToQueryStr(form.crewSignOn);
                }

                if (form.crewSignOff == DateTimePicker.MinimumDateTime)
                {
                    OffDateStr = "Null";
                }
                else
                {
                    OffDateStr = MainForm.DateTimeToQueryStr(form.crewSignOff);
                }

                cmd.CommandText =
                    "update CREW_ON_BOARD set \n" +
                    "CREW_NAME='" + MainForm.StrToSQLStr(form.crewName) + "',\n" +
                    "VESSEL_NAME='" + MainForm.StrToSQLStr(form.crewVessel) + "',\n" +
                    "CREW_POSITION='" + MainForm.StrToSQLStr(form.crewPosition) + "',\n" +
                    "DATE_ON=" + OnDateStr + ",\n" +
                    "DATE_OFF=" + OffDateStr + ",\n" +
                    "VESSEL_GUID=" + MainForm.GuidToStr(form.vesselGuid) + "\n" +
                    "where \n" +
                    "ID=" + adgvCrew.CurrentRow.Cells["ID"].Value.ToString();

                MainForm.cmdExecute(cmd);

                this.Cursor = Cursors.WaitCursor;

                int curRow = adgvCrew.CurrentRow.Index;
                int curCol = adgvCrew.CurrentCell.ColumnIndex;

                try
                {
                    DS.Tables["CREW_ON_BOARD"].Clear();

                    crewAdapter.Fill(DS, "CREW_ON_BOARD");

                    adgvCrew.CurrentCell = adgvCrew[curCol, curRow];
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }