ردود الذكاء الاصطناعي
سؤالك:
إجابة الشبكة العصبية:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace CSVFileReader
{
public partial class Form1 : Form
{
DataTable dataTable;
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "CSV Files|*.csv";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
dataTable = new DataTable();
string[] lines = File.ReadAllLines(openFileDialog.FileName);
if (lines.Length > 0)
{
string[] headers = lines[0].Split(',');
foreach (string header in headers)
{
dataTable.Columns.Add(header);
}
for (int i = 1; i < lines.Length; i++)
{
string[] data = lines[i].Split(',');
dataTable.Rows.Add(data);
}
dataGridView1.DataSource = dataTable;
}
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "CSV Files|*.csv";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
StringBuilder sb = new StringBuilder();
IEnumerable<string> columnNames = dataTable.Columns.Cast<DataColumn>().Select(column => column.ColumnName);
sb.AppendLine(string.Join(",", columnNames));
foreach (DataRow row in dataTable.Rows)
{
IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());
sb.AppendLine(string.Join(",", fields));
}
File.WriteAllText(saveFileDialog.FileName, sb.ToString());
}
}
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
printDocument1.Print();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics g = e.Graphics;
Font font = new Font("Arial", 12);
Brush brush = new SolidBrush(Color.Black);
float x = 10;
float y = 10;
foreach (DataRow row in dataTable.Rows)
{
foreach (DataColumn col in dataTable.Columns)
{
g.DrawString(row[col].ToString(), font, brush, x, y);
x += 100;
}
y += 20;
x = 10;
}
}
}
}
این کد یک برنامه Windows Form ساده است که از عناصر OpenFileDialog، SaveFileDialog، DataGridView، menuStrip، printDialog، printDocument برای کار با فایل های .csv استفاده می کند. این برنامه می تواند فایل های .csv را باز کند، آنها را در یک DataGridView نمایش دهد، امکان ذخیره تغییرات را فراهم کند، آمار مربوط به شاخص های انتخاب شده را نمایش دهد و این آمار را چاپ کند.
يرجى ملاحظة: قد لا تكون الإجابات المقدمة بواسطة الذكاء الاصطناعي دقيقة دائمًا. لا تعتمد عليها في القضايا الحساسة مثل الطب، القانون، الأمور المالية أو القضايا الأمنية. من الأفضل دائمًا الرجوع إلى المتخصصين المؤهلين عند اتخاذ القرارات المهمة. إدارة الموقع غير مسؤولة عن المحتوى الذي يتم إنتاجه تلقائيًا.