Sh

using System;

using System.Drawing;

using System.IO;

using System.Security.Cryptography;

using System.Text;

using System.Windows.Forms;


namespace SabzProteinERP

{

    public partial class MainForm : Form

    {

        TabControl tabs;

        TabPage tabDashboard, tabSales, tabInventory, tabReports, tabSettings, tabSecurity;


        TextBox txtKey, txtPlain, txtCipher, txtDecrypted;


        public MainForm()

        {

            InitializeComponent();

            BuildUI();

        }


        private void BuildUI()

        {

            this.Text = “سیستم حسابداری سبز پروتئین”;

            this.Size = new Size(950, 650);

            this.StartPosition = FormStartPosition.CenterScreen;

            this.RightToLeft = RightToLeft.Yes;

            this.RightToLeftLayout = true;


            tabs = new TabControl();

            tabs.Dock = DockStyle.Fill;


            tabDashboard = new TabPage(“داشبورد”);

            tabSales     = new TabPage(“فروش”);

            tabInventory = new TabPage(“انبار”);

            tabReports   = new TabPage(“گزارشات”);

            tabSettings  = new TabPage(“تنظیمات”);

            tabSecurity  = new TabPage(“امنیت (AES)”);


            tabs.TabPages.Add(tabDashboard);

            tabs.TabPages.Add(tabSales);

            tabs.TabPages.Add(tabInventory);

            tabs.TabPages.Add(tabReports);

            tabs.TabPages.Add(tabSettings);

            tabs.TabPages.Add(tabSecurity);


            this.Controls.Add(tabs);


            SetupDashboard();

            SetupSales();

            SetupInventory();

            SetupReports();

            SetupSettings();

            SetupSecurityAES();

        }


        private void SetupDashboard()

        {

            Label lbl = new Label();

            lbl.Text = “داشبورد حسابداری سبز پروتئین”;

            lbl.Font = new Font(“Tahoma”, 22, FontStyle.Bold);

            lbl.Location = new Point(20, 20);

            tabDashboard.Controls.Add(lbl);

        }


        private void SetupSales()

        {

            Label lbl = new Label();

            lbl.Text = “مدیریت فروش”;

            lbl.Font = new Font(“Tahoma”, 18, FontStyle.Bold);

            lbl.Location = new Point(20, 20);

            tabSales.Controls.Add(lbl);


            Button btnInvoice = new Button();

            btnInvoice.Text = “ثبت فاکتور فروش”;

            btnInvoice.Location = new Point(20, 80);

            btnInvoice.Size = new Size(200, 45);

            btnInvoice.Click += (s, e) => MessageBox.Show(“ثبت فاکتور فروش (نمونه)”);

            tabSales.Controls.Add(btnInvoice);

        }


        private void SetupInventory()

        {

            Label lbl = new Label();

            lbl.Text = “مدیریت انبار”;

            lbl.Font = new Font(“Tahoma”, 18, FontStyle.Bold);

            lbl.Location = new Point(20, 20);

            tabInventory.Controls.Add(lbl);


            Button btnStock = new Button();

            btnStock.Text = “مشاهده موجودی”;

            btnStock.Location = new Point(20, 80);

            btnStock.Size = new Size(200, 45);

            btnStock.Click += (s, e) => MessageBox.Show(“نمایش موجودی (نمونه)”);

            tabInventory.Controls.Add(btnStock);

        }


        private void SetupReports()

        {

            Label lbl = new Label();

            lbl.Text = “گزارشات سیستم”;

            lbl.Font = new Font(“Tahoma”, 18, FontStyle.Bold);

            lbl.Location = new Point(20, 20);

            tabReports.Controls.Add(lbl);


            Button btnReportSales = new Button();

            btnReportSales.Text = “گزارش فروش”;

            btnReportSales.Location = new Point(20, 80);

            btnReportSales.Size = new Size(200, 45);

            btnReportSales.Click += (s, e) => MessageBox.Show(“گزارش فروش اجرا شد”);

            tabReports.Controls.Add(btnReportSales);

        }


        private void SetupSettings()

        {

            Label lbl = new Label();

            lbl.Text = “تنظیمات سیستم”;

            lbl.Font = new Font(“Tahoma”, 18, FontStyle.Bold);

            lbl.Location = new Point(20, 20);

            tabSettings.Controls.Add(lbl);


            Button btnBackup = new Button();

            btnBackup.Text = “پشتیبان‌گیری”;

            btnBackup.Location = new Point(20, 80);

            btnBackup.Size = new Size(200, 45);

            btnBackup.Click += (s, e) => MessageBox.Show(“پشتیبان‌گیری انجام شد”);

            tabSettings.Controls.Add(btnBackup);

        }


