Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            DataTable dt = GetDgvToTable(dataGridView1);

            dt.DefaultView.Sort = "index";
            string csvFileName = System.IO.Path.GetTempFileName();

            CSVFileHelper.SaveCSV(dt, csvFileName);
            if (File.Exists("Server.dat.bak"))
            {
                File.Delete("Server.dat.bak");
            }
            File.Move("Server.dat", "Server.dat.bak");
            DESFileClass.EncryptFile(csvFileName, "Server.dat", "c2Soecqg9f5GXCflI7c6wBNq4fAXiZcS");
            File.Delete(csvFileName);
            this.Close();
        }
Ejemplo n.º 2
0
        public static void LoadGrid(DataGridView dataGridView, string group)
        {
            //if (File.Exists("Server.csv"))
            //{
            //    DESFileClass.EncryptFile("Server.csv", "Server.dat", "c2Soecqg9f5GXCflI7c6wBNq4fAXiZcS");
            //    //File.Delete("Server.csv");
            //}
            if (File.Exists("Server.dat"))
            {
                string csvFileName = System.IO.Path.GetTempFileName();
                DESFileClass.DecryptFile("Server.dat", csvFileName, "c2Soecqg9f5GXCflI7c6wBNq4fAXiZcS");
                dt = CSVFileHelper.ReadCSV(csvFileName);
                File.Delete(csvFileName);
                if (!dt.Columns.Contains("OrderIndex"))
                {
                    dt.Columns.Add("OrderIndex", typeof(Int32));
                }
                foreach (DataRow row in dt.Rows)
                {
                    int index = 0;
                    int.TryParse(row["Index"].ToString(), out index);
                    row["OrderIndex"] = index;
                }

                dt.DefaultView.Sort = "OrderIndex ASC";
                if (string.Compare(group, "All", false) != 0)
                {
                    dt.DefaultView.RowFilter = string.Format("Group = '{0}'", group);
                    dataGridView.DataSource  = dt.DefaultView;
                }
                else
                {
                    dataGridView.DataSource = dt.DefaultView;
                }
            }
        }