visual c# encrypt decrypt text file

First create class : encrypt_decrypt.cs
inside:

using System;
using System.Security.Cryptography;
using System.Text;

namespace RestWebinarSample
{

    class Encryptor
    {
        public static string IV = "1a1a1a1a1a1a1a1a";
        public static string Key = "1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a13";

        public static string Encrypt(string decrypted)
        {
            byte[] textbytes = ASCIIEncoding.ASCII.GetBytes(decrypted);
            AesCryptoServiceProvider endec = new AesCryptoServiceProvider();
            endec.BlockSize = 128;
            endec.KeySize = 256;
            endec.IV = ASCIIEncoding.ASCII.GetBytes(IV);
            endec.Key = ASCIIEncoding.ASCII.GetBytes(Key);
            endec.Padding = PaddingMode.PKCS7;
            endec.Mode = CipherMode.CBC;
            ICryptoTransform icrypt = endec.CreateEncryptor(endec.Key, endec.IV);
            byte[] enc = icrypt.TransformFinalBlock(textbytes, 0, textbytes.Length);
            icrypt.Dispose();
            return Convert.ToBase64String(enc);
        }

        public static string Decrypted(string encrypted)
        {
            byte[] textbytes = Convert.FromBase64String(encrypted);
            AesCryptoServiceProvider endec = new AesCryptoServiceProvider();
            endec.BlockSize = 128;
            endec.KeySize = 256;
            endec.IV = ASCIIEncoding.ASCII.GetBytes(IV);
            endec.Key = ASCIIEncoding.ASCII.GetBytes(Key);
            endec.Padding = PaddingMode.PKCS7;
            endec.Mode = CipherMode.CBC;
            ICryptoTransform icrypt = endec.CreateDecryptor(endec.Key, endec.IV);
            byte[] enc = icrypt.TransformFinalBlock(textbytes, 0, textbytes.Length);
            icrypt.Dispose();
            return System.Text.ASCIIEncoding.ASCII.GetString(enc);
        }
    }
}

then 2 buttons encrypt and decrypt

private void encrypt_Click(object sender, EventArgs e)
{

    Directory.CreateDirectory("data\\");

    var sw = new StreamWriter("data\\" + "data.ls");

    string enctxt = Encryptor.Encrypt("willbeencrypted");

    sw.WriteLine(enctxt);

    sw.Close();
}

private void decrypt_Click(object sender, EventArgs e)
{
    StreamReader sr = new StreamReader(Application.StartupPath + "\\data\\" + "data.ls");
    string line = sr.ReadLine();

    MessageBox.Show(Encryptor.Decrypted(Convert.ToString(line)));
}

EXCEPTION WRITE TO LOG

public void WRITELOG(string ERROR, Exception E, int TYPE)
 {
     try
     {
         string directory = AppDomain.CurrentDomain.BaseDirectory + "logs\\";
         Directory.CreateDirectory(directory);
         string EXTENTION = "";
         if (TYPE == 0)
             EXTENTION = " - ERRORS";
         else if (TYPE == 1)
             EXTENTION = " - STATUS";
         else if (TYPE == 2)
             EXTENTION = " - EXPS";
         string path = directory + DateTime.Now.ToString("yyyy.MM.dd" + EXTENTION) + ".txt";
         if (!File.Exists(path))
             File.Create(path).Close();
         else
         {
             if (TYPE > 0 || E == null)
                 File.AppendAllText(path, Environment.NewLine);
             else
                 File.AppendAllText(path, Environment.NewLine + Environment.NewLine +
                     Environment.NewLine + Environment.NewLine + Environment.NewLine);
         }
         File.AppendAllText(path, DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"+ " : " + ERROR +
             Environment.NewLine + (E != null ? " ----- HATA : ----- " + E.ToString() : ""));
     }
     catch { }
 }

C# WEB SERVICE SORGULAMASI

using System;
using System.Windows.Forms;

