예제 #1
0
        private void NewInspector(string newName = "")
        {
            //Add new inspector

            InspectorForm inspectorForm = new InspectorForm(MainForm.zeroGuid, 1);

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

            //Full name
            inspectorForm.inspectorName = "";
            //Notes
            inspectorForm.inspectorNotes = "";
            //Photo file
            inspectorForm.inspectorPhoto = "";
            //Unfavourable
            inspectorForm.inspectorUnfavourable = false;

            inspectorForm.inspectorBackground = "";

            var rslt = inspectorForm.ShowDialog();

            if (rslt == DialogResult.OK)
            {
                if (!InspectorExists(inspectorForm.inspectorName, MainForm.zeroGuid))
                {
                    cmd.CommandText =
                        "insert into INSPECTORS (INSPECTOR_NAME,Notes,Photo,Unfavourable,Background)\n" +
                        "values('" + MainForm.StrToSQLStr(inspectorForm.inspectorName) + "',\n" +
                        "'" + MainForm.StrToSQLStr(inspectorForm.inspectorNotes) + "',\n" +
                        "'" + MainForm.StrToSQLStr(inspectorForm.inspectorPhoto) + "',\n" +
                        Convert.ToString(inspectorForm.inspectorUnfavourable) + "," +
                        "'" + MainForm.StrToSQLStr(inspectorForm.inspectorBackground) + "')";
                    MainForm.cmdExecute(cmd);

                    //int row = dataGridView1.CurrentRow.Index;

                    if (DS.Tables.Contains("INSPECTORS"))
                    {
                        DS.Tables["INSPECTORS"].Clear();
                    }

                    cmd.CommandText =
                        "update INSPECTORS set HAS_PROFILE=False";
                    cmd.ExecuteNonQuery();

                    cmd.CommandText =
                        "update INSPECTORS set HAS_PROFILE=True \n" +
                        "where INSPECTOR_GUID in (select DISTINCT INSPECTOR_GUID from UNIFIED_COMMENTS)";
                    cmd.ExecuteNonQuery();

                    fillInspectors();
                }
            }
        }
예제 #2
0
        private void button6_Click(object sender, EventArgs e)
        {
            //Show 2nd inspector card

            if (comboBox2.Text.Trim().Length == 0)
            {
                return;
            }

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

            DataTable dt = DS.Tables["INSPECTORS_TWO"];

            DataRow[] dr = dt.Select("INSPECTOR_GUID=" + comboBox2.SelectedValue.ToString());

            if (dr.Length == 0)
            {
                return;
            }


            foreach (DataRow row in dr)
            {
                Guid inspectorGuid = MainForm.StrToGuid(row.ItemArray[0].ToString());

                InspectorForm inspForm = new InspectorForm(inspectorGuid, 0);

                inspForm.inspectorName = row.ItemArray[1].ToString();

                inspForm.inspectorNotes = row.ItemArray[2].ToString();

                inspForm.inspectorPhoto = row.ItemArray[3].ToString();

                inspForm.inspectorUnfavourable = Convert.ToBoolean(row.ItemArray[4]);

                inspForm.inspectorBackground = row.ItemArray[5].ToString();

                var rslt = inspForm.ShowDialog();

                if (rslt == DialogResult.OK)
                {
                    //Сохраняем изменения
                    cmd.CommandText =
                        "update INSPECTORS set\n" +
                        "INSPECTOR_NAME='" + StrToSQLStr(inspForm.inspectorName) + "',\n" +
                        "Notes='" + StrToSQLStr(inspForm.inspectorNotes) + "',\n" +
                        "Photo='" + StrToSQLStr(inspForm.inspectorPhoto) + "',\n" +
                        "Unfavourable=" + Convert.ToString(inspForm.inspectorUnfavourable) + "\n" +
                        "where INSPECTOR_GUID=" + MainForm.GuidToStr(inspectorGuid);
                    cmd.ExecuteNonQuery();

                    string inspector1 = comboBox1.Text;

                    UpdateInspectorsList();

                    //Записываем имя в поле
                    comboBox2.Text = inspForm.inspectorName;
                    comboBox1.Text = inspector1;
                }
            }
        }
예제 #3
0
        private void btnEditInspector_Click(object sender, EventArgs e)
        {
            //Edit inspector

            if (cbInspectorName.SelectedValue == null || MainForm.StrToGuid(cbInspectorName.SelectedValue.ToString()) == MainForm.zeroGuid)
            {
                MessageBox.Show("You are able to change just registered inspector", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Guid inspectorGuid = MainForm.StrToGuid(cbInspectorName.SelectedValue.ToString());

            this.Cursor = Cursors.WaitCursor;

            InspectorForm inspectorForm = new InspectorForm(inspectorGuid, 0);

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

            cmd.CommandText =
                "select * \n" +
                "from INSPECTORS \n" +
                "where INSPECTOR_GUID=" + MainForm.GuidToStr(inspectorGuid);

            OleDbDataReader reader = cmd.ExecuteReader();

            if (!reader.HasRows)
            {
                reader.Close();

                MessageBox.Show("Inspector with GUID=" + inspectorGuid.ToString() + " was not found in database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            reader.Read();
            //Full name
            inspectorForm.inspectorName = reader["INSPECTOR_NAME"].ToString();
            //Notes
            inspectorForm.inspectorNotes = reader["Notes"].ToString();
            //Photo file
            inspectorForm.inspectorPhoto = reader["Photo"].ToString();
            //Background
            inspectorForm.inspectorBackground = reader["Background"].ToString();

            inspectorForm.inspectorUnfavourable = Convert.ToBoolean(reader["Unfavourable"]);
            //Unfavourable
            reader.Close();

            var rslt = inspectorForm.ShowDialog();

            this.Cursor = Cursors.Default;

            if ((rslt == DialogResult.OK) && (MainForm.isPowerUser))
            {
                if (InspectorExists(inspectorForm.inspectorName, inspectorGuid))
                {
                    MessageBox.Show("Inspector with the same name already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                cmd.CommandText =
                    "update INSPECTORS set\n" +
                    "INSPECTOR_NAME='" + MainForm.StrToSQLStr(inspectorForm.inspectorName) + "',\n" +
                    "Notes='" + MainForm.StrToSQLStr(inspectorForm.inspectorNotes) + "',\n" +
                    "Photo='" + MainForm.StrToSQLStr(inspectorForm.inspectorPhoto) + "',\n" +
                    "Unfavourable=" + Convert.ToString(inspectorForm.inspectorUnfavourable) + ",\n" +
                    "Background='" + MainForm.StrToSQLStr(inspectorForm.inspectorBackground) + "'\n" +
                    "where INSPECTOR_GUID=" + MainForm.GuidToStr(inspectorGuid);
                cmd.ExecuteNonQuery();

                cmd.CommandText =
                    "update INSPECTORS set HAS_PROFILE=False";
                cmd.ExecuteNonQuery();

                cmd.CommandText =
                    "update INSPECTORS set HAS_PROFILE=True \n" +
                    "where INSPECTOR_GUID in (select DISTINCT INSPECTOR_GUID from UNIFIED_COMMENTS)";
                cmd.ExecuteNonQuery();

                fillInspectors();

                cbInspectorName.Text = inspectorForm.inspectorName;
            }
        }