Example #1
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("У Вас нет доступа к этой коллекции");
            }
        }
Example #2
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("У Вас нет доступа к этой коллекции");
            }
        }