// Technique from http://www.vb-helper.com/howto_2008_uac_shield.html private Bitmap GetUacShieldIcon() { const int width = 50; const int height = 50; const int margin = 4; Bitmap shieldImage; Button button = new Button() { Text = " ", Size = new Size(width, height), FlatStyle = FlatStyle.System }; button.SetShieldIcon(true); Bitmap buttonImage = new Bitmap(width, height); button.Refresh(); button.DrawToBitmap(buttonImage, new Rectangle(0, 0, width, height)); int minX = width; int maxX = 0; int minY = width; int maxY = 0; for (int y = margin; y < height - margin; y++) { var targetColor = buttonImage.GetPixel(margin, y); for (int x = margin; x < width - margin; x++) { if (buttonImage.GetPixel(x, y).Equals(targetColor)) { buttonImage.SetPixel(x, y, Color.Transparent); } else { if (minY > y) minY = y; if (minX > x) minX = x; if (maxY < y) maxY = y; if (maxX < x) maxX = x; } } } int shieldWidth = maxX - minX + 1; int shieldHeight = maxY - minY + 1; shieldImage = new Bitmap(shieldWidth, shieldHeight); using (Graphics g = Graphics.FromImage(shieldImage)) g.DrawImage(buttonImage, 0, 0, new Rectangle(minX, minY, shieldWidth, shieldHeight), GraphicsUnit.Pixel); buttonImage.Dispose(); return shieldImage; }
private static void PrintDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { int tmpWidth, i, j; int eMarginBoundsTop = e.MarginBounds.Top; int eMarginBoundsLeft = e.MarginBounds.Left; int eMarginBoundsWidth = e.MarginBounds.Width; int tmpTop = e.MarginBounds.Top; int tmpLeft = e.MarginBounds.Left; string sTemp = ""; try { // Before starting first page, it saves Width & Height of Headers and CoulmnType if (PageNo == 1) { if (PrintXH) //有序号 { eMarginBoundsLeft += WidthXH; eMarginBoundsWidth -= WidthXH; TopXH = e.MarginBounds.Top; LeftXH = e.MarginBounds.Left; tmpLeft += WidthXH; } foreach (DataGridViewColumn GridCol in dgv.Columns) { if (!GridCol.Visible) { continue; } // Skip if the current column not selected if (!PrintDGV.SelectedColumns.Contains(GridCol.HeaderText)) { continue; } // Detemining whether the columns are fitted to page or not. if (FitToPageWidth) { tmpWidth = (int)(Math.Floor((double)((double)GridCol.Width / (double)TotalWidth * (double)TotalWidth * ((double)eMarginBoundsWidth / (double)TotalWidth)))); } else { tmpWidth = GridCol.Width; } HeaderHeight = (int)(e.Graphics.MeasureString(GridCol.HeaderText, GridCol.InheritedStyle.Font, tmpWidth).Height) + 11; // Save width & height of headres and ColumnType ColumnLefts.Add(tmpLeft); ColumnWidths.Add(tmpWidth); ColumnTypes.Add(GridCol.GetType()); tmpLeft += tmpWidth; } } // Printing Current Page, Row by Row while (RowPos <= dgv.Rows.Count - 1) { DataGridViewRow GridRow = dgv.Rows[RowPos]; if (GridRow.IsNewRow || (!PrintAllRows && !GridRow.Selected)) { RowPos++; continue; } //CellHeight = GridRow.Height; CellHeight = GridRow.Height + 8; if (tmpTop + CellHeight >= e.MarginBounds.Height + e.MarginBounds.Top) { DrawFooter(e, RowsPerPage); NewPage = true; PageNo++; e.HasMorePages = true; return; } else { if (NewPage) { // 单据汇总,表头 string[] sTitle = PrintTitle.Split(new char[1] { ';' }); for (j = 0; j < sTitle.Length; j++) { if (j <= 1) { if (j == 0) { e.Graphics.DrawString(sTitle[j], _Font12, Brushes.Black, new System.Drawing.RectangleF(e.MarginBounds.Left, tmpTop, e.MarginBounds.Width, (int)(e.Graphics.MeasureString(sTitle[j], _Font12, e.MarginBounds.Width).Height)), StrFormat); } else { e.Graphics.DrawString(sTitle[j], _Font, Brushes.Black, new System.Drawing.RectangleF(e.MarginBounds.Left, tmpTop, e.MarginBounds.Width, (int)(e.Graphics.MeasureString(sTitle[j], _Font12, e.MarginBounds.Width).Height)), StrFormatR); } } else { e.Graphics.DrawString(sTitle[j], _Font, Brushes.Black, e.MarginBounds.Left, tmpTop); } if (j == 0) { continue; } if (j == 1) { tmpTop += (int)(e.Graphics.MeasureString(sTitle[j], _Font12, e.MarginBounds.Width).Height); } else { tmpTop += (int)(e.Graphics.MeasureString(sTitle[j], _Font, e.MarginBounds.Width).Height); } } /* * e.Graphics.DrawString(PrintTitle, new System.Drawing.Font(dgv.Font, FontStyle.Bold), * Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top - * e.Graphics.MeasureString(PrintTitle, new System.Drawing.Font(dgv.Font, * FontStyle.Bold), e.MarginBounds.Width).Height - 13); * * String s = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString(); * * //e.Graphics.DrawString(s, new Font(dgv.Font, FontStyle.Bold), * // Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width - * // e.Graphics.MeasureString(s, new Font(dgv.Font, * // FontStyle.Bold), e.MarginBounds.Width).Width), e.MarginBounds.Top - * // e.Graphics.MeasureString(PrintTitle, new Font(new Font(dgv.Font, * // FontStyle.Bold), FontStyle.Bold), e.MarginBounds.Width).Height - 13); * * e.Graphics.DrawString(s, new System.Drawing.Font(_Font, FontStyle.Bold), * Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width - * e.Graphics.MeasureString(s, new System.Drawing.Font(_Font, * FontStyle.Bold), e.MarginBounds.Width).Width), e.MarginBounds.Top - * e.Graphics.MeasureString(PrintTitle, new System.Drawing.Font(new System.Drawing.Font(_Font, * FontStyle.Bold), FontStyle.Bold), e.MarginBounds.Width).Height - 13); */ // Draw Columns //tmpTop = e.MarginBounds.Top; i = 0; //表头 if (PrintXH) //有序号 { e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), new System.Drawing.Rectangle(LeftXH, tmpTop, WidthXH, HeaderHeight)); e.Graphics.DrawRectangle(Pens.Black, new System.Drawing.Rectangle(LeftXH, tmpTop, WidthXH, HeaderHeight)); e.Graphics.DrawString("序号", _Font, new SolidBrush(Color.Black), new System.Drawing.RectangleF(LeftXH, tmpTop, WidthXH, HeaderHeight), StrFormatC); } foreach (DataGridViewColumn GridCol in dgv.Columns) { if (!GridCol.Visible) { continue; } if (!PrintDGV.SelectedColumns.Contains(GridCol.HeaderText)) { continue; } e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), new System.Drawing.Rectangle((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[i], HeaderHeight)); e.Graphics.DrawRectangle(Pens.Black, new System.Drawing.Rectangle((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[i], HeaderHeight)); e.Graphics.DrawString(GridCol.HeaderText, GridCol.InheritedStyle.Font, new SolidBrush(GridCol.InheritedStyle.ForeColor), new System.Drawing.RectangleF((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[i], HeaderHeight), StrFormatC); i++; } NewPage = false; tmpTop += HeaderHeight; } // Draw Columns Contents if (PrintXH) //有序号 { e.Graphics.DrawString((RowPos + 1).ToString(), _Font, new SolidBrush(Color.Black), new RectangleF(LeftXH, (float)tmpTop, WidthXH, (float)CellHeight), StrFormatC); // Drawing Cells Borders e.Graphics.DrawRectangle(Pens.Black, new System.Drawing.Rectangle(LeftXH, tmpTop, WidthXH, CellHeight)); } i = 0; foreach (DataGridViewCell Cel in GridRow.Cells) { if (!Cel.OwningColumn.Visible) { continue; } if (!SelectedColumns.Contains(Cel.OwningColumn.HeaderText)) { continue; } // For the TextBox Column if (((Type)ColumnTypes[i]).Name == "DataGridViewTextBoxColumn" || ((Type)ColumnTypes[i]).Name == "DataGridViewLinkColumn") { if (PrintWarn) { //e.Graphics.DrawString(Cel.Value.ToString(), Cel.InheritedStyle.Font, // new SolidBrush(Cel.InheritedStyle.ForeColor), // new RectangleF((int)ColumnLefts[i], (decimal)tmpTop, // (int)ColumnWidths[i], (decimal)CellHeight), StrFormat); //确定背景 if (Cel.Style.BackColor == Color.LightPink) { e.Graphics.FillRectangle(new SolidBrush(Color.LightPink), new System.Drawing.Rectangle((int)ColumnLefts[i], (int)tmpTop, (int)ColumnWidths[i], (int)CellHeight)); } } if (Cel.Value.GetType() == typeof(System.DateTime)) { if (Cel.Value.ToString() != "") { sTemp = Convert.ToDateTime(Cel.Value.ToString()).ToString("yyyy年M月dd日"); } else { sTemp = ""; } e.Graphics.DrawString(sTemp, _Font, new SolidBrush(Cel.InheritedStyle.ForeColor), new RectangleF((int)ColumnLefts[i], (float)tmpTop, (int)ColumnWidths[i], (float)CellHeight), StrFormatC); } else { e.Graphics.DrawString(Cel.Value.ToString(), _Font, new SolidBrush(Cel.InheritedStyle.ForeColor), new RectangleF((int)ColumnLefts[i], (float)tmpTop, (int)ColumnWidths[i], (float)CellHeight), StrFormatC); } } // For the Button Column else if (((Type)ColumnTypes[i]).Name == "DataGridViewButtonColumn") { CellButton.Text = Cel.Value.ToString(); CellButton.Size = new Size((int)ColumnWidths[i], CellHeight); Bitmap bmp = new Bitmap(CellButton.Width, CellButton.Height); CellButton.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height)); e.Graphics.DrawImage(bmp, new System.Drawing.Point((int)ColumnLefts[i], tmpTop)); } // For the CheckBox Column else if (((Type)ColumnTypes[i]).Name == "DataGridViewCheckBoxColumn") { CellCheckBox.Size = new Size(14, 14); CellCheckBox.Checked = (bool)Cel.Value; Bitmap bmp = new Bitmap((int)ColumnWidths[i], CellHeight); Graphics tmpGraphics = Graphics.FromImage(bmp); tmpGraphics.FillRectangle(Brushes.White, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height)); CellCheckBox.DrawToBitmap(bmp, new System.Drawing.Rectangle((int)((bmp.Width - CellCheckBox.Width) / 2), (int)((bmp.Height - CellCheckBox.Height) / 2), CellCheckBox.Width, CellCheckBox.Height)); e.Graphics.DrawImage(bmp, new System.Drawing.Point((int)ColumnLefts[i], tmpTop)); } // For the ComboBox Column else if (((Type)ColumnTypes[i]).Name == "DataGridViewComboBoxColumn") { CellComboBox.Size = new Size((int)ColumnWidths[i], CellHeight); Bitmap bmp = new Bitmap(CellComboBox.Width, CellComboBox.Height); CellComboBox.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height)); e.Graphics.DrawImage(bmp, new System.Drawing.Point((int)ColumnLefts[i], tmpTop)); e.Graphics.DrawString(Cel.Value.ToString(), Cel.InheritedStyle.Font, new SolidBrush(Cel.InheritedStyle.ForeColor), new RectangleF((int)ColumnLefts[i] + 1, tmpTop, (int)ColumnWidths[i] - 16, CellHeight), StrFormatComboBox); } // For the Image Column else if (((Type)ColumnTypes[i]).Name == "DataGridViewImageColumn") { System.Drawing.Rectangle CelSize = new System.Drawing.Rectangle((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[i], CellHeight); Size ImgSize = ((Image)(Cel.FormattedValue)).Size; e.Graphics.DrawImage((Image)Cel.FormattedValue, new System.Drawing.Rectangle((int)ColumnLefts[i] + (int)((CelSize.Width - ImgSize.Width) / 2), tmpTop + (int)((CelSize.Height - ImgSize.Height) / 2), ((Image)(Cel.FormattedValue)).Width, ((Image)(Cel.FormattedValue)).Height)); } // Drawing Cells Borders e.Graphics.DrawRectangle(Pens.Black, new System.Drawing.Rectangle((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[i], CellHeight)); i++; } tmpTop += CellHeight; } RowPos++; // For the first page it calculates Rows per Page if (PageNo == 1) { RowsPerPage++; } } if (RowsPerPage == 0) { return; } // Write Footer (Page Number) DrawFooter(e, RowsPerPage); e.HasMorePages = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool ReloadDecorTab(OleDbConnection oleDb, DataTable oleSchem) { OleDbCommand cm; OleDbDataReader rd; int downPosDec = 0; if (oleSchem.Rows.Cast<DataRow>().Any( row => (string)row["TABLE_NAME"] == "decors")) { if (_tabDec != null) tabMain.Controls.Remove(_tabDec); if (AddTabDecor() && _tabDec != null) { cm = new OleDbCommand("SELECT * FROM decors ORDER BY Number ", oleDb); rd = cm.ExecuteReader(); var outComps = new LinkedList<Component2>(); if (_mSwAddin.GetComponents(_swSelModel.IGetActiveConfiguration().IGetRootComponent2(), outComps, true, false)) //if (_mSwAddin.GetComponents(_swSelComp, outComps, true, false)) { // чтение из первой табличке decors var listElementsForForm = Decors.GetListComponentForDecors( _mSwAddin, rd, outComps); rd.Close(); // чтение из второй таблички config_names var newList = new List<DecorsListL>(); foreach (var decorsList in listElementsForForm) { cm = new OleDbCommand( "SELECT * FROM config_names WHERE id = " + decorsList.Number, oleDb); rd = cm.ExecuteReader(); if (rd.Read()) { if (rd["captConf"] as string != null) { newList.Add(new DecorsListL(decorsList.Number, decorsList.Component, (string)rd["captConf"], (string)rd["captDec"])); } else { newList.Add(new DecorsListL(decorsList.Number, decorsList.Component, string.Empty, (string)rd["captDec"])); } } rd.Close(); } int dinamicDownPosition = 30; int dinamicDownPositionPack = 0; if (newList.Count == 0) { Logging.Log.Instance.Fatal("Возможна ошибка или описка в таблицах decors и config_names. Обратитесь к разработчикам библиотеки." + _swSelComp.Name); throw new Exception("Возможна ошибка или описка в таблицах decors и config_names. Обратитесь к разработчикам библиотеки."); } else minimumconf = newList.Min(x => x.Number); int diff = 0; foreach (var newL in newList) { bool isAtrName = false; ComboBox cb = null; string name = newL.LabelDecName; var sizeForLabel = (int)(name.Length * 2.5); if (sizeForLabel < 25) sizeForLabel = 25; #region Конфигурации if (newL.LabelConfName != "") { if ( !listForDimensions.Select(x => x.Component).Contains( newL.Component)) { string nameForConfigLabel = newL.LabelConfName; if (name.Length < nameForConfigLabel.Length) sizeForLabel = (int)(nameForConfigLabel.Length * 2.5); var labelForConfigName = new Label { Size = new Size(50, sizeForLabel), Location = new Point(0, dinamicDownPosition), Text = nameForConfigLabel, TextAlign = ContentAlignment. MiddleLeft }; diff = dinamicDownPosition - dinamicDownPositionPack; packControlsWhenChangeMode.Add(labelForConfigName, diff); var comboBoxConfig = new ComboBox { Location = new Point( labelForConfigName. Location .X + labelForConfigName.Size . Width, labelForConfigName. Location .Y), Size = new Size(50, 35), Name = nameForConfigLabel }; packControlsWhenChangeMode.Add(comboBoxConfig, diff); var labelConfigSelected = new Label { Location = new Point(labelForConfigName.Location.X, labelForConfigName.Location.Y > 35 ? labelForConfigName.Location.Y - 35 : 0), Size = new Size(248, 25), Font = new Font("Tahoma", (float)7, FontStyle.Bold) }; var seperateLine = new Label { Location = new Point(labelForConfigName.Location.X, labelForConfigName.Location.Y > 48 ? labelForConfigName.Location.Y - 48 : 0), Size = new Size(_tabDec.Size.Width, 20), Text = "_______________________________________________________", ForeColor = Color.DarkGray }; seperateLine.SendToBack(); comboBoxConfig.Tag = new KeyValuePair<Label, ComboBox>(labelConfigSelected, null); cb = comboBoxConfig; comboBoxConfig.KeyDown += ComboBoxConfigKeyDown; cm = new OleDbCommand( "SELECT * FROM decors_conf WHERE id = " + newL.Number + " AND Visible = true", oleDb); rd = cm.ExecuteReader(); var strList = new Dictionary<int, string>(); int l = 0; int numberCurrentConf = 0; var namesOfConfigurations = new List<string>(); while (rd.Read()) { string confName = rd["Configuration"].ToString(); namesOfConfigurations.Add(confName); } rd.Close(); namesOfConfigurations.Sort((x, y) => x.CompareTo(y)); bool wasChangeConf = false; foreach ( //нахождение нужной конфигурации и перезагрузка детали для этой конфигурации, var nameOfConfiguration in namesOfConfigurations) //чтобы активная конфигурация в детали совпадала с активной конфигурацией в компоненте { Size size = TextRenderer.MeasureText(nameOfConfiguration, comboBoxConfig.Font); int lonhName = size.Width; //nameOfConfiguration.Length * 5; if (comboBoxConfig.DropDownWidth < lonhName) comboBoxConfig.DropDownWidth = lonhName; if (newL.Component.ReferencedConfiguration == nameOfConfiguration) { numberCurrentConf = l; ChangeConfigurationForReferenceModel( newL.Component, nameOfConfiguration); wasChangeConf = true; } comboBoxConfig.Items.Add(nameOfConfiguration); strList.Add(l, nameOfConfiguration); l++; } if (!wasChangeConf) { string nameConf = namesOfConfigurations.First(); numberCurrentConf = 0; // если у модели больше конфигураций, чем указано в mdb newL.Component.ReferencedConfiguration = nameConf;// то мы вибираем первую по алфавиту, указаную там ChangeConfigurationForReferenceModel( newL.Component, nameConf); } _dictConfig.Add( new DecorComponentsWithCombo(newL.Number, comboBoxConfig, newL.Component), strList); comboBoxConfig.SelectedIndex = numberCurrentConf; if (!string.IsNullOrEmpty(comboBoxConfig.SelectedItem.ToString())) { labelConfigSelected.Text = comboBoxConfig.Name + " : " + comboBoxConfig.SelectedItem.ToString(); } _tabDec.Controls.Add(labelForConfigName); _tabDec.Controls.Add(comboBoxConfig); controlsToHideWhenChangeMode.Add(labelConfigSelected); _tabDec.Controls.Add(labelConfigSelected); controlsToHideWhenChangeMode.Add(seperateLine); _tabDec.Controls.Add(seperateLine); isAtrName = true; comboBoxConfig.SelectedIndexChanged += ComboBoxConfigSelectedIndexChanged; } else MessageBox.Show(@"Одинаковые управляющие компоненты " + newL.LabelConfName, _mSwAddin.MyTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (dinamicDownPosition == 30) dinamicDownPosition = 0; else dinamicDownPosition -= 40; } #endregion var lablDecor = new Label { Size = new Size(50, sizeForLabel), Location = new Point(110, dinamicDownPosition), Text = name }; packControlsWhenChangeMode.Add(lablDecor, diff); dinamicDownPosition = dinamicDownPosition + sizeForLabel + 45; dinamicDownPositionPack = dinamicDownPositionPack + sizeForLabel + 5; var comboBoxDecor = new ComboBox { Location = new Point( lablDecor.Location.X + lablDecor.Size.Width, lablDecor.Location.Y), Size = new Size(40, 35), Name = name, Tag = newL.Number }; packControlsWhenChangeMode.Add(comboBoxDecor, diff); if (isAtrName) cb.Tag = new KeyValuePair<Label, ComboBox>(((KeyValuePair<Label, ComboBox>)cb.Tag).Key, comboBoxDecor); #region Новая кнопка Button btnAllMod = null; Button btnFitDecor = null; var mdoc = newL.Component.IGetModelDoc(); if (mdoc != null && mdoc.get_CustomInfo2("", "Accessories") != "Yes") { var toolTip1 = new ToolTip(); btnAllMod = new Button { Location = new Point( comboBoxDecor.Location.X + comboBoxDecor.Size.Width + 5, comboBoxDecor.Location.Y), Tag = comboBoxDecor.Name, Name = newL.Number.ToString(), BackgroundImage = bitmap, BackgroundImageLayout = ImageLayout.Stretch //Image = bitmap }; packControlsWhenChangeMode.Add(btnAllMod, diff); btnAllMod.Size = new Size(21, 21);//new Size(30, btnAllMod.Size.Height); var r = new Rectangle(btnAllMod.Location, btnAllMod.Size); btnAllMod.DrawToBitmap(bitmap, r); toolTip1.SetToolTip(btnAllMod, "присвоить цвет всем деталям данного типа"); btnAllMod.Click += BtnAllModClick; _tabDec.Controls.Add(btnAllMod); var toolTip2 = new ToolTip(); Image image = imageList1.Images[3]; btnFitDecor = new Button { Location = new Point( comboBoxDecor.Location.X + comboBoxDecor.Size.Width + 5 + 25, comboBoxDecor.Location.Y), Tag = comboBoxDecor.Name, Name = newL.Number.ToString() + "ex", BackgroundImage = image, BackgroundImageLayout = ImageLayout.Stretch, //ImageKey = @"expand.ico", ImageList = imageList1 }; packControlsWhenChangeMode.Add(btnFitDecor, diff); toolTip2.SetToolTip(btnFitDecor, "растянуть декор по ширине и высоте"); btnFitDecor.Size = new Size(21, 21);//new Size(24, btnFitDecor.Size.Height); btnFitDecor.Tag = comboBoxDecor.Name; btnFitDecor.Click += BtnFitDecorClick; _tabDec.Controls.Add(btnFitDecor); } #endregion groupBox1.Location = new Point(groupBox1.Location.X, lablDecor.Location.Y + lablDecor.Size.Height + 5); if (!packControlsWhenChangeMode.ContainsKey(groupBox1)) packControlsWhenChangeMode.Add(groupBox1, diff); else packControlsWhenChangeMode[groupBox1] = diff; if (pnlMode == null) { pnlMode = new Panel() { Location = new Point(5, groupBox1.Location.Y + groupBox1.Size.Height - 17), Size = new Size(_tabDec.Size.Width - 10, 37) }; rbMode1 = new RadioButton() { Location = new Point(10, 15), Text = "Сокращенный", Size = new Size(groupBox1.Size.Width / 2 + 40, 30) }; rbMode2 = new RadioButton() { Location = new Point(pnlMode.Size.Width / 2 + 25, rbMode1.Location.Y), Text = "Полный", Size = new Size(groupBox1.Size.Width / 2, 30) }; pnlMode.Controls.Add(rbMode1); pnlMode.Controls.Add(rbMode2); _tabDec.Controls.Add(pnlMode); } else { pnlMode.Location = new Point(groupBox1.Location.X - 30, groupBox1.Location.Y + groupBox1.Size.Height - 17); rbMode1.Location = new Point(10, 15); rbMode2.Location = new Point(pnlMode.Size.Width / 2 + 25, rbMode1.Location.Y); } if (!packControlsWhenChangeMode.ContainsKey(pnlMode)) packControlsWhenChangeMode.Add(pnlMode, diff); else packControlsWhenChangeMode[pnlMode] = diff; var list = new Dictionary<int, string>(); downPosDec = pnlMode.Location.Y + pnlMode.Size.Height - 12; string decPathDef = Furniture.Helpers.LocalAccounts.decorPathResult; string decPathFileNameWithoutExt = ""; cm = new OleDbCommand("SELECT * FROM decors_conf WHERE id = " + newL.Number + " AND Visible = true", oleDb); rd = cm.ExecuteReader(); string strConfForComponent = ""; if (rd.Read()) strConfForComponent = rd["Configuration"].ToString(); rd.Close(); rd = cm.ExecuteReader(); if (newL.Component.IGetModelDoc().GetConfigurationCount() > 1 && strConfForComponent != "" && strConfForComponent != "all") { while (rd.Read()) { if ((string)rd["Configuration"] == newL.Component.ReferencedConfiguration) { decPathFileNameWithoutExt = rd["Group"].ToString(); break; } } } else if (rd.Read()) decPathFileNameWithoutExt = rd["Group"].ToString(); rd.Close(); _tabDec.Controls.Add(comboBoxDecor); if (decPathFileNameWithoutExt == "") { if (btnAllMod != null) btnAllMod.Visible = false; comboBoxDecor.Visible = false; comboBoxDecor.MouseCaptureChanged += ComboBoxDecorMouseCaptureChanged; comboBoxDecor.SelectedIndexChanged += ComboBoxDecorSelectedIndexChanged; comboBoxDecor.KeyDown += ComboBoxDecorKeyDown; continue; } string path; try { path = GetTextureFileFromRenderMaterial( newL.Component.IGetModelDoc()); } catch { path = ""; } var lastOleDb = oleDb; oleDb.Close(); bool isNotUniqDecors = false; if (path == "" && Properties.Settings.Default.SetDecorsFromFirstElement && Decors.MemoryForDecors != null && Decors.MemoryForDecors.ContainsKey(name)) { path = Decors.MemoryForDecors[name]; isNotUniqDecors = true; } if (!OpenOleDecors(out oleDb)) return false; int m = 0; string[] outVal; bool isDecor = false; string selectStr; if (GetDecorsPathArray(decPathFileNameWithoutExt, out outVal)) { string bigSelectStr = "SELECT * FROM decordef WHERE "; for (int l = 0; l < outVal.Count(); l++) { if (l == 0) bigSelectStr = bigSelectStr + outVal[l] + " = true"; else bigSelectStr = bigSelectStr + " OR " + outVal[l] + " = true"; } selectStr = bigSelectStr; } else selectStr = "SELECT * FROM decordef WHERE " + decPathFileNameWithoutExt + " = true"; cm = new OleDbCommand(selectStr, oleDb); rd = cm.ExecuteReader(); var strNameList = new List<string>(); while (rd.Read()) { strNameList.Add(rd["FILEJPG"].ToString()); } rd.Close(); oleDb.Close(); oleDb = lastOleDb; oleDb.Open(); strNameList.Sort((x, y) => x.CompareTo(y)); bool isDefaultDecInOurColumn = false; int maxLengthOfName = 2; foreach (var fileName in strNameList) { string oneOfPath = decPathDef + fileName + ".jpg"; if (File.Exists(oneOfPath)) { if (fileName.Length > maxLengthOfName) maxLengthOfName = fileName.Length; list.Add(m, oneOfPath); comboBoxDecor.Items.Add( Path.GetFileNameWithoutExtension(oneOfPath)); if (Path.GetFileNameWithoutExtension(path) == Path.GetFileNameWithoutExtension(oneOfPath))//(path == oneOfPath) { comboBoxDecor.SelectedIndex = m; if (!isNotUniqDecors) isDecor = true; else isDefaultDecInOurColumn = true; comboBoxDecor.MouseCaptureChanged += ComboBoxDecorMouseCaptureChanged; } m++; } else MessageBox.Show( @"Файл" + Environment.NewLine + oneOfPath + Environment.NewLine + @"не существует!", _mSwAddin.MyTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } if (maxLengthOfName > 2) { comboBoxDecor.Size = new Size(13 * maxLengthOfName, comboBoxDecor.Size.Width); if (btnAllMod != null) btnAllMod.Location = new Point( comboBoxDecor.Location.X + comboBoxDecor.Size.Width + 5, comboBoxDecor.Location.Y); if (btnFitDecor != null) btnFitDecor.Location = new Point( comboBoxDecor.Location.X + comboBoxDecor.Size.Width + 5 + 25, comboBoxDecor.Location.Y); } _tabDec.Controls.Add(lablDecor); _dictionary.Add(comboBoxDecor, list); // добавление нового элемента в общий список элементов подверженных изменению _commonList.Add(comboBoxDecor); if (isDecor) { if (Properties.Settings.Default.CashModeOn) { _objListChanged.Add(comboBoxDecor); } SetDecorPicture(comboBoxDecor, false, true);//Properties.Settings.Default.CashModeOn, true); } else { if (((isDefaultDecInOurColumn && isNotUniqDecors) || (Properties.Settings.Default.CashModeOn && _dictionary[comboBoxDecor].ContainsKey(comboBoxDecor.SelectedIndex))) && !_objListChanged.Contains(comboBoxDecor)) { AddDict(comboBoxDecor, _dictionary[comboBoxDecor][ comboBoxDecor.SelectedIndex]); _objListChanged.Add(comboBoxDecor); } } comboBoxDecor.SelectedIndexChanged += ComboBoxDecorSelectedIndexChanged; comboBoxDecor.KeyDown += ComboBoxDecorKeyDown; } } _dictHeightPage.Add(_tabDec, downPosDec); } } else { if (_tabDec != null) tabMain.Controls.Remove(_tabDec); } return true; }