private void lbMilitaryUnit_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (sList != null)
     {
         sList.values.Clear();
     }
     if (lbMilitaryUnit.SelectedItem != null)
     {
         int idMilitaryUnit = (lbMilitaryUnit.SelectedItem as MilitaryUnit).Id;
         bList = new SubUnitList(DataWorker.getSubUnitList(sqlWorker.selectData("SELECT * FROM SubUnit WHERE idMilitaryUnit = " + idMilitaryUnit + " ORDER BY name")));
         lbBattalion.ItemsSource = bList.values;
     }
 }
예제 #2
0
        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            String rusName = (sender as MenuItem).Header.ToString();
            String tableName;

            switch (rusName)
            {
            case "Должность":
                tableName = "Post";
                break;

            case "Образование":
                tableName = "Education";
                break;

            case "Категория":
                tableName = "Category";
                break;

            case "Кем призван":
                tableName = "Draft";
                break;

            case "Кем возбуждено УД":
                tableName = "Organ";
                break;

            case "Семейное положение":
                tableName = "FamilyStatus";
                break;

            default:
                tableName = rusName;
                break;
            }

            DBList dblist = new DBList(tableName, DataWorker.getList(sqlWorker.selectData("SELECT * FROM " + tableName)));
            //statusBar.Text = dblist.values.Count + " строки" + (dblist.values.Count>0?"; {" + dblist.values[0].Key + ", " + dblist.values[0].Value + "}":"");

            EditDBList wnd = new EditDBList(rusName, dblist, sqlWorker);

            wnd.ShowDialog();
        }
예제 #3
0
        public AddAccomplice(SqliteWorker _sqlWorker)
        {
            InitializeComponent();
            this.ResizeMode = ResizeMode.CanMinimize;

            sqlWorker = _sqlWorker;

            postList         = new DBList("Post", DataWorker.getList(sqlWorker.selectData("SELECT * FROM Post ORDER BY description")));
            draftList        = new DBList("Draft", DataWorker.getList(sqlWorker.selectData("SELECT * FROM Draft ORDER BY description")));
            educationList    = new DBList("Education", DataWorker.getList(sqlWorker.selectData("SELECT * FROM Education ORDER BY description")));
            familyStatusList = new DBList("FamilyStatus", DataWorker.getList(sqlWorker.selectData("SELECT * FROM FamilyStatus ORDER BY description")));

            rankList     = new RankList(DataWorker.getRankList(sqlWorker.selectData("SELECT * FROM Rank ORDER BY priority")));
            militaryList = new MilitaryUnitList(DataWorker.getMilitaryUnitList(sqlWorker.selectData("SELECT * FROM MilitaryUnit")));

            cbPost.ItemsSource         = postList.values;
            cbDraft.ItemsSource        = draftList.values;
            cbEducation.ItemsSource    = educationList.values;
            cbFamilyStatus.ItemsSource = familyStatusList.values;

            cbRank.ItemsSource         = rankList.values;
            cbMilitaryUnit.ItemsSource = militaryList.values;

            rowSubUnit.Height  = new GridLength(0);
            rowContrakt.Height = new GridLength(0);
            this.Height       -= 150;
        }
예제 #4
0
        private void cbMilitaryUnit_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            cbSubUnit.IsEnabled = false;
            if (rowSubUnit.Height.Value > 0)
            {
                rowSubUnit.Height = new GridLength(0);
                this.Height      -= 30;
            }
            if (subUnitList != null)
            {
                subUnitList.values.Clear();
            }

            battalionList = new SubUnitList(
                DataWorker.getSubUnitList(
                    sqlWorker.selectData("SELECT * FROM SubUnit WHERE idMilitaryUnit = " +
                                         (cbMilitaryUnit.SelectedItem as MilitaryUnit).Id +
                                         " ORDER BY name")));
            cbBattalion.ItemsSource    = battalionList.values;
            cbBattalion.IsEnabled      = true;
            btnEditStructure.IsEnabled = true;
        }
