예제 #1
0
 private void FrmExec_SaveFile(string s)
 {
     try
     {
         frmSqlEdit f = new frmSqlEdit(null);
         f.sql = s;
         DialogService.ShowDialog(f);
     }
     catch (Exception ex)
     {
         Logger.Error(s, ex);
     }
 }
예제 #2
0
        private void ribbon_connectSetingsButtonClick()
        {
            if (cnt == null)
            {
                ConnectToSql();
            }
            frmDbConnect f = new frmDbConnect(cnt, cnsb);

            DialogService.ShowDialog(f);

            if (f.DialogResult == DialogResult.OK)
            {
                cnt  = f.cnt;
                cnsb = f.cnsb;
                ConnectToSql();
            }
            UpdateICConteiner();
            f.Dispose();
        }
예제 #3
0
 public static void EditObjectUniversal(Excel.Worksheet _wSheet, SqlConnection _cnt, string _ic, bool _SaveAsSql, bool _Check)
 {
     if (!Instance.SqlInfoEventHandled)
     {
         Instance.SqlInfoEventHandled = true;
         _cnt.InfoMessage            += _cnt_InfoMessage;
     }
     Instance.StopExecute = false;
     Instance.cnt         = _cnt;
     Instance.wSheet      = _wSheet;
     Instance.query       = _ic;
     Instance.SaveAsSql   = _SaveAsSql;
     Instance.Check       = _Check;
     Instance.bar.Style   = ProgressBarStyle.Continuous;
     Instance.t           = new Thread(Instance.EditObjectUniversal);
     Instance.t.Name      = "SQL Thread";
     Instance.t.Start();
     DialogService.ShowDialog(Instance);
 }
예제 #4
0
 private void ribbon_btnSettingCliked()
 {
     DialogService.ShowDialog(new frmSelectTech(ICList));
     UpdateICConteiner();
 }
예제 #5
0
        private void GetObjectUniversal()
        {
            SqlDataReader reader = null;

            try
            {
                if (SaveAsSql)
                {
                    Stream         myStream;
                    SaveFileDialog saveFileDialog1 = new SaveFileDialog();

                    saveFileDialog1.Filter           = "txt files (*.sql)|*.sql|All files (*.*)|*.*";
                    saveFileDialog1.FilterIndex      = 1;
                    saveFileDialog1.RestoreDirectory = true;

                    if (DialogService.ShowDialog(saveFileDialog1) == DialogResult.OK)
                    {
                        if ((myStream = saveFileDialog1.OpenFile()) != null)
                        {
                            byte[] bytes = Encoding.UTF8.GetBytes(query);
                            myStream.Write(bytes, 0, bytes.Length);
                            myStream.Close();
                        }
                    }
                }
                else
                {
                    SqlCommand command = new SqlCommand(query, cnt);
                    reader = command.ExecuteReader();

                    // Делаем шапку
                    //var wSheet = Application.ActiveWorkbook.ActiveSheet;

                    int             lLastCol = wSheet.Cells[1, wSheet.Columns.Count].End(Excel.XlDirection.xlToLeft).Column; // находим последнюю колонку
                    int             lLastRow = wSheet.Cells[wSheet.Rows.Count, 1].End(Excel.XlDirection.xlUp).Row;           // Последнюю строку
                    Excel.Worksheet s        = wSheet;
                    s.Range[s.Cells[1, 1], s.Cells[lLastRow, lLastCol]].Clear();
                    object[] arr = new object[reader.FieldCount];
                    //reader.g
                    for (int j = 0, c = reader.FieldCount; j < c; j++)
                    {
                        arr[j] = reader.GetName(j);
                    }

                    wSheet.Range[wSheet.Cells[1, 1], wSheet.Cells[1, reader.FieldCount]].Value = arr;


                    int i = 2;
                    while (reader.Read())
                    {
                        //this.BeginInvoke(UpdateProgressbar, new object[] { 2, lLastRow, i });
                        //Thread.Sleep(100);
                        if (this.StopExecute)
                        {
                            reader?.Close();
                            this.BeginInvoke(UserEndExecuteEvent);
                            return;
                        }
                        ;
                        try
                        {
                            for (int j = 0, c = reader.FieldCount; j < c; j++)
                            {
                                try
                                {
                                    //var res = reader[reader.GetName(j)];
                                    var res = reader[reader.GetName(j)];
                                    if (res.GetType() == typeof(byte[]))
                                    {
                                        arr[j] = "'0x" + BitConverter.ToString((byte[])res).Replace("-", "");
                                    }
                                    else if (res.GetType() == typeof(System.DBNull))
                                    {
                                        arr[j] = "'null";
                                    }
                                    else
                                    {
                                        arr[j] = "'" + res.ToString();
                                    }
                                }
                                catch { }
                            }
                            wSheet.Range[wSheet.Cells[i, 1], wSheet.Cells[i, reader.FieldCount]].Value = arr;
                        }
                        catch (Exception ex)
                        {
                            this.BeginInvoke(ErrorInThread, new object[] { ex, "GetObjectUniversal" });
                        }
                        i++;
                    }
                    reader.Close();
                    //wSheet.Columns.AutoFit();
                    wSheet.Columns.WrapText = false;
                    //wSheet.Columns.Font.Name = "Lucida Console";
                    //l.WriteDebug("Что то прочитали");
                }
            }
            catch (Exception exc)
            {
                this.BeginInvoke(ErrorInThread, new object[] { exc, "GetObjectUniversal" });
                this.BeginInvoke(DebugInThread, new object[] { query });
            }
            reader?.Close();
            this.BeginInvoke(EndExecuteEvent);
        }