Beispiel #1
0
        private void SaveFile()
        {
            switch (EcoLanguage.getLang())
            {
            case 0:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en");
                break;

            case 1:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("de");
                break;

            case 2:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("es");
                break;

            case 3:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("fr");
                break;

            case 4:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("it");
                break;

            case 5:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("ja");
                break;

            case 6:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("ko");
                break;

            case 7:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("pt");
                break;

            case 8:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("ru");
                break;

            case 9:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("zh-CHS");
                break;

            case 10:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("zh-CHT");
                break;

            default:
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en");
                break;
            }
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "Execl files (*.xls)|*.xls";
            saveFileDialog.FilterIndex      = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt     = true;
            saveFileDialog.Title            = "Excel";
            if (this.checkBox_SaveAll.Checked)
            {
                LogSysLog.SaveRange = 1;
            }
            else
            {
                LogSysLog.SaveRange = 0;
            }
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                System.IO.Stream stream;
                try
                {
                    stream = saveFileDialog.OpenFile();
                }
                catch (System.Exception)
                {
                    this.SaveSuccess = 2;
                    return;
                }
                System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(stream, System.Text.Encoding.Unicode);
                string text = "";
                try
                {
                    for (int i = 0; i < this.dataGridViewLogs.Columns.Count; i++)
                    {
                        string name = this.dataGridViewLogs.Columns[i].Name;
                        if (text.Length == 0)
                        {
                            text += name;
                        }
                        else
                        {
                            text = text + "\t" + name;
                        }
                    }
                    streamWriter.WriteLine(text);
                    if (LogSysLog.SaveRange == 0)
                    {
                        for (int j = 0; j < this.dataGridViewLogs.Rows.Count; j++)
                        {
                            string text2 = "";
                            for (int k = 0; k < this.dataGridViewLogs.Columns.Count; k++)
                            {
                                if (k > 0)
                                {
                                    text2 += "\t";
                                }
                                if (this.dataGridViewLogs.Rows[j].Cells[k].Value == null)
                                {
                                    text2 = (text2 ?? "");
                                }
                                else
                                {
                                    text2 += this.dataGridViewLogs.Rows[j].Cells[k].Value.ToString().Trim();
                                }
                            }
                            streamWriter.WriteLine(text2);
                        }
                    }
                    else
                    {
                        DataTable allLogs = LogAPI.getAllLogs();
                        for (int l = 0; l < allLogs.Rows.Count; l++)
                        {
                            string text3 = "";
                            for (int m = 0; m < allLogs.Columns.Count; m++)
                            {
                                if (m > 0)
                                {
                                    text3 += "\t";
                                }
                                if (allLogs.Rows[l][m].ToString() == null)
                                {
                                    text3 = (text3 ?? "");
                                }
                                else
                                {
                                    text3 += allLogs.Rows[l][m].ToString().Trim();
                                }
                            }
                            streamWriter.WriteLine(text3);
                        }
                    }
                    streamWriter.Close();
                    stream.Close();
                    this.SaveSuccess = 1;
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    streamWriter.Close();
                    stream.Close();
                }
            }
        }