Exemple #1
0
        public static Guid GetCrewGuid(string crewName, Guid positionGuid)
        {
            if (crewName.Trim().Length == 0)
            {
                return(MainForm.zeroGuid);
            }

            if (positionGuid == MainForm.zeroGuid)
            {
                return(MainForm.zeroGuid);
            }

            OleDbCommand cmd = new OleDbCommand("", MainForm.connection);

            cmd.CommandText =
                "select Count(CREW_GUID) as ReCount \n" +
                "from CREW \n" +
                "where \n" +
                "CREW_NAME='" + MainForm.StrToSQLStr(crewName) + "' \n" +
                "and CREW_POSITION_GUID=" + MainForm.GuidToStr(positionGuid);

            int recCount = (int)cmd.ExecuteScalar();

            switch (recCount)
            {
            case 0:
                return(SaveNewCrew(crewName, positionGuid));

            case 1:
                cmd.CommandText =
                    "select CREW_GUID \n" +
                    "from CREW \n" +
                    "where \n" +
                    "CREW_NAME='" + MainForm.StrToSQLStr(crewName) + "' \n" +
                    "and CREW_POSITION_GUID=" + MainForm.GuidToStr(positionGuid);

                return((Guid)cmd.ExecuteScalar());

            default:
                FormSelectCrewmemberFromList form = new FormSelectCrewmemberFromList();
                form.crewmemberName = crewName;
                form.positionGuid   = positionGuid;

                if (form.ShowDialog() == DialogResult.OK)
                {
                    return(form.crewGuid);
                }
                else
                {
                    return(MainForm.zeroGuid);
                }
            }
        }
Exemple #2
0
        private void btnInfo_Click(object sender, EventArgs e)
        {
            if (!CheckCrewExists())
            {
                MessageBox.Show("Unable to show details for \"" + cbCrewmember.Text + "\"", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            OleDbCommand cmd = new OleDbCommand("", MainForm.connection);

            //Проверяем наличие имени в списке

            cmd.CommandText =
                "select Count(CREW_GUID) \n" +
                "from CREW \n" +
                "where \n" +
                "CREW_NAME like '" + MainForm.StrToSQLStr(cbCrewmember.Text) + "' \n" +
                "and CREW_POSITION_GUID=" + MainForm.GuidToStr(_positionGuid);

            int recCount = (int)cmd.ExecuteScalar();

            if (recCount == 0)
            {
                return;
            }

            if (_crewGuid == MainForm.zeroGuid)
            {
                if (recCount == 1)
                {
                    cmd.CommandText =
                        "select CREW_GUID \n" +
                        "from CREW \n" +
                        "where \n" +
                        "CREW_NAME like '" + MainForm.StrToSQLStr(cbCrewmember.Text) + "' \n" +
                        "and CREW_POSITION_GUID=" + MainForm.GuidToStr(_positionGuid);

                    object x = cmd.ExecuteScalar();

                    try
                    {
                        _crewGuid = (Guid)x;
                    }
                    catch
                    {
                        MessageBox.Show("Unable to get crewmember GUID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    FormSelectCrewmemberFromList form = new FormSelectCrewmemberFromList();

                    form.crewmemberName = cbCrewmember.Text;
                    form.positionGuid   = _positionGuid;

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                    }
                }
            }

            if (cbCrewmember.SelectedValue.ToString().Length > 0)
            {
                this.Cursor = Cursors.WaitCursor;

                CrewDetailsForm form = new CrewDetailsForm();

                //form.positionGuid = _positionGuid;

                form.crewGuid = MainForm.StrToGuid(cbCrewmember.SelectedValue.ToString());
                //form.crewmemberName = cbCrewmember.Text;

                var rslt = form.ShowDialog();

                if (rslt == DialogResult.OK)
                {
                    FillCrewmembers(_positionGuid);

                    //Записываем имя в поле
                    cbCrewmember.Text = form.crewName;
                }

                this.Cursor = Cursors.Default;
            }
        }