        private void SetupSecurityAES()

        {

            Label lblTitle = new Label();

            lblTitle.Text = “رمزنگاری و رمزگشایی AES”;

            lblTitle.Font = new Font(“Tahoma”, 20, FontStyle.Bold);

            lblTitle.Location = new Point(20, 20);

            tabSecurity.Controls.Add(lblTitle);


            Label lblKey = new Label();

            lblKey.Text = “کلید:”;

            lblKey.Location = new Point(20, 80);

            tabSecurity.Controls.Add(lblKey);


            txtKey = new TextBox();

            txtKey.Location = new Point(120, 75);

            txtKey.Width = 400;

            tabSecurity.Controls.Add(txtKey);


            Label lblPlain = new Label();

            lblPlain.Text = “متن اصلی:”;

            lblPlain.Location = new Point(20, 130);

            tabSecurity.Controls.Add(lblPlain);


            txtPlain = new TextBox();

            txtPlain.Location = new Point(120, 125);

            txtPlain.Width = 400;

            tabSecurity.Controls.Add(txtPlain);


            Button btnEncrypt = new Button();

            btnEncrypt.Text = “رمزگذاری”;

            btnEncrypt.Location = new Point(20, 180);

            btnEncrypt.Size = new Size(120, 40);

            btnEncrypt.Click += BtnEncrypt_Click;

            tabSecurity.Controls.Add(btnEncrypt);


            Label lblCipher = new Label();

            lblCipher.Text = “متن رمزگذاری شده:”;

            lblCipher.Location = new Point(20, 240);

            tabSecurity.Controls.Add(lblCipher);


            txtCipher = new TextBox();

            txtCipher.Location = new Point(20, 270);

            txtCipher.Width = 550;

            txtCipher.ReadOnly = true;

            tabSecurity.Controls.Add(txtCipher);


            Button btnDecrypt = new Button();

            btnDecrypt.Text = “رمزگشایی”;

            btnDecrypt.Location = new Point(20, 320);

            btnDecrypt.Size = new Size(120, 40);

            btnDecrypt.Click += BtnDecrypt_Click;

            tabSecurity.Controls.Add(btnDecrypt);


            Label lblDecrypted = new Label();

            lblDecrypted.Text = “متن رمزگشایی شده:”;

            lblDecrypted.Location = new Point(20, 380);

            tabSecurity.Controls.Add(lblDecrypted);


            txtDecrypted = new TextBox();

            txtDecrypted.Location = new Point(20, 410);

            txtDecrypted.Width = 550;

            txtDecrypted.ReadOnly = true;

            tabSecurity.Controls.Add(txtDecrypted);

        }


        private void BtnEncrypt_Click(object sender, EventArgs e)

        {

            try

            {

                byte[] keyBytes = Encoding.UTF8.GetBytes(txtKey.Text);

                byte[] plainBytes = Encoding.UTF8.GetBytes(txtPlain.Text);


                using (Aes aes = Aes.Create())

                {

                    aes.Key = keyBytes;

                    aes.IV = new byte[16];


                    using (MemoryStream ms = new MemoryStream())

                    using (CryptoStream cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write))

                    {

                        cs.Write(plainBytes, 0, plainBytes.Length);

                        cs.FlushFinalBlock();

                        txtCipher.Text = Convert.ToBase64String(ms.ToArray());

                    }

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(“خطا در رمزگذاری: ” + ex.Message);

            }

        }


        private void BtnDecrypt_Click(object sender, EventArgs e)

        {

            try

            {

                byte[] keyBytes = Encoding.UTF8.GetBytes(txtKey.Text);

                byte[] cipherBytes = Convert.FromBase64String(txtCipher.Text);


                using (Aes aes = Aes.Create())

                {

                    aes.Key = keyBytes;

                    aes.IV = new byte[16];


                    using (MemoryStream ms = new MemoryStream(cipherBytes))

                    using (CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Read))

                    using (MemoryStream plainMs = new MemoryStream())

                    {

                        cs.CopyTo(plainMs);

                        txtDecrypted.Text = Encoding.UTF8.GetString(plainMs.ToArray());

                    }

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(“خطا در رمزگشایی: ” + ex.Message);

            }

        }

    }

}

Scroll to Top