namespace BMSLicenseKontrol
{
    public partial class Form1 : DevExpress.XtraEditors.XtraForm
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {



        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            ServiceBMSLicense.LicenseServiceSoapClient SBMSLicense = new ServiceBMSLicense.LicenseServiceSoapClient();
            SBMSLicense.LicenseQuery(lisans.Text, GetStatikIp.GetIPAddress());
            MessageBox.Show(SBMSLicense.LicenseQuery(lisans.Text, GetStatikIp.GetIPAddress()).Rows[0][6].ToString()); //0rıncı row 6ıncı column MSGBOXDA GOSTER
            gridControl1.DataSource = SBMSLicense.LicenseQuery(lisans.Text, GetStatikIp.GetIPAddress());//ISDERSEN DIREK DONUSU GRIDVIEWDE GOSTER


        }
    }
}

c# CLASS GET STATIK IP

using System;
using System.IO;
using System.Net;

namespace BMSLicenseKontrol
{
    class GetStatikIp
    {
        public static string GetIPAddress()

        {

            String address = "";

            WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");

            using (WebResponse response = request.GetResponse())

            using (StreamReader stream = new StreamReader(response.GetResponseStream()))

            {

                address = stream.ReadToEnd();

            }

            int first = address.IndexOf("Address: "+ 9;

            int last = address.LastIndexOf("");

            address = address.Substring(first, last - first);

            return address;

        }
    }
}

Aspxgridview selected ve toplu işlemleri

--aşağıdaki kod bütün seçili rowlara işlem yapar
            List SelectedUsers = grid.GetSelectedFieldValues(new string[] { "ID", "TUTAR" });
            foreach (object user in SelectedUsers)
            {
                IList items = user as IList;
                if (items == null) return;
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CarringtonWebConnectionString1"].ConnectionString);
                con.Open();
                SqlCommand cmd = new SqlCommand("update ACIKHESAP set ODEME_DURUMU=1, ODENEN_TUTAR=" + items[1].ToString() + " where ID=" + items[0].ToString(), con);
                cmd.ExecuteNonQuery();
            }




---aşağıdaki kod seçili seçili deil farketmez hepsine işlem yapar
            for (int i = 0; i < grid.VisibleRowCount; i++)
            {
                var items = grid.GetRowValues(i, new string[] { "ID", "TUTAR" }) as object[];
                // ASPxListBox1.Items.Add(rowValues[0].ToString());
                //you can add these key in a list here

                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CarringtonWebConnectionString1"].ConnectionString);
                con.Open();
                SqlCommand cmd = new SqlCommand("update ACIKHESAP set ODEME_DURUMU=2, ODENEN_TUTAR=" + items[1].ToString() + " where ID=" + items[0].ToString(), con);
                cmd.ExecuteNonQuery();

visual studio asp datasource olarak xmli kullanmak

new empty web project
insert new web page adı index.aspx
insert new item xml
içine :

  <Student
    StudentID=”1″
    FirstName=”A”
    LastName=”AA”
    TotalMarks=”100″>
 
  <Student
    StudentID=”2″
    FirstName=”B”
    LastName=”BB”
    TotalMarks=”200″>
 
  <Student
    StudentID=”3″
    FirstName=”C”
    LastName=”CC”
    TotalMarks=”500″>
 
  <Student
    StudentID=”4″
    FirstName=”D”
    LastName=”DD”
    TotalMarks=”700″>
 

ve gridview at ve datasource xmlden xml dosyasını seç

ASPXGRIDVIEW İşlemleri

Gridviewde seçili satırın bilgisini alabilme :
        protected void ASPxGridView1_SelectionChanged(object sender, EventArgs e)
        {
            var products = ASPxGridView1.GetSelectedFieldValues(“NAME”);
            Label1.Text = products[0].ToString();
        }

Gridviewin Sonuna İşlemler Seç eklemek için source da sona ekle
           
               
           
       
   

Gridview devexpress 7.2 sonrası için gecerli export Gridview
un altina ekle
 

un ustune ekle
        <Toolbars>
            <dx:GridViewToolbar EnableAdaptivity=“true”>
                <Items>
                    <dx:GridViewToolbarItem Command=“ExportToPdf” />
                    <dx:GridViewToolbarItem Command=“ExportToXls” />
                    <dx:GridViewToolbarItem Command=“ExportToXlsx” />
                    <dx:GridViewToolbarItem Command=“ExportToDocx” />
                    <dx:GridViewToolbarItem Command=“ExportToRtf” />
                    <dx:GridViewToolbarItem Command=“ExportToCsv” />
                </Items>
            </dx:GridViewToolbar>
        </Toolbars>


Gridview grup category combobox ve baglantisi 
birinci sqldatasource_musteriler yarat ve bunu aspxgridviewe bind
Ikinci datasource sqldatasource_musterigruplari  yarat  bu bir yere bind olmayacak

Sqlden iki tablo yarat birinin adi musteri(id,adi,grupid) olsun
digeride musteri_grup (id,grup_adi) olsun

aspxgridview designerda columnsa tikla combobox column ekle captionunu grup yap, Fieldname grupid sec, sag tabda comboboxpropertiesde datasourceid musteri_gruplarini sec text field grup_adi , valuefield=id 


Gridview Horizontal scrollbar 

   

       

       

       

Datasource eklemede hata alırsan sol taraftan server explorerden modify deyip save passwordu seç


Gridview  Required zorunlu alan ayari
Designerda ac ve columnsdan zorunlu alana tıkla ve sağda textboxpropertiesden en aşağıda validation settingste requiredi true yap

Master Detail Grid
ONCE 2 TANE SQLDATASOURCE VE 2 TANE ASPXGRIDVIEW YARAT BIRI MUSTERILER DIGERI MUSTERI HAREKETLER
MUSTERILERI NORMAL TABLODAN AL ASPXGRIDVIEW MUSTERILERIN SETTINGS DETAILDE DETAILROWU TRUE YAP,

MUSTERI HAREKETLERINIDE AL WHERE KISMINA TIKLA COLUMN MUSTERI_ID OPERATOR ” = ”  , SOURCE SESSION , SESSION FIELD = MUSTERI_ID

VE DAHA SONRA KODA EKLE
        protected void ASPxGridViewmusterihareketler_BeforePerformDataSelect(object sender, EventArgs e)
        {
            Session[“MUSTERI_ID”] = (sender as ASPxGridView).GetMasterRowKeyValue();
        }

SON OLARAKDA ASPXGRIDVIEWMUSTERILERE TIKLA EDITTEMPLATE VE DETAILROWU SEC VE ASPXGRIDMUSTERIHAREKETLERINI ICINE SURUKLE VE END TEMPLATE YAP


Gridviewda son kolumun genişliğini max yapmak
       
           
           
           
               
           
            <dx:GridViewDataTextColumn FieldName="ADI" VisibleIndex="2" Width=”100%”>
           
       


gridview detay masterda detay width sorunu once masterin altina ekle :
    <dx:ASPxGridView Width=”100%” 
       
       

sonra masterin son colomunun widthini %100 yap
 

sonra detaya ekle
   <dx:ASPxGridView2 Width=”100%” 
       
       

Devexpress gridview Dinamik Satır Ekleme (sil butonuyla)

Bir tane devexpress gridview yarat ve kodlar aşağıda

 

 

 
using DevExpress.XtraEditors.Repository;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TIPEXE
{
    public partial class Form1 : Form
    {
        public class BILGILER
        {

            public BILGILER()
            {
            }

            public string BARKOD { get; set; }
            public string ADI { get; set; }
            public string SİL { get; set; }

        }
        public BindingList _Grid_data;
        public Form1()
        {
            InitializeComponent();

        }
        private void button3_Click(object sender, EventArgs e)
        {
            _Grid_data.Add(new BILGILER()
            {
                BARKOD = "asd",
                ADI = "assaas"
            });
            RepositoryItemButtonEdit SILDUGMESI = new RepositoryItemButtonEdit();
            SILDUGMESI.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
            SILDUGMESI.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
            SILDUGMESI.Buttons[0].Image = Bitmap.FromFile("resimler\\simgeler\\SIL.png");
            SILDUGMESI.Buttons[0].Caption = "SİL";
            SILDUGMESI.ButtonClick += SILDUGMESI_ButtonClick;
            gridControl1.RepositoryItems.Add(SILDUGMESI);
            gridView1.Columns["SİL"].ColumnEdit = SILDUGMESI;
        }
        private void SILDUGMESI_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            gridView1.DeleteSelectedRows();
        }
        private void bunifuFlatButton3_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            form2.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _Grid_data = new BindingList();
            gridControl1.DataSource = _Grid_data;
            gridView1.PopulateColumns();
            //bunifuFlatButton4.BackColor = Color.Teal;
            //bunifuFlatButton4.Activecolor = Color.Teal;
        }
    }
}