Ejemplo n.º 1
0
        /// <summary>
        /// Kiểm tra trong một ngày sử dụng bao nhiêu lần
        /// </summary>
        public static int CheckDateTimesCurrent()
        {
            try
            {
                DataSet ds     = new DataSet();
                int     _times = 0;
                if (File.Exists(_pathDateTimesCurrent))
                {
                    ds.ReadXml(_pathDateTimesCurrent);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DateTime _date = Convert.ToDateTime(LibraryDev.Decrypt(_key, ds.Tables[0].Rows[0]["col1"] + string.Empty));
                        _times = Convert.ToInt32(LibraryDev.Decrypt(_key, ds.Tables[0].Rows[0]["col2"] + string.Empty));

                        //Nếu ngày hiện tại lớn hơn ngày log, cập nhật ngày mới
                        if (DateTime.Now.Date > _date)
                        {
                            _date  = DateTime.Now.Date;
                            _times = 1;
                        }
                        else
                        {
                            _times = _times + 1;
                        }

                        ds.Tables[0].Rows[0]["col1"] = LibraryDev.Encrypt(LibraryDev._key, _date + string.Empty);
                        ds.Tables[0].Rows[0]["col2"] = LibraryDev.Encrypt(LibraryDev._key, _times + string.Empty);
                        ds.Tables[0].WriteXml(_pathDateTimesCurrent);
                    }
                }
                else
                {
                    //Tạo xml mới ngày hiện tại
                    ds.Tables.Add("DSkinWin");
                    ds.Tables[0].Columns.Add("col1", typeof(String)); //Ngày
                    ds.Tables[0].Columns.Add("col2", typeof(String)); //Số lần mở

                    DataRow r = ds.Tables[0].NewRow();
                    r["col1"] = LibraryDev.Encrypt(LibraryDev._key, DateTime.Now.Date + string.Empty);
                    r["col2"] = LibraryDev.Encrypt(LibraryDev._key, "1");
                    _times    = 1;
                    ds.Tables[0].Rows.Add(r);

                    ds.Tables[0].WriteXml(_pathDateTimesCurrent);
                }

                return(_times);
            }
            catch (Exception)
            {
                return(0);
            }
        }
Ejemplo n.º 2
0
        public static void Active(DataSet ds, string path, string _address)
        {
            ds.Tables[0].Rows[0]["col6"] = LibraryDev.Encrypt(LibraryDev._key, "active");
            ds.Tables[0].WriteXml(path);
            System.IO.Directory.CreateDirectory(LibraryDev._pathFolderSuccess);

            ds.Tables[0].Columns.Add("col7", typeof(String));//Active
            ds.Tables[0].Columns.Add("col8", typeof(String));
            ds.Tables[0].Rows[0]["col7"] = _address;
            ds.Tables[0].Rows[0]["col8"] = LibraryDev.Encrypt(LibraryDev._key, _address);
            ds.Tables[0].WriteXml(LibraryDev._pathSuccess);
        }
Ejemplo n.º 3
0
        public static DataTable ActiveEvent()
        {
            DataTable dt = new DataTable();

            try
            {
                DataSet ds = new DataSet();
                ds.ReadXml(_pathSuccess);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    string   _permission     = LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col4"] + string.Empty);
                    string   _active         = LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col6"] + string.Empty);
                    string   _address        = ds.Tables[0].Rows[0]["col7"] + string.Empty;
                    string   _address_encypt = LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col8"] + string.Empty);
                    DateTime _dayEnd;

                    try
                    {
                        _dayEnd = Convert.ToDateTime(LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col10"] + string.Empty));
                    }
                    catch (Exception)
                    {
                        clsMessage.MessageExclamation("Vui lòng hiệu chỉnh thời gian theo định dạng dd/MM/yyyy.");
                        return(dt);
                    }

                    if (_dayEnd.Date < DateTime.Now.Date)
                    {
                        _strDeath = "Hết hạn sử dụng phần mềm. Vui lòng kích hoạt.";
                        File.Delete(_pathSuccess);
                        return(dt);
                    }

                    if (CheckDateTimesCurrent() > 10)
                    {
                        _strDeath = "Vui lòng hiệu chỉnh đúng thời gian hiện tại.";
                        return(dt);
                    }

                    if (_active == "active" && _address == _address_encypt)
                    {
                        _print  = _permission.Contains("print");
                        _update = _permission.Contains("update");
                        _excel  = _permission.Contains("excel");
                    }
                    //Lấy dữ liệu kích hoạt
                    dt.Columns.Add("Key", typeof(String));         //Key
                    dt.Columns.Add("Hospital", typeof(String));    //bệnh viện
                    dt.Columns.Add("Day", typeof(DateTime));       //ngày kích hoạt
                    dt.Columns.Add("DayEnd", typeof(DateTime));    //ngày hết hạn
                    dt.Columns.Add("Time", typeof(String));        //thời gian su dung
                    dt.Columns.Add("Permission", typeof(String));  //quyền
                    dt.Columns.Add("Key_Enctypt", typeof(String)); //Encrypt
                    dt.Columns.Add("Active", typeof(String));      //Active

                    DataRow r = dt.NewRow();
                    r["Key"]         = ds.Tables[0].Rows[0]["col1"] + string.Empty;
                    r["Hospital"]    = LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col2"] + string.Empty);
                    r["Time"]        = LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col3"] + string.Empty);
                    r["Permission"]  = LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col4"] + string.Empty);
                    r["Key_Enctypt"] = ds.Tables[0].Rows[0]["col5"] + string.Empty;;
                    r["Active"]      = LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col6"] + string.Empty);
                    r["Day"]         = Convert.ToDateTime(LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col9"] + string.Empty));
                    r["DayEnd"]      = Convert.ToDateTime(LibraryDev.Decrypt(LibraryDev._key, ds.Tables[0].Rows[0]["col10"] + string.Empty));
                    dt.Rows.Add(r);
                }

                return(dt);
            }
            catch (Exception)
            {
                return(dt);
            }
        }