예제 #5
0
        public MainWindow()
        {
            PleaseWait wndP = new PleaseWait();

            wndP.Show();

            InitializeComponent();

            dpLeft.Text  = "01.01." + DateTime.Now.ToString("yyyy");
            dpRight.Text = DateTime.Now.ToString("dd.MM.yyyy");

            crimes = new ObservableCollection <Crime>();
            try
            {
                sqlWorker = new SqliteWorker("CrimesAndIncidents");


                //изменение формата дат, оставлю, вдруг понадобится
                //for (int i = 0; i < crimes.Count; i++)
                //{
                //    sqlWorker.executeQuery("UPDATE Crime SET " +
                //        "dateRegistration = " + (crimes[i].DateRegistration == "" ? "NULL, " : "'" +crimes[i].DateRegistration + "', ") +
                //        "dateInstitution = " + (crimes[i].DateInstitution == "" ? "NULL, " : "'" + crimes[i].DateInstitution + "', ") +
                //        "dateCommit = " + (crimes[i].DateCommit == "" ? "NULL, " : "'" + crimes[i].DateCommit + "' ") +
                //        "WHERE idCrime = " + crimes[i].Id);
                //}
                coll = new CollectionViewSource();


                btnOk_Click_1(null, null);

                crimesDataGrid.CanUserAddRows = false;

                rowFilter.Height = new GridLength(0);

                cbRegistred.SelectedIndex = 1;

                mList = new MilitaryUnitList(DataWorker.getMilitaryUnitList(sqlWorker.selectData("SELECT * FROM MilitaryUnit")));
                mList.values.Add(new MilitaryUnit(-1, "", "все", "все", "", 0, 1));

                cbFilterMilitaryUnit.ItemsSource   = mList.values;
                cbFilterMilitaryUnit.SelectedIndex = mList.values.Count - 1;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Во время загрузки приложения возникли неполадки:\n" + ex.Message);
            }

            wndP.Close();
        }
        public SelectAccomplice(SqliteWorker _sqlWorker, AccompliceList accompliceList)
        {
            InitializeComponent();

            lbChoosed.AutoGenerateColumns    = false;
            lbChoosed.IsReadOnly             = true;
            lbNotChoosed.AutoGenerateColumns = false;
            lbNotChoosed.IsReadOnly          = true;

            sqlWorker = _sqlWorker;

            aList = new AccompliceList(
                DataWorker.getAccompliceList(
                    sqlWorker.selectData("SELECT R.shortName as rank, S.shortName as subUnit, SF.shortName as battalion, M.shortName as militaryUnit, A.*, R.priority " +
                                         "FROM Accomplice A " +
                                         "INNER JOIN SubUnit S ON S.idSubUnit = A.idSubUnit " +
                                         "LEFT JOIN Rank R ON R.idRank = A.idRank " +
                                         "LEFT JOIN SubUnit SF ON S.idFKSubUnit = SF.idSubUnit " +
                                         "LEFT JOIN MilitaryUnit M ON M.idMilitaryUnit = S.idMilitaryUnit OR M.idMilitaryUnit = SF.idMilitaryUnit " +
                                         "")));//сортировка хз по чему
            if (accompliceList == null)
            {
                aChoosedList = new AccompliceList();
            }
            else
            {
                aChoosedList = accompliceList;
                for (int i = 0; i < accompliceList.values.Count; i++)
                {
                    aList.deleteById(accompliceList.values[i].Id);
                }
            }
            aChoosedView         = new CollectionViewSource();
            aChoosedView.Source  = aList.values;
            aChoosedView.Filter += collectView_Filter;

            lbChoosed.ItemsSource    = aChoosedList.values;
            lbNotChoosed.ItemsSource = aChoosedView.View;

            txFilter.Focus();
        }
        public AddCrime(SqliteWorker _sqlWorker, Crime _c = null)
        {
            InitializeComponent();

            sqlWorker = _sqlWorker;

            organList    = new DBList("Organ", DataWorker.getList(sqlWorker.selectData("SELECT * FROM Organ ORDER BY description")));
            categoryList = new DBList("Category", DataWorker.getList(sqlWorker.selectData("SELECT * FROM Category ORDER BY description")));
            militaryList = new MilitaryUnitList(DataWorker.getMilitaryUnitList(sqlWorker.selectData("SELECT * FROM MilitaryUnit")));
            clauseList   = new ClauseList(DataWorker.getClauseList(sqlWorker.selectData("SELECT * FROM Clause ORDER BY number, part, point")));

            cbOrgan.ItemsSource        = organList.values;
            cbMilitaryUnit.ItemsSource = militaryList.values;
            cbClause.ItemsSource       = clauseList.values;
            lbCategoty.ItemsSource     = categoryList.values;

            if (_c != null)
            {
                isEditing = true;

                c                       = _c;
                txDamage.Text           = c.Damage;
                txDateCommit.Text       = c.DateCommit;
                txDateInstitution.Text  = c.DateInstitution;
                txDateRegistration.Text = c.DateRegistration;
                txDateVerdict.Text      = c.DateVerdict;
                txnumberCase.Text       = c.NumberCase;
                txStory.Text            = c.Story;
                txVerdict.Text          = c.Verdict;

                //если происшествие
                if (c.Clause == "")
                {
                    rbIncident.IsChecked = true;
                }

                chkIsRegistred.IsChecked = c.IsRegistred;

                for (int i = 0; i < cbOrgan.Items.Count; i++)
                {
                    if ((cbOrgan.Items[i] as KeyValue).Key == c.IdOrgan)
                    {
                        cbOrgan.SelectedIndex = i;
                    }
                }

                for (int i = 0; i < cbClause.Items.Count; i++)
                {
                    if ((cbClause.Items[i] as Clause).Id == c.IdClause)
                    {
                        cbClause.SelectedIndex = i;
                    }
                }

                for (int i = 0; i < cbMilitaryUnit.Items.Count; i++)
                {
                    if ((cbMilitaryUnit.Items[i] as MilitaryUnit).Id == c.IdMilitaryUnit)
                    {
                        cbMilitaryUnit.SelectedIndex = i;
                    }
                }

                accompliceList = new AccompliceList(
                    DataWorker.getAccompliceList(
                        sqlWorker.selectData("SELECT R.shortName as rank, S.shortName as subUnit, SF.shortName as battalion, M.shortName as militaryUnit, A.*, R.priority " +
                                             "FROM Accomplice A " +
                                             "INNER JOIN SubUnit S ON S.idSubUnit = A.idSubUnit " +
                                             "INNER JOIN Portaking P ON P.idAccomplice = A.idAccomplice " +
                                             "LEFT JOIN Rank R ON R.idRank = A.idRank " +
                                             "LEFT JOIN SubUnit SF ON S.idFKSubUnit = SF.idSubUnit " +
                                             "LEFT JOIN MilitaryUnit M ON M.idMilitaryUnit = S.idMilitaryUnit OR M.idMilitaryUnit = SF.idMilitaryUnit " +
                                             "WHERE P.idCrime = " + c.Id)));

                lbAccomplice.ItemsSource = accompliceList.values;

                //categoryList
                DBList categoryUsed = new DBList("", DataWorker.getList(sqlWorker.selectData("SELECT * FROM InCategory WHERE idCrime = " + c.Id + ";")));
                for (int i = 0; i < categoryUsed.values.Count; i++)
                {
                    for (int j = 0; j < categoryList.values.Count; j++)
                    {
                        if (categoryUsed.values[i].Key == categoryList.values[j].Key)
                        {
                            categoryList.values[j].IsCheked = true;
                        }
                    }
                }
            }
            else
            {
                chkIsRegistred.IsChecked = true;
            }
        }
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            int newId = sqlWorker.getNewId("Crime");
            int oldId = 0;

            if (rbCrime.IsChecked == true &&
                cbClause.SelectedItem != null &&
                cbMilitaryUnit.SelectedItem != null &&
                txStory.Text != "" &&
                txDateRegistration.Text != "")
            {
                //заполнен минимум для преступления
                string accomplices = "", postAccomplice = "";
                if (accompliceList != null)
                {
                    for (int i = 0; i < accompliceList.values.Count; i++)
                    {
                        accomplices += (i == 0 ? "" : "\n") + accompliceList.values[i].Rank + " " + accompliceList.values[i].ShortName;

                        //в идеале надо хранить в экземпляре Accomplice, но "и так сойдет"
                        postAccomplice += (i == 0 ? "" : "\n") + sqlWorker.selectData("SELECT description FROM Post WHERE idPost = " + accompliceList.values[i].IdPost).Rows[0][0].ToString();
                    }
                }
                if (c != null)
                {
                    oldId = c.Id;
                }
                c = new Crime(
                    cbOrgan.SelectedItem == null?0:(cbOrgan.SelectedItem as KeyValue).Key,
                    cbClause.SelectedItem == null?0:(cbClause.SelectedItem as Clause).Id,
                    cbMilitaryUnit.SelectedItem == null ? 0 : (cbMilitaryUnit.SelectedItem as MilitaryUnit).Id,
                    txDateRegistration.Text,
                    txDateInstitution.Text,
                    txDateCommit.Text,
                    txStory.Text,
                    txDamage.Text,
                    txDateVerdict.Text,
                    txVerdict.Text,
                    txnumberCase.Text,
                    postAccomplice,
                    accomplices,
                    cbClause.SelectedItem == null ? "" : (cbClause.SelectedItem as Clause).ToString(),
                    cbClause.SelectedItem == null ? "" : (cbClause.SelectedItem as Clause).Number,
                    chkIsRegistred.IsChecked == true ? 1:0,
                    cbMilitaryUnit.SelectedItem == null ? "" : (cbMilitaryUnit.SelectedItem as MilitaryUnit).ShortName);
            }
            else if (rbCrime.IsChecked == false &&
                     cbMilitaryUnit.SelectedItem != null &&
                     txStory.Text != "" &&
                     txDateRegistration.Text != "")
            {
                //введен минимум для происшествия
                string accomplices = "", postAccomplice = "";
                for (int i = 0; i < accompliceList.values.Count; i++)
                {
                    accomplices += (i == 0 ? "" : "\n") + accompliceList.values[i].Rank + " " + accompliceList.values[i].ShortName;

                    //в идеале надо хранить в экземпляре Accomplice, но "и так сойдет"
                    postAccomplice += (i == 0 ? "" : "\n") + sqlWorker.selectData("SELECT description FROM Post WHERE idPost = " + accompliceList.values[i].IdPost).Rows[0][0].ToString();
                }
                if (c != null)
                {
                    oldId = c.Id;
                }
                c = new Crime(
                    cbOrgan.SelectedItem == null ? 0 : (cbOrgan.SelectedItem as KeyValue).Key,
                    cbClause.SelectedItem == null ? 0 : (cbClause.SelectedItem as Clause).Id,
                    cbMilitaryUnit.SelectedItem == null ? 0 : (cbMilitaryUnit.SelectedItem as MilitaryUnit).Id,
                    txDateRegistration.Text,
                    txDateInstitution.Text,
                    txDateCommit.Text,
                    txStory.Text,
                    txDamage.Text,
                    txDateVerdict.Text,
                    txVerdict.Text,
                    txnumberCase.Text,
                    postAccomplice,
                    accomplices,
                    cbClause.SelectedItem == null ? "" : (cbClause.SelectedItem as Clause).ToString(),
                    cbClause.SelectedItem == null ? "" : (cbClause.SelectedItem as Clause).Number,
                    chkIsRegistred.IsChecked == true ? 1 : 0,
                    cbMilitaryUnit.SelectedItem == null ? "" : (cbMilitaryUnit.SelectedItem as MilitaryUnit).ShortName);
            }
            else
            {
                MessageBox.Show("Не все обязательные поля заполнены!");
                return;
            }
            //похоже единственный случай когда изменения в бд нужно производить не из главного окна
            //т.к. нужно вносить изменения в 2 дополнительные таблицы - Portaking и InCategory

            c.Id = newId;

            if (!isEditing && sqlWorker.addCrime(c, accompliceList, categoryList))
            {
                this.Close();
            }
            else if (isEditing && sqlWorker.updateCrime(c, accompliceList, categoryList, oldId))
            {
                this.Close();
            }
            else
            {
                MessageBox.Show("Ошибка при добавлении преступления в базу данных");
            }
        }
