Example #1
0
        /// <summary>
        /// Выгрузка данных в Excel;
        /// </summary>        
        /// <returns></returns> 
        public void createXLS()
        {
            ExcelClass TZExcel = new ExcelClass();

            HashCode.HashCode.CheckFileByHash("техническое задание.xlt");

            if (System.IO.File.Exists(Program.PathString + "\\техническое задание.xlt"))
            {

                try
                {
                    TZExcel.OpenDocument(Program.PathString + "\\техническое задание.xlt");
                    TZExcel.Visible = false;

                    if ((BMPIsLoad == 1) || (BMPIsLoad == 3))
                    {
                        if (this.SCETCH1.Image != null)
                        {
                            using (TemporaryFile tempFile = new TemporaryFile())
                            {
                                this.SCETCH1.Image.Save(tempFile.FilePath.ToString(), System.Drawing.Imaging.ImageFormat.Bmp);

                                TZExcel.SelectCells(this.SCETCH1.Name, Type.Missing);

                                TZExcel.WritePictureToCell(tempFile.FilePath.ToString());

                            }

                        }

                    }
                    else if ((BMPIsLoad == 0) || (BMPIsLoad == 2))
                    {

                        if (this.SCETCH1.Image != null)
                        {
                            TZExcel.SelectCells(this.SCETCH1.Name, Type.Missing);

                            TZExcel.WritePictureToCell(SQLOracle.LoadImageToTemp("Select SCETCH1 FROM USP_TZ_DATA WHERE ID_DOC = '" + number + "'"));

                        }
                    }

                    if ((BMPIsLoad == 2) || (BMPIsLoad == 3))
                    {
                        if (this.SCETCH2.Image != null)
                        {
                            using (TemporaryFile tempFile = new TemporaryFile())
                            {
                                this.SCETCH2.Image.Save(tempFile.FilePath.ToString(), System.Drawing.Imaging.ImageFormat.Bmp);

                                TZExcel.SelectCells(this.SCETCH2.Name, Type.Missing);

                                TZExcel.WritePictureToCell(tempFile.FilePath.ToString());

                            }

                        }

                    }
                    else if ((BMPIsLoad == 0) || (BMPIsLoad == 1))
                    {

                        if (this.SCETCH2.Image != null)
                        {
                            TZExcel.SelectCells(this.SCETCH2.Name, Type.Missing);

                            TZExcel.WritePictureToCell(SQLOracle.LoadImageToTemp("Select SCETCH2 FROM USP_TZ_DATA WHERE ID_DOC = '" + number + "'"));

                        }
                    }

                    for (int i = 0; i < this.tabPage1.Controls.Count; i++)
                    {

                        if (this.tabPage1.Controls[i].Controls.Count == 0)
                        {

                            if ((this.tabPage1.Controls[i].GetType() == typeof(DateTimePicker)) || (this.tabPage1.Controls[i].GetType() == typeof(TextBox)) || (this.tabPage1.Controls[i].GetType() == typeof(ComboBox)))
                            {
                                TZExcel.SelectCells(this.tabPage1.Controls[i].Name, Type.Missing);
                                TZExcel.WriteDataToCell(this.tabPage1.Controls[i].Text.ToString());
                            }

                        }
                        else if (this.tabPage1.Controls[i].Controls.Count > 0)
                        {
                            ExcelExport(this.tabPage1.Controls[i], ref TZExcel);
                        }
                    }

                    for (int i = 0; i < this.tabPage2.Controls.Count; i++)
                    {
                        if (this.tabPage2.Controls[i].Controls.Count == 0)
                        {

                            if ((this.tabPage2.Controls[i].GetType() == typeof(DateTimePicker)) || (this.tabPage2.Controls[i].GetType() == typeof(TextBox)) || (this.tabPage2.Controls[i].GetType() == typeof(ComboBox)))
                            {
                                TZExcel.SelectCells(this.tabPage2.Controls[i].Name, Type.Missing);
                                TZExcel.WriteDataToCell(this.tabPage2.Controls[i].Text.ToString());
                            }

                        }
                        else if (this.tabPage2.Controls[i].Controls.Count > 0)
                        {
                            ExcelExport(this.tabPage2.Controls[i], ref TZExcel);
                        }
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");

                }
                finally
                {
                    TZExcel.Visible = true;
                    TZExcel.Dispose();
                }
            }
        }