//удаление коллекции 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("Выберите один из фондов!"); } }
//сохранить изменения 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(); }
//добавление коллекции 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); } } }
//добавление экспоната в базу данных 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("У Вас нет доступа к этой коллекции"); } }
//изменение экспоната 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("У Вас нет доступа к этой коллекции"); } }