예제 #9
0
        private DataTable getTableCategories(string dateLeft, string dateRight)
        {
            DataTable tableMilitaryUnits = sqlWorker.selectData("SELECT shortName FROM MilitaryUnit ORDER BY idMilitaryUnit");
            DataTable tableCategories    = sqlWorker.selectData("SELECT description FROM Category;");
            DataTable tableData          = sqlWorker.selectData("SELECT M.idMilitaryUnit, Cat.idCategory as 'категория', COUNT(C.story) as 'количество преступлений'   " +
                                                                "FROM MilitaryUnit M " +
                                                                "INNER JOIN Crime C ON M.idMilitaryUnit = C.idMilitaryUnit  " +
                                                                "AND C.isRegistred = 1  " +
                                                                "AND C.idClause > -1 " +
                                                                "AND C.dateRegistration BETWEEN '" + dateLeft + "' AND '" + dateRight + "' " +
                                                                "INNER JOIN InCategory InC ON C.idCrime = InC.idCrime " +
                                                                "INNER JOIN Category Cat ON InC.idCategory = Cat.idCategory " +
                                                                "GROUP BY M.shortName, Cat.description " +
                                                                "ORDER BY M.idMilitaryUnit");

            DataTable tableCrimes = new DataTable();

            tableCrimes.Columns.Add("Категория");
            tableCrimes.Columns.Add("Всего");

            for (int i = 0; i < tableMilitaryUnits.Rows.Count; i++)
            {
                tableCrimes.Columns.Add(tableMilitaryUnits.Rows[i][0].ToString());
            }

            for (int i = 0; i < tableCategories.Rows.Count; i++)
            {
                tableCrimes.Rows.Add(tableCrimes.NewRow());
                tableCrimes.Rows[i][0] = tableCategories.Rows[i][0].ToString();
            }
            tableCrimes.Rows.Add(tableCrimes.NewRow());
            tableCrimes.Rows[tableCategories.Rows.Count][0] = "Всего";

            for (int i = 0; i < tableData.Rows.Count; i++)
            {
                int    idMil = Int32.Parse(tableData.Rows[i][0].ToString());
                int    idCat = Int32.Parse(tableData.Rows[i][1].ToString());
                string val   = tableData.Rows[i][2].ToString();
                tableCrimes.Rows[idCat - 1][idMil + 1] = val;
            }

            int[] valuesOnMilitaryUnit = new int[tableMilitaryUnits.Rows.Count];
            int[] valuesOnCategories   = new int[tableCategories.Rows.Count];

            for (int i = 0; i < tableMilitaryUnits.Rows.Count; i++)
            {
                valuesOnMilitaryUnit[i] = 0;
                for (int j = 0; j < tableCategories.Rows.Count; j++)
                {
                    if (tableCrimes.Rows[j][i + 2].ToString() != "")
                    {
                        valuesOnMilitaryUnit[i] += Int32.Parse(tableCrimes.Rows[j][i + 2].ToString());
                    }
                }
                tableCrimes.Rows[tableCategories.Rows.Count][i + 2] = valuesOnMilitaryUnit[i];
            }

            int sum = 0;

            for (int i = 0; i < tableCategories.Rows.Count; i++)
            {
                valuesOnCategories[i] = 0;
                for (int j = 0; j < tableMilitaryUnits.Rows.Count; j++)
                {
                    if (tableCrimes.Rows[i][j + 2].ToString() != "")
                    {
                        valuesOnCategories[i] += Int32.Parse(tableCrimes.Rows[i][j + 2].ToString());
                    }
                }
                tableCrimes.Rows[i][1] = valuesOnCategories[i];
                sum += valuesOnCategories[i];
            }
            tableCrimes.Rows[tableCategories.Rows.Count][1] = sum;

            return(tableCrimes);
        }
예제 #10
0
        public AddAccomplice(Accomplice accomplice, SqliteWorker _sqlWorker)
        {
            InitializeComponent();
            this.ResizeMode = ResizeMode.CanMinimize;

            sqlWorker = _sqlWorker;

            postList         = new DBList("Post", DataWorker.getList(sqlWorker.selectData("SELECT * FROM Post")));
            draftList        = new DBList("Draft", DataWorker.getList(sqlWorker.selectData("SELECT * FROM Draft")));
            educationList    = new DBList("Education", DataWorker.getList(sqlWorker.selectData("SELECT * FROM Education")));
            familyStatusList = new DBList("FamilyStatus", DataWorker.getList(sqlWorker.selectData("SELECT * FROM FamilyStatus")));

            rankList     = new RankList(DataWorker.getRankList(sqlWorker.selectData("SELECT * FROM Rank")));
            militaryList = new MilitaryUnitList(DataWorker.getMilitaryUnitList(sqlWorker.selectData("SELECT * FROM MilitaryUnit")));

            cbPost.ItemsSource         = postList.values;
            cbDraft.ItemsSource        = draftList.values;
            cbEducation.ItemsSource    = educationList.values;
            cbFamilyStatus.ItemsSource = familyStatusList.values;

            cbRank.ItemsSource         = rankList.values;
            cbMilitaryUnit.ItemsSource = militaryList.values;

            rowSubUnit.Height  = new GridLength(0);
            rowContrakt.Height = new GridLength(0);
            this.Height       -= 150;

            txFullName.Text          = accomplice.FullName;
            txName.Text              = accomplice.ShortName;
            txNumberContrakt.Text    = (accomplice.NumberContrakt == 0 ? "" : accomplice.NumberContrakt.ToString());
            txDateOfBirthday.Text    = accomplice.DateOfBirth;
            txDateFirstContrakt.Text = accomplice.DateOfFirstContrakt;
            txDateLastContrakt.Text  = accomplice.DateOfLastContrakt;

            chkbContrakt.IsChecked = accomplice.IsContrakt;
            chkbMedic.IsChecked    = accomplice.IsMedic;

            rSex.IsChecked = accomplice.Sex;
            fSex.IsChecked = !accomplice.Sex;

            for (int i = 0; i < cbPost.Items.Count; i++)
            {
                if ((cbPost.Items[i] as KeyValue).Key == accomplice.IdPost)
                {
                    cbPost.SelectedIndex = i;
                }
            }

            for (int i = 0; i < cbDraft.Items.Count; i++)
            {
                if ((cbDraft.Items[i] as KeyValue).Key == accomplice.IdDraft)
                {
                    cbDraft.SelectedIndex = i;
                }
            }

            for (int i = 0; i < cbEducation.Items.Count; i++)
            {
                if ((cbEducation.Items[i] as KeyValue).Key == accomplice.IdEducation)
                {
                    cbEducation.SelectedIndex = i;
                }
            }

            for (int i = 0; i < cbFamilyStatus.Items.Count; i++)
            {
                if ((cbFamilyStatus.Items[i] as KeyValue).Key == accomplice.IdFamilyStatus)
                {
                    cbFamilyStatus.SelectedIndex = i;
                }
            }

            for (int i = 0; i < cbRank.Items.Count; i++)
            {
                if ((cbRank.Items[i] as Rank).Id == accomplice.IdRank)
                {
                    cbRank.SelectedIndex = i;
                }
            }

            //получение id воинской части и выбор этой части в комбобоксе
            DataTable dt = sqlWorker.selectData("SELECT M.idMilitaryUnit FROM SubUnit S " +
                                                "LEFT JOIN SubUnit SF ON S.idFKSubUnit = SF.idSubUnit " +
                                                "LEFT JOIN MilitaryUnit M ON S.idMilitaryUnit = M.idMilitaryUnit OR SF.idMilitaryUnit = M.idMilitaryUnit " +
                                                "WHERE S.idSubUnit = " + accomplice.IdSubUnit);
            int idT = Int32.Parse(dt.Rows[0][0].ToString());

            for (int i = 0; i < cbMilitaryUnit.Items.Count; i++)
            {
                if ((cbMilitaryUnit.Items[i] as MilitaryUnit).Id == idT)
                {
                    cbMilitaryUnit.SelectedIndex = i;
                }
            }

            dt = sqlWorker.selectData("SELECT SF.idSubUnit FROM SubUnit S " +
                                      "LEFT JOIN SubUnit SF ON S.idFKSubUnit = SF.idSubUnit " +
                                      "WHERE S.idSubUnit = " + accomplice.IdSubUnit);
            if (dt.Rows[0][0].ToString() != "")
            {
                //есть промежуточное подразделение (батальон)
                idT = Int32.Parse(dt.Rows[0][0].ToString());
                for (int i = 0; i < cbBattalion.Items.Count; i++)
                {
                    if ((cbBattalion.Items[i] as SubUnit).Id == idT)
                    {
                        cbBattalion.SelectedIndex = i;
                    }
                }
            }
            else
            {
                //подразделение непосредственного подчинения воинской части
                for (int i = 0; i < cbBattalion.Items.Count; i++)
                {
                    if ((cbBattalion.Items[i] as SubUnit).Id == accomplice.IdSubUnit)
                    {
                        cbBattalion.SelectedIndex = i;
                    }
                }
            }

            idA = accomplice.Id;
        }
예제 #11
0
        internal static ObservableCollection <Crime> getCrimes(SqliteWorker sqlWorker, string leftDateRange = "", string rightDateRange = "9999.99.99", int idAccomplice = -1)
        {
            ObservableCollection <Crime> list = new ObservableCollection <Crime>();

            DataTable tableCrimes = sqlWorker.selectData("SELECT  Cl.point, Cl.part, Cl.number, Cl.description, C.*, M.shortName FROM Crime C " +
                                                         "LEFT JOIN Clause Cl ON C.idClause = Cl.idClause " +
                                                         "INNER JOIN MilitaryUnit M ON M.idMilitaryUnit = C.idMilitaryUnit " +
                                                         (idAccomplice == -1?"":"INNER JOIN Portaking P ON P.idCrime = C.idCrime AND P.idAccomplice = " + idAccomplice + " ") +
                                                         "WHERE C.dateRegistration BETWEEN '" + leftDateRange + "' AND '" + rightDateRange + "' " +
                                                         "ORDER BY C.dateRegistration, C.dateInstitution, C.dateCommit, C.story;");

            if (tableCrimes.Rows.Count > 0)
            {
                try
                {
                    for (int i = 0; i < tableCrimes.Rows.Count; i++)
                    {
                        DataTable tableAccomplice = sqlWorker.selectData("SELECT R.shortName, A.shortName, A.isContrakt, P.description, R.priority FROM Accomplice A " +
                                                                         "INNER JOIN Portaking P ON P.idAccomplice = A.idAccomplice " +
                                                                         "INNER JOIN Rank R ON A.idRank = R.idRank " +
                                                                         "INNER JOIN Post P ON P.idPost = A.idPost " +
                                                                         "WHERE P.idCrime = " + Int32.Parse(tableCrimes.Rows[i][4].ToString()) + ";");
                        string accomplices = "", postAccomplice = "";
                        for (int j = 0; j < tableAccomplice.Rows.Count; j++)
                        {
                            accomplices += (j == 0 ? "" : "\n") + tableAccomplice.Rows[j][0] + (tableAccomplice.Rows[j][2].ToString() == "1" &&
                                                                                                Int32.Parse(tableAccomplice.Rows[j][4].ToString()) < 60 ? " к/с " : " ") + tableAccomplice.Rows[j][1];
                            postAccomplice += (j == 0 ? "" : "\n") + tableAccomplice.Rows[j][3];
                        }

                        Crime c = new Crime(
                            tableCrimes.Rows[i][5].ToString() == "" ? 0 : Int32.Parse(tableCrimes.Rows[i][5].ToString()),
                            tableCrimes.Rows[i][6].ToString() == "" ? 0 : Int32.Parse(tableCrimes.Rows[i][6].ToString()),
                            tableCrimes.Rows[i][7].ToString() == "" ? 0 : Int32.Parse(tableCrimes.Rows[i][7].ToString()),
                            tableCrimes.Rows[i][8].ToString(),
                            tableCrimes.Rows[i][9].ToString(),
                            tableCrimes.Rows[i][10].ToString(),
                            tableCrimes.Rows[i][11].ToString(),
                            tableCrimes.Rows[i][12].ToString(),
                            tableCrimes.Rows[i][13].ToString(),
                            tableCrimes.Rows[i][14].ToString(),
                            tableCrimes.Rows[i][15].ToString(),
                            postAccomplice,
                            accomplices,
                            (tableCrimes.Rows[i][0].ToString() == "" ? "" : "п.'" + tableCrimes.Rows[i][0].ToString() + "' ") +
                            (tableCrimes.Rows[i][1].ToString() == "" ? "" : "ч." + tableCrimes.Rows[i][1].ToString() + " ") +
                            (tableCrimes.Rows[i][2].ToString() == "" ? "" : "ст." + tableCrimes.Rows[i][2].ToString() + " ") +
                            (tableCrimes.Rows[i][3].ToString() == "" ? "" : " (" + tableCrimes.Rows[i][3].ToString() + ")"),
                            (tableCrimes.Rows[i][2].ToString() == "" ? "" : tableCrimes.Rows[i][2].ToString()) +       //статья УК РФ
                            (tableCrimes.Rows[i][1].ToString() == "" ? "" : "," + tableCrimes.Rows[i][1].ToString()),
                            Int32.Parse(tableCrimes.Rows[i][16].ToString()),
                            tableCrimes.Rows[i][17].ToString()); //часть статьи

                        c.Id = tableCrimes.Rows[i][4].ToString() == "" ? 0 : Int32.Parse(tableCrimes.Rows[i][4].ToString());
                        list.Add(c);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Некорректные данные в БД:\n" + ex.Message);
                }
            }
            return(list);
        }