Ejemplo n.º 1
0
        //заполнение значениями текстбоксов
        void attrValueFill()
        {
            fView frmMain = this.Owner as fView;

            foreach (FlowLayoutPanel flpBuf in tlpAttr.Controls)
            {
                foreach (Control tb in flpBuf.Controls)
                {
                    if (tb.Name.ToString() != "")
                    {
                        if (frmMain.attr[0] != "")
                        {
                            tb.Text = frmMain.attr[0];
                        }
                        else
                        {
                            tb.Text = "-";
                        }
                        frmMain.attr.RemoveAt(0);
                    }
                }
            }

            existsImageFill();
        }
Ejemplo n.º 2
0
        //закрытие
        private void fColEdit_FormClosing(object sender, FormClosingEventArgs e)
        {
            fView frmMain = this.Owner as fView;

            firstSelection         = true;
            frmMain.firstSelection = true;
        }
Ejemplo n.º 3
0
        //заполнение значениями текстбоксов
        void attrValueFill()
        {
            fView frmMain = this.Owner as fView;

            foreach (FlowLayoutPanel flpBuf in (splitContainer1.Panel1.Controls["flpMain"] as FlowLayoutPanel).Controls)
            {
                foreach (Control tcb in flpBuf.Controls)
                {
                    if ((tcb.GetType().ToString() == "System.Windows.Forms.TextBox") |
                        (tcb.GetType().ToString() == "System.Windows.Forms.ComboBox") |
                        (tcb.GetType().ToString() == "System.Windows.Forms.DateTimePicker"))
                    {
                        tcb.Text = frmMain.attr[0];
                        frmMain.attr.RemoveAt(0);
                    }
                }
            }

            foreach (FlowLayoutPanel flpBuf in (splitContainer1.Panel2.Controls["flpMisc"] as FlowLayoutPanel).Controls)
            {
                foreach (Control tcb in flpBuf.Controls)
                {
                    if ((tcb.GetType().ToString() == "System.Windows.Forms.TextBox") |
                        (tcb.GetType().ToString() == "System.Windows.Forms.ComboBox") |
                        (tcb.GetType().ToString() == "System.Windows.Forms.DateTimePicker"))
                    {
                        tcb.Text = frmMain.attr[0];
                        frmMain.attr.RemoveAt(0);
                    }
                }
            }
            existsImageFill();
        }
Ejemplo n.º 4
0
        //изменить экспонат
        private void toEdit(object sender, EventArgs e)
        {
            fView frmMain = this.Owner as fView;

            this.Hide();
            frmMain.editExhibit(selectedFund as object, EventArgs.Empty);
            this.Close();
        }
Ejemplo n.º 5
0
        //заполнение листбокса с существующими изображениями
        void existsImageFill()
        {
            fView frmMain = this.Owner as fView;

            if (Directory.Exists(frmMain.resPath + selectedFund + @"\" + frmMain.kp + @"\"))
            {
                string[] imagesInKp = Directory.GetFiles(frmMain.resPath + selectedFund + @"\" + frmMain.kp + @"\");
                lbExistsImg.Items.AddRange(imagesInKp);
            }
        }
Ejemplo n.º 6
0
        //выбор фонда
        private void selectFund(object sender, TreeViewEventArgs e)
        {
            if (firstSelection != true)
            {
                selectedFund = tvFund.SelectedNode.Text;

                if (tvFund.SelectedNode.Text != "Фонды:")
                {
                    fView   frmMain      = this.Owner as fView;
                    string  sql          = "SELECT * FROM " + selectedFund + " WHERE idExhibition = 1";
                    DataSet dsAttributes = new DataSet();

                    lbAttr.Items.Clear();
                    attrNames.Clear();

                    OleDbConnection connection = new OleDbConnection(frmMain.connection_string);
                    connection.Open();
                    OleDbDataAdapter    adapter     = new OleDbDataAdapter(sql, connection);
                    OleDbCommandBuilder comBuilder1 = new OleDbCommandBuilder(adapter);
                    dsAttributes = new DataSet();
                    adapter.Fill(dsAttributes, "Attributes");
                    connection.Close();

                    foreach (DataColumn dcAttr in dsAttributes.Tables[0].Columns)
                    {
                        if (dcAttr.ToString() != "idExhibition")
                        {
                            if (dcAttr.ToString().Contains('_'))
                            {
                                lbAttr.Items.Add(dcAttr.ToString().Replace("_", " "));
                            }
                            else
                            {
                                lbAttr.Items.Add(dcAttr.ToString());
                            }

                            attrNames.Add(dcAttr.ToString());
                        }
                    }

                    lblFindCount.Text = "Найдено: " + lbAttr.Items.Count.ToString();
                }
                else
                {
                    tbAttr.Text = "";
                    lbNewAttr.Items.Clear();
                    lbAttr.Items.Clear();
                    lblFindCount.Text = "Найдено: 0";
                }
            }
            else
            {
                firstSelection = false;
            }
        }
Ejemplo n.º 7
0
        //извлечение коллекций
        void fundsExtract()
        {
            fView frmMain = this.Owner as fView;

            if (frmMain.admin == true)
            {
                tsbtnAddCol.Enabled  = true;
                tspbtnDelCol.Enabled = true;
                tsbtnAddCol.Enabled  = true;

                OleDbConnection connection = new OleDbConnection(frmMain.connection_string);
                connection.Open();
                DataTable dtFunds = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
                connection.Close();

                tvFund.Nodes.Add("Фонды:");
                foreach (DataRow item in dtFunds.Rows)
                {
                    if ((string)item["TABLE_NAME"] != "Экспонаты" & (string)item["TABLE_NAME"] != "Пользователи")
                    {
                        tvFund.Nodes[0].Nodes.Add((string)item["TABLE_NAME"]);
                    }
                }
                tvFund.ExpandAll();
            }
            else
            {
                tsbtnAddCol.Enabled  = false;
                tspbtnDelCol.Enabled = false;
                tsbtnAddCol.Enabled  = false;

                string   sql = "SELECT * FROM Пользователи WHERE user = '******'";
                string[] collections;
                DataSet  dsCollections = new DataSet();

                OleDbConnection connection = new OleDbConnection(frmMain.connection_string);
                connection.Open();
                OleDbDataAdapter    adapter     = new OleDbDataAdapter(sql, connection);
                OleDbCommandBuilder comBuilder1 = new OleDbCommandBuilder(adapter);
                dsCollections = new DataSet();
                adapter.Fill(dsCollections, "Collections");
                connection.Close();

                string bufCollections = dsCollections.Tables[0].Rows[0][2].ToString();
                collections = bufCollections.Remove(bufCollections.Length - 1).Split('|');

                tvFund.Nodes.Add("Фонды:");
                foreach (string str in collections)
                {
                    tvFund.Nodes[0].Nodes.Add(str);
                }
                tvFund.ExpandAll();
            }
        }
Ejemplo n.º 8
0
        //удаление коллекции
        private void delCollection(object sender, EventArgs e)
        {
            fView frmMain = this.Owner as fView;

            if (tvFund.SelectedNode.Text != "Фонды:")
            {
                if (tvFund.SelectedNode.Text != "Общие")
                {
                    DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите удалить коллекцию '" + tvFund.SelectedNode.Text + "'?", "Удаление коллекции", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        string sql     = "SELECT * FROM " + tvFund.SelectedNode.Text;
                        string selFund = tvFund.SelectedNode.Text;

                        OleDbConnection connection = new OleDbConnection(frmMain.connection_string);

                        connection.Open();
                        OleDbDataAdapter    adapter    = new OleDbDataAdapter(sql, connection);
                        OleDbCommandBuilder comBuilder = new OleDbCommandBuilder(adapter);
                        DataSet             dsDelExh   = new DataSet();
                        adapter.Fill(dsDelExh, "delExhibition");
                        connection.Close();

                        for (int i = 0; i < dsDelExh.Tables[0].Rows.Count; i++)
                        {
                            frmMain.sqlQuery("DELETE FROM Общие WHERE idExhibition = " + dsDelExh.Tables[0].Rows[i]["idExhibition"]);
                            frmMain.sqlQuery("DELETE FROM Экспонаты WHERE idExhibition = " + dsDelExh.Tables[0].Rows[i]["idExhibition"]);
                        }

                        frmMain.sqlQuery("DROP TABLE " + tvFund.SelectedNode.Text);

                        MessageBox.Show("Коллекция '" + selFund + "' удалена!");

                        tvFund.Nodes.Clear();
                        fundsExtract();
                        frmMain.firstSelection = true;
                        frmMain.tvFund.Nodes.Clear();
                        frmMain.fundsExtract();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        //ничего
                    }
                }
                else
                {
                    MessageBox.Show("Нельзя удалить данную коллекцию!");
                }
            }
            else
            {
                MessageBox.Show("Выберите один из фондов!");
            }
        }
Ejemplo n.º 9
0
        //извлечение атрибутов
        void filtersExtract()
        {
            fView frmMain = this.Owner as fView;

            if (selectedFund != "Фонды:")
            {
                string[] sqls = new string[] { "SELECT Экспонаты.exhibitionName, Общие.* FROM Экспонаты, Общие", "SELECT * FROM " + selectedFund };
                attrFill(sqls);

                attrValueFill();
            }
        }
Ejemplo n.º 10
0
        //сохранить изменения
        private void saveChanges(object sender, EventArgs e)
        {
            fView frmMain = this.Owner as fView;

            OleDbConnection connection = new OleDbConnection(frmMain.connection_string);

            connection.Open();
            OleDbDataAdapter    adapter    = new OleDbDataAdapter("SELECT * FROM " + selectedFund, connection);
            OleDbCommandBuilder comBuilder = new OleDbCommandBuilder(adapter);
            DataSet             dsBuffer   = new DataSet();

            adapter.Fill(dsBuffer, "Rows");
            connection.Close();

            //добавление
            if (lbNewAttr.Items.Count > 0)
            {
                for (int i = 0; i < lbNewAttr.Items.Count; i++)
                {
                    if (lbNewAttr.Items[i].ToString().Contains(' '))
                    {
                        lbNewAttr.Items[i] = lbNewAttr.Items[i].ToString().Replace(" ", "_");
                    }
                    string sqlQuery = "ALTER TABLE " + selectedFund + " ADD COLUMN [" + lbNewAttr.Items[i].ToString() + "] text(255)";
                    frmMain.sqlQuery(sqlQuery);

                    for (int j = 0; j < dsBuffer.Tables[0].Rows.Count; j++)
                    {
                        sqlQuery = "UPDATE " + selectedFund + " SET [" + lbNewAttr.Items[i].ToString() + "] = ''";
                        frmMain.sqlQuery(sqlQuery);
                    }
                }
            }

            //удаление атрибута
            for (int i = 0; i < lbAttr.Items.Count; i++)
            {
                if (lbAttr.Items[i].ToString().Contains("Удалено: "))
                {
                    connection = new OleDbConnection(frmMain.connection_string);
                    frmMain.sqlQuery("ALTER TABLE " + selectedFund + " DROP [" + attrNames[i] + "]");
                }
            }

            tbAttr.Text = "";
            lbAttr.Items.Clear();
            lbNewAttr.Items.Clear();

            frmMain.tvFund.Nodes.Clear();
            frmMain.fundsExtract();
            frmMain.selectedFund = frmMain.tvFund.Nodes[0].Nodes[0].Text;
            frmMain.filtersExtract();
        }
Ejemplo n.º 11
0
        //добавление коллекции
        private void addCollection(object sender, EventArgs e)
        {
            fView frmMain = this.Owner as fView;

            if ((sender as ToolStripButton).Name == "tsbtnAddCol")
            {
                tslblCollName.Visible       = true;
                tstbCollName.Visible        = true;
                tsbtnCollName.Visible       = true;
                tssepCollName.Visible       = true;
                tsbtnCollNameCancel.Visible = true;
            }
            else
            {
                try
                {
                    tslblCollName.Visible       = false;
                    tstbCollName.Visible        = false;
                    tsbtnCollName.Visible       = false;
                    tssepCollName.Visible       = false;
                    tsbtnCollNameCancel.Visible = false;

                    if (tstbCollName.Text != "")
                    {
                        frmMain.sqlQuery("CREATE TABLE " + tstbCollName.Text + " (idExhibition int)");
                        tvFund.Nodes.Clear();
                        fundsExtract();
                        frmMain.tvFund.Nodes.Clear();
                        frmMain.firstSelection = true;
                        frmMain.fundsExtract();
                    }
                    else
                    {
                        MessageBox.Show("Введите название коллекции!");
                    }

                    tstbCollName.Text = "";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 12
0
        //сохранить изменения
        private void saveUser(object sender, EventArgs e)
        {
            if (tbLogin.Text != "" && tbPass.Text != "")
            {
                fView  frmMain = this.Owner as fView;
                string access  = "";
                string sql;

                if (cbAdminStatus.Checked != true)
                {
                    for (int i = 0; i < clbCollections.Items.Count; i++)
                    {
                        if (clbCollections.GetItemChecked(i))
                        {
                            access = access + clbCollections.Items[i].ToString() + @"|";
                        }
                    }
                }

                if (existsUserEdit == true)
                {
                    DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите изменить данные пользователя '" + editingUser + "'?", "Редактирование существующего пользователя", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        if (cbAdminStatus.Checked == true)
                        {
                            sql = "UPDATE Пользователи SET [user] = '" + tbLogin.Text + "', [password] = '" + tbPass.Text + "', [adminornot] = '1' WHERE user = '******'";
                        }
                        else
                        {
                            sql = "UPDATE Пользователи SET [user] = '" + tbLogin.Text + "', [password] = '" + tbPass.Text + "', [fundAccess] = '" + access + "', [adminornot] = '0' WHERE user = '******'";
                        }

                        sqlQuery(sql);

                        MessageBox.Show("Данные пользователя '" + editingUser + "' изменены");
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        MessageBox.Show("Данные пользователя " + editingUser + " не были изменены");
                    }

                    existsUserEdit         = false;
                    btnDeleteUser.Enabled  = false;
                    tbLogin.Text           = "";
                    tbPass.Text            = "";
                    cbUsers.Text           = "";
                    clbCollections.Enabled = true;

                    for (int i = 0; i < clbCollections.Items.Count; i++)
                    {
                        clbCollections.SetItemChecked(i, false);
                    }
                }
                else
                {
                    if (cbAdminStatus.Checked == true)
                    {
                        sql = "INSERT INTO Пользователи ([user], [password], [fundAccess], [adminornot]) values ('" + tbLogin.Text + "', '" + tbPass.Text + "', '', '1')";
                    }
                    else
                    {
                        sql = "INSERT INTO Пользователи ([user], [password], [fundAccess], [adminornot]) values ('" + tbLogin.Text + "', '" + tbPass.Text + "', '" + access + "', '0')";
                    }

                    sqlQuery(sql);

                    MessageBox.Show("Пользователь добавлен!");

                    existsUserEdit         = false;
                    btnDeleteUser.Enabled  = false;
                    tbLogin.Text           = "";
                    tbPass.Text            = "";
                    cbUsers.Text           = "";
                    clbCollections.Enabled = true;

                    for (int i = 0; i < clbCollections.Items.Count; i++)
                    {
                        clbCollections.SetItemChecked(i, false);
                    }
                }
                cbUsers.Items.Clear();
                loadUsers();
            }
            else
            {
                MessageBox.Show("Поля 'Логин' и 'Пароль' не могут быть пустыми!");
            }
        }
Ejemplo n.º 13
0
        //изменение экспоната
        private void addExhibit(object sender, EventArgs e)
        {
            fView  frmMain             = this.Owner as fView;
            string sql                 = "";
            string values_sql          = "";
            string descriptionFind_sql = "";
            bool   collectionOwner     = false;

            foreach (string col in frmMain.fundsAccess)
            {
                if (col == selectedFund)
                {
                    collectionOwner = true;
                }
            }

            if (collectionOwner == true | frmMain.admin == true)
            {
                foreach (FlowLayoutPanel flpBuf in (splitContainer1.Panel1.Controls["flpMain"] as FlowLayoutPanel).Controls)
                {
                    foreach (Control tcb in flpBuf.Controls)
                    {
                        if ((tcb.GetType().ToString() == "System.Windows.Forms.TextBox") |
                            (tcb.GetType().ToString() == "System.Windows.Forms.ComboBox") |
                            (tcb.GetType().ToString() == "System.Windows.Forms.DateTimePicker"))
                        {
                            if (tcb.Name == "exhibitionName")
                            {
                                sql = "UPDATE Экспонаты SET exportStatus = 'toCorrect(noXML)', exhibitionName = '" + tcb.Text + "', fundTable = '" + selectedFund + "' WHERE idExhibition = " + frmMain.id;
                                descriptionFind_sql = selectedFund + "_" + tcb.Text + "_";
                                //Вставка атрибутов в таблицу "Экспонаты", кроме "descriptionFind"
                                frmMain.editStatus = true;
                                frmMain.sqlQuery(sql);
                                sql = "UPDATE Общие SET ";
                            }
                            else
                            {
                                sql        = sql + "[" + tcb.Name + "] = '" + tcb.Text + "', ";
                                values_sql = values_sql + "'" + tcb.Text + "', ";
                            }
                        }
                    }
                }
                //Вставка атрибутов в таблицу "Общие"
                sql                 = sql.Remove(sql.Length - 2) + " WHERE idExhibition = " + frmMain.id;
                values_sql          = values_sql.Remove(values_sql.Length - 2);
                descriptionFind_sql = descriptionFind_sql + values_sql.Replace("'", "").Replace(", ", "_");
                frmMain.editStatus  = true;
                frmMain.sqlQuery(sql);

                sql = "UPDATE " + selectedFund + " SET ";
                if (frmMain.exStatus == false)
                {
                    //Вставка атрибутов в таблицу выбранной коллекции
                    string selValues_sql = "";
                    foreach (FlowLayoutPanel flpBuf in (splitContainer1.Panel2.Controls["flpMisc"] as FlowLayoutPanel).Controls)
                    {
                        foreach (Control tcb in flpBuf.Controls)
                        {
                            if ((tcb.GetType().ToString() == "System.Windows.Forms.TextBox") |
                                (tcb.GetType().ToString() == "System.Windows.Forms.ComboBox") |
                                (tcb.GetType().ToString() == "System.Windows.Forms.DateTimePicker"))
                            {
                                sql           = sql + "[" + tcb.Name + "] = '" + tcb.Text + "', ";
                                selValues_sql = selValues_sql + "'" + tcb.Text + "', ";
                            }
                        }
                    }

                    if ((splitContainer1.Panel2.Controls["flpMisc"] as FlowLayoutPanel).Controls.Count > 0)
                    {
                        sql                = sql.Remove(sql.Length - 2) + " WHERE idExhibition = " + frmMain.id;
                        selValues_sql      = selValues_sql.Remove(selValues_sql.Length - 2);
                        frmMain.editStatus = true;
                        frmMain.sqlQuery(sql);

                        //Вставка атрибутов в descriptionFind
                        sql = "UPDATE Экспонаты SET exportStatus = 'toCorrect(noXML)', descriptionFind = '" + descriptionFind_sql + "_" + selValues_sql.Replace("'", "").Replace(", ", "_") + "' WHERE idExhibition = " + frmMain.id;
                        frmMain.editStatus = true;
                        frmMain.sqlQuery(sql);
                    }
                    else
                    {
                        //Вставка атрибутов в descriptionFind
                        sql = "UPDATE Экспонаты SET exportStatus = 'toCorrect(noXML)', descriptionFind = '" + descriptionFind_sql + "' WHERE idExhibition = " + frmMain.id;
                        frmMain.editStatus = true;
                        frmMain.sqlQuery(sql);
                    }

                    //Редактирование изображений:
                    //изменение старых
                    pbImage.Image = null;
                    pbImage.Image = museum.Properties.Resources.image;
                    pbImage.Invalidate();

                    if (lbExistsImg.Items.Count > 0)
                    {
                        foreach (string imagePath in lbExistsImg.Items)
                        {
                            if (imagePath.Contains("Удалено: "))
                            {
                                try
                                {
                                    File.Delete(imagePath.Remove(0, 9));
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                            }
                        }
                    }

                    //добавление новых
                    if (!(Directory.Exists(frmMain.resPath + selectedFund)))
                    {
                        Directory.CreateDirectory(frmMain.resPath + selectedFund);
                    }
                    if (!(Directory.Exists(frmMain.resPath + selectedFund + @"\" + frmMain.kp)))
                    {
                        Directory.CreateDirectory(frmMain.resPath + selectedFund + @"\" + frmMain.kp);
                    }
                    //если обе папки уже существуют
                    {
                        foreach (string imgPath in lbImages.Items)
                        {
                            File.Copy(imgPath, frmMain.resPath + selectedFund + @"\" + frmMain.kp + @"\" + (imgPath.Split('\u005c')).Last().ToString(), true);
                        }
                        frmMain.editStatus = true;
                        frmMain.sqlQuery("UPDATE Общие SET Фото = '" + frmMain.resPath + selectedFund + @"\" + frmMain.kp + "' WHERE idExhibition = " + frmMain.id);
                    }

                    MessageBox.Show("Экспонат обновлён");
                }
                lbImages.Items.Clear();
                lbExistsImg.Items.Clear();
                existsImageFill();
                frmMain.exStatus = false;
                frmMain.refresh();
            }
            else
            {
                MessageBox.Show("У Вас нет доступа к этой коллекции");
            }
        }
Ejemplo n.º 14
0
        //закрытие формы
        private void formClosing(object sender, FormClosingEventArgs e)
        {
            fView frmMain = this.Owner as fView;

            frmMain.reportExists = false;
        }
Ejemplo n.º 15
0
        //заполнение списка существующих изображений
        void existsImageFill()
        {
            fView frmMain = this.Owner as fView;

            if (Directory.Exists(frmMain.resPath + selectedFund + @"\" + frmMain.kp + @"\"))
            {
                string[] imagesInKp = Directory.GetFiles(frmMain.resPath + selectedFund + @"\" + frmMain.kp + @"\");

                FlowLayoutPanel flpImages = new FlowLayoutPanel();
                flpImages.AutoSize = true;

                if (imagesInKp.Length > 0)
                {
                    foreach (string path in imagesInKp)
                    {
                        PictureBox pbImage = new PictureBox();

                        using (var file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Inheritable))
                        {
                            pbImage.Image = Image.FromStream(file);
                        }

                        pbImage.Width       = 70;
                        pbImage.Height      = 70;
                        pbImage.SizeMode    = PictureBoxSizeMode.Zoom;
                        pbImage.BorderStyle = BorderStyle.FixedSingle;
                        pbImage.Click      += new EventHandler(pbImage_Click);
                        if (flpImages.Controls.Count == 0)
                        {
                            pbMainImage.Image = pbImage.Image;
                        }

                        FlowLayoutPanel flpImageBuf = new FlowLayoutPanel();
                        flpImageBuf.Width         = pbImage.Width + 4;
                        flpImageBuf.Height        = pbImage.Height + 4;
                        flpImageBuf.FlowDirection = FlowDirection.TopDown;
                        flpImageBuf.WrapContents  = false;
                        flpImageBuf.Controls.Add(pbImage);

                        flpImages.Controls.Add(flpImageBuf);
                    }

                    tlpImages.Controls.Add(flpImages);


                    //если изображения не привязаны
                }
                else
                {
                    Label lblNoImages = new Label();

                    lblNoImages.Text     = "Изображения отсутствуют!";
                    lblNoImages.AutoSize = true;
                    lblNoImages.Top      = tlpImages.Height / 2 - lblNoImages.Height / 2;
                    lblNoImages.Left     = tlpImages.Width / 2 - lblNoImages.Width / 2 - 38;
                    lblNoImages.Font     = new Font(lblNoImages.Font, lblNoImages.Font.Style | FontStyle.Bold);

                    tlpImages.Controls.Add(lblNoImages);
                }
            }
            else
            {
                Label lblNoImages = new Label();

                lblNoImages.Text     = "Изображения отсутствуют!";
                lblNoImages.AutoSize = true;
                lblNoImages.Top      = tlpImages.Height / 2 - lblNoImages.Height / 2;
                lblNoImages.Left     = tlpImages.Width / 2 - lblNoImages.Width / 2 - 38;
                lblNoImages.Font     = new Font(lblNoImages.Font, lblNoImages.Font.Style | FontStyle.Bold);

                tlpImages.Controls.Add(lblNoImages);
            }
        }
Ejemplo n.º 16
0
        //выполнение запросов на добавление атрибутов
        void attrFill(string query, SplitterPanel p)
        {
            fView frmMain = this.Owner as fView;

            //извлечение атрибутов
            OleDbConnection connection = new OleDbConnection(connection_string);

            connection.Open();
            OleDbDataAdapter    adapter    = new OleDbDataAdapter(query, connection);
            OleDbCommandBuilder comBuilder = new OleDbCommandBuilder(adapter);

            dsAttr = new DataSet();
            adapter.Fill(dsAttr, "attributes");
            connection.Close();

            //удаление ненужных столцов из DataSet
            dsAttr.Tables[0].Columns.Remove("idExhibition");
            if (p == splitContainer1.Panel1)
            {
                dsAttr.Tables[0].Columns.Remove("Фото");
            }

            //создание полей для ввода атрибутов
            FlowLayoutPanel flpAttr = new FlowLayoutPanel();

            if (p == splitContainer1.Panel1)
            {
                flpAttr.Name = "flpMain";
            }
            else
            {
                flpAttr.Name = "flpMisc";
            }
            flpAttr.Dock     = DockStyle.Fill;
            flpAttr.AutoSize = true;

            for (int i = 0; i < dsAttr.Tables[0].Columns.Count; i++)
            {
                TextBox         tbAttr        = new TextBox();
                ComboBox        cbAttr        = new ComboBox();
                DateTimePicker  dtpAttr       = new DateTimePicker();
                Label           lblAttr       = new Label();
                FlowLayoutPanel flpAttrBuffer = new FlowLayoutPanel();

                tbAttr.Width          = 130;
                dtpAttr.Width         = 130;
                dtpAttr.Format        = DateTimePickerFormat.Custom;
                dtpAttr.CustomFormat  = "dd.MM.yy' 'hh:mm:ss";
                dtpAttr.ValueChanged += new EventHandler(dtpAttr_ValueChanged);
                cbAttr.Width          = 130;
                cbAttr.DropDownStyle  = ComboBoxStyle.DropDownList;
                switch (dsAttr.Tables[0].Columns[i].Caption)
                {
                case "Способ_поступления":
                    cbAttr.Items.AddRange(frmMain.sposobPostupleniya);
                    break;

                case "Типология_по_8-НК":
                    cbAttr.Items.AddRange(frmMain.tipologiyaPo8NK);
                    break;

                case "Форма_собственности":
                    cbAttr.Items.AddRange(frmMain.formaSobstvennosti);
                    break;

                case "Ограничение_на_публикацию_на_портале":
                    cbAttr.Items.AddRange(frmMain.ogranicheniye);
                    break;

                case "Категория_ценности_музейного_предмета":
                    cbAttr.Items.AddRange(frmMain.kategoriyaCennosti);
                    break;
                }
                lblAttr.AutoSize            = true;
                flpAttrBuffer.AutoSize      = true;
                flpAttrBuffer.FlowDirection = FlowDirection.TopDown;
                flpAttrBuffer.WrapContents  = false;

                if (dsAttr.Tables[0].Columns[i].ToString().Contains('_'))
                {
                    lblAttr.Text = dsAttr.Tables[0].Columns[i].ToString().Replace("_", " ");
                }
                else
                {
                    lblAttr.Text = dsAttr.Tables[0].Columns[i].ToString();
                }
                if (dsAttr.Tables[0].Columns[i].ToString() == "exhibitionName")
                {
                    lblAttr.Text = "Название экспоната";
                }

                string bufLabelName = lblAttr.Text;
                if (lblAttr.Text.Length > 20)
                {
                    lblAttr.Text = lblAttr.Text.Substring(0, 17) + "...";
                    ToolTip tooltip = new ToolTip();
                    tooltip.AutoPopDelay = 5000;
                    tooltip.InitialDelay = 1000;
                    tooltip.ReshowDelay  = 500;
                    tooltip.ShowAlways   = true;

                    tooltip.SetToolTip(lblAttr, bufLabelName);
                }

                string  bufDTPText = dtpAttr.Value.ToString();
                ToolTip tooltipDTP = new ToolTip();
                tooltipDTP.AutoPopDelay = 5000;
                tooltipDTP.InitialDelay = 1000;
                tooltipDTP.ReshowDelay  = 500;
                tooltipDTP.ShowAlways   = true;

                tooltipDTP.SetToolTip(dtpAttr, bufDTPText);

                tbAttr.Name  = dsAttr.Tables[0].Columns[i].ToString();
                cbAttr.Name  = dsAttr.Tables[0].Columns[i].ToString();
                dtpAttr.Name = dsAttr.Tables[0].Columns[i].ToString();

                flpAttrBuffer.Controls.Add(lblAttr);
                if ((dsAttr.Tables[0].Columns[i].Caption == "Способ_поступления") |
                    (dsAttr.Tables[0].Columns[i].Caption == "Типология_по_8-НК") |
                    (dsAttr.Tables[0].Columns[i].Caption == "Форма_собственности") |
                    (dsAttr.Tables[0].Columns[i].Caption == "Ограничение_на_публикацию_на_портале") |
                    (dsAttr.Tables[0].Columns[i].Caption == "Категория_ценности_музейного_предмета"))
                {
                    flpAttrBuffer.Controls.Add(cbAttr);
                }
                else if ((dsAttr.Tables[0].Columns[i].Caption == "Дата_записи_о_предмете_в_книге_поступлений_основного_фонда_музея"))
                {
                    flpAttrBuffer.Controls.Add(dtpAttr);
                }
                else
                {
                    flpAttrBuffer.Controls.Add(tbAttr);
                }
                flpAttr.Controls.Add(flpAttrBuffer);
            }
            p.Controls.Clear();
            dsAttr.Tables[0].Clear();
            p.Controls.Add(flpAttr);
        }
Ejemplo n.º 17
0
        //добавление экспоната в базу данных
        private void addExhibit(object sender, EventArgs e)
        {
            fView  frmMain             = this.Owner as fView;
            string sql                 = "";
            string attr_sql            = "";
            string values_sql          = "";
            string descriptionFind_sql = "";
            bool   collectionOwner     = false;

            foreach (string col in frmMain.fundsAccess)
            {
                if (col == selectedFund)
                {
                    collectionOwner = true;
                }
            }

            if (collectionOwner == true | frmMain.admin == true)
            {
                foreach (FlowLayoutPanel flpBuf in (splitContainer1.Panel1.Controls["flpMain"] as FlowLayoutPanel).Controls)
                {
                    foreach (Control tcb in flpBuf.Controls)
                    {
                        if ((tcb.GetType().ToString() == "System.Windows.Forms.TextBox") |
                            (tcb.GetType().ToString() == "System.Windows.Forms.ComboBox") |
                            (tcb.GetType().ToString() == "System.Windows.Forms.DateTimePicker"))
                        {
                            if (tcb.Name == "exhibitionName")
                            {
                                sql = "INSERT INTO Экспонаты (exhibitionName, fundTable) values ('" + tcb.Text + "', '" + selectedFund + "')";
                                descriptionFind_sql = selectedFund + "_" + tcb.Text + "_";
                            }
                            else
                            {
                                if (tcb.Name == "КП_номер")
                                {
                                    frmMain.kp = tcb.Text;
                                }
                                attr_sql   = attr_sql + "[" + tcb.Name.ToString() + "], ";
                                values_sql = values_sql + "'" + tcb.Text + "', ";
                            }
                        }
                    }
                }
                //Вставка атрибутов в таблицу "Экспонаты", кроме "descriptionFind"
                frmMain.sqlQuery(sql);
                frmMain.sqlQuery("SELECT MAX(idExhibition) FROM Экспонаты");

                //Вставка атрибутов в таблицу "Общие"
                attr_sql            = attr_sql.Remove(attr_sql.Length - 2);
                values_sql          = values_sql.Remove(values_sql.Length - 2);
                descriptionFind_sql = descriptionFind_sql + values_sql.Replace("'", "").Replace(", ", "_");
                sql = "INSERT INTO Общие (idExhibition, " + attr_sql + ") values ('" + frmMain.id + "', " + values_sql + ")";
                frmMain.sqlQuery(sql);

                if (frmMain.exStatus == false)
                {
                    //Вставка атрибутов в таблицу выбранной коллекции
                    string selAttr_sql   = "";
                    string selValues_sql = "";
                    foreach (FlowLayoutPanel flpBuf in (splitContainer1.Panel2.Controls["flpMisc"] as FlowLayoutPanel).Controls)
                    {
                        foreach (Control tcb in flpBuf.Controls)
                        {
                            if ((tcb.GetType().ToString() == "System.Windows.Forms.TextBox") |
                                (tcb.GetType().ToString() == "System.Windows.Forms.ComboBox") |
                                (tcb.GetType().ToString() == "System.Windows.Forms.DateTimePicker"))
                            {
                                selAttr_sql   = selAttr_sql + "[" + tcb.Name.ToString() + "], ";
                                selValues_sql = selValues_sql + "'" + tcb.Text + "', ";
                            }
                        }
                    }
                    if ((splitContainer1.Panel2.Controls["flpMisc"] as FlowLayoutPanel).Controls.Count > 0)
                    {
                        selAttr_sql   = selAttr_sql.Remove(selAttr_sql.Length - 2);
                        selValues_sql = selValues_sql.Remove(selValues_sql.Length - 2);
                        sql           = "INSERT INTO " + selectedFund + " (idExhibition, " + selAttr_sql + ") values ('" + frmMain.id + "', " + selValues_sql + ")";
                    }
                    else
                    {
                        sql = "INSERT INTO " + selectedFund + " (idExhibition) values ('" + frmMain.id + "')";
                    }
                    frmMain.sqlQuery(sql);

                    //Вставка атрибутов в descriptionFind
                    sql = "UPDATE Экспонаты SET exportStatus = 'toRegister(noXML)', descriptionFind = '" + descriptionFind_sql + "_" + selValues_sql.Replace("'", "").Replace(", ", "_") + "' WHERE idExhibition = " + frmMain.id;
                    frmMain.sqlQuery(sql);

                    //Добавление изображений
                    if (!(Directory.Exists(frmMain.resPath + selectedFund)))
                    {
                        Directory.CreateDirectory(frmMain.resPath + selectedFund);
                    }
                    if (!(Directory.Exists(frmMain.resPath + selectedFund + @"\" + frmMain.kp)))
                    {
                        Directory.CreateDirectory(frmMain.resPath + selectedFund + @"\" + frmMain.kp);
                    }
                    //если обе папки уже существуют
                    {
                        foreach (string imgPath in lbImages.Items)
                        {
                            File.Copy(imgPath, frmMain.resPath + selectedFund + @"\" + frmMain.kp + @"\" + (imgPath.Split('\u005c')).Last().ToString(), true);
                        }
                        frmMain.sqlQuery("UPDATE Общие SET Фото = '" + frmMain.resPath + selectedFund + @"\" + frmMain.kp + "' WHERE idExhibition = " + frmMain.id);
                    }

                    MessageBox.Show("Экспонат добавлен");
                }

                //Очищаем текстбоксы
                foreach (FlowLayoutPanel flpBuf in (splitContainer1.Panel1.Controls["flpMain"] as FlowLayoutPanel).Controls)
                {
                    foreach (Control tb in flpBuf.Controls)
                    {
                        if (tb.GetType().ToString() == "System.Windows.Forms.TextBox")
                        {
                            tb.Text = "";
                        }
                    }
                }

                foreach (FlowLayoutPanel flpBuf in (splitContainer1.Panel2.Controls["flpMisc"] as FlowLayoutPanel).Controls)
                {
                    foreach (Control tb in flpBuf.Controls)
                    {
                        if (tb.GetType().ToString() == "System.Windows.Forms.TextBox")
                        {
                            tb.Text = "";
                        }
                    }
                }
                lbImages.Items.Clear();
                pbImage.Image    = museum.Properties.Resources.image;
                frmMain.exStatus = false;
                frmMain.refresh();
            }
            else
            {
                MessageBox.Show("У Вас нет доступа к этой коллекции");
            }
        }