Example #1
0
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     Application.DoEvents();
     try
     {
         BaseFunction.GetConfig();
         delayLoadTimer.Interval = 80;
         delayLoadTimer.Enabled  = true;
         bsiSetting.Caption      = @"当前系统计算的板宽为:【" + BaseFunction.Area + @"mm】";
         barStaticItem2.Caption  = CheckRegInfo.GetOAuthInfo();
         if (!File.Exists(imageConfig))
         {
             XmlHelper.CreateImageXml(imageConfig);
             PiEncryptHelper.EncFile(imageConfig);
         }
         if (!PiEncryptHelper.IsFileEnc(imageConfig, ref nKeyID))
         {
             MessageBox.Show(@"系统文件错误!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
     }
     catch (Exception)
     {
         Cursor.Current = Cursors.Default;
     }
 }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.RestoreDirectory = true;
            ofd.FilterIndex      = 1;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = ofd.FileName;
            }

            int x = 0;

            if (PiEncryptHelper.IsFileEnc(textBox1.Text, ref x))
            {
                label1.Text = string.Format(@"文件以加密,加密标识为:{0}", x);
            }
        }
Example #3
0
        private void LoadData()
        {
            if (!File.Exists(imageConfig))
            {
                XmlHelper.CreateImageXml(imageConfig);
                PiEncryptHelper.EncFile(imageConfig);
            }
            if (PiEncryptHelper.IsFileEnc(imageConfig, ref nKeyID))
            {
                PiEncryptHelper.DecFile(imageConfig);
            }
            MaterialsNode mNode = new MaterialsNode();

            mNode.RNode = "Materials";
            List <MaterialsData> list = XmlHelper.GetXmlData(imageConfig, mNode);

            PiEncryptHelper.EncFile(imageConfig);
            BindDgvMain(list);
        }
Example #4
0
        protected override void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                int index = gvMain.FocusedRowHandle;
                if (index <= -1)
                {
                    MessageBox.Show(@"请选择需要删除的型材!", @"错误", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
                if (DialogResult.Yes ==
                    MessageBox.Show(@"是否删除选中的型材数据?", @"提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    MaterialsNode mNode = new MaterialsNode();
                    mNode.RNode         = "Materials";
                    mNode.PNodeAttr     = "key";
                    mNode.PNodeNewValue = this.gvMain.GetFocusedRowCellValue("Area").ToString();
                    string filename = this.gvMain.GetFocusedRowCellValue("Path").ToString();

                    this.gvMain.DeleteRow(index);
                    if (PiEncryptHelper.IsFileEnc(imageConfig, ref nKeyID))
                    {
                        PiEncryptHelper.DecFile(imageConfig);
                    }
                    XmlHelper.Delete(imageConfig, mNode);
                    PiEncryptHelper.EncFile(imageConfig);
                    if (File.Exists(filename))
                    {
                        File.SetAttributes(filename, FileAttributes.Normal);

                        File.Delete(filename);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, @"错误", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Example #5
0
        private void LoadProfileInfo()
        {
            if (!File.Exists(imageConfig))
            {
                XmlHelper.CreateImageXml(imageConfig);
                PiEncryptHelper.EncFile(imageConfig);
            }
            if (PiEncryptHelper.IsFileEnc(imageConfig, ref nKeyID))
            {
                PiEncryptHelper.DecFile(imageConfig);
            }
            MaterialsNode mNode = new MaterialsNode();

            mNode.RNode = "Materials";
            list        = XmlHelper.GetXmlData(imageConfig, mNode);

            PiEncryptHelper.EncFile(imageConfig);

            gcMain.DataSource = null;


            gcMain.DataSource = list;
        }
Example #6
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            AsyncWaitForm.Instance.AsyncShow("开始导入型材", "正在导入型材",
                                             delegate(AsyncWaitForm exfrm)
            {
                exfrm.SetMsgAndProgress("导入型材", 10);
                if (!File.Exists(imageConfig))
                {
                    XmlHelper.CreateImageXml(imageConfig);
                    PiEncryptHelper.EncFile(imageConfig);
                }

                if (PiEncryptHelper.IsFileEnc(imageConfig, ref nKeyID))
                {
                    ;
                }
                {
                    PiEncryptHelper.DecFile(imageConfig);
                }
                OpenFileDialog ofd = new OpenFileDialog();
                //ofd.Filter = @"图像文件(*.jpg;*.jpg;*.jpeg;*.gif;*.png)|*.jpg;*.jpeg;*.gif;*.png";
                ofd.Filter           = @"图像文件(*.png)|*.png";
                ofd.Multiselect      = true;
                ofd.Title            = @"请选择文件";
                ofd.RestoreDirectory = true;

                MaterialsNode mNode = new MaterialsNode();
                mNode.CNode         = new string[4];
                mNode.CNodeValue    = new string[4];
                string path         = AppDomain.CurrentDomain.BaseDirectory + "MaterialsImg\\" + lueType.Text + "\\";

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }



                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    foreach (var item in ofd.SafeFileNames)
                    {
                        string filename = path + item.ToLower();
                        if (File.Exists(filename))
                        {
                            MessageBox.Show(string.Format("【{0}】型材已经存在!", item.ToLower().Replace(".png", "")));
                            return;
                        }
                    }


                    for (int i = 0; i < ofd.FileNames.Length; i++)
                    {
                        string filePath = path + ofd.SafeFileNames[i].ToLower();
                        string truePath = "MaterialsImg\\" + lueType.Text + "\\" + ofd.SafeFileNames[i].ToLower();
                        if (File.Exists(filePath))
                        {
                            MessageBox.Show(string.Format("【{0}】型材已经存在!", ofd.SafeFileNames[i].ToLower().Replace(".png", "")));
                            return;
                        }
                        if (File.Exists(filePath))
                        {
                            XmlHelper.Update(imageConfig, "Image//Key_" + ofd.SafeFileNames[i].ToLower().Replace(".png", ""), "Path", filePath);
                        }
                        else
                        {
                            mNode.RNode         = "Materials";
                            mNode.PNode         = "Image";
                            mNode.PNodeAttr     = "key";
                            mNode.PNodeValue    = ofd.SafeFileNames[i].ToLower().Replace(".png", "");
                            mNode.CNode[0]      = "Type";
                            mNode.CNodeValue[0] = lueType.Text;
                            mNode.CNode[1]      = "Value";
                            mNode.CNodeValue[1] = ofd.SafeFileNames[i].ToLower().Replace(".png", "");
                            mNode.CNode[2]      = "Path";
                            mNode.CNodeValue[2] = truePath;
                            mNode.CNode[3]      = "Depth";
                            mNode.CNodeValue[3] = txtDepth.Text;
                            //XmlHelper.Insert(xmlPath, "Image", "Key_" + ofd.SafeFileNames[i].Replace(".png", ""), "Path",
                            //    filePath);
                            XmlHelper.Insert(imageConfig, mNode);
                        }
                        File.Copy(ofd.FileNames[i].ToLower(), filePath, true);
                    }

                    //XmlHelper.Insert();
                }
                exfrm.SetMsgAndProgress("导入完成", 90);
                DialogResult = DialogResult.OK;
                PiEncryptHelper.EncFile(imageConfig);
            }, delegate
            {
                AsyncWaitForm.Instance.SetMsgAndProgress(100);
            });
        }
Example #7
0
 private void button3_Click(object sender, EventArgs e)
 {
     PiEncryptHelper.DecFile(textBox1.Text);
 }
Example #8
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                string path = txtRegFile.Text.Trim();
                PiEncryptHelper.DecFile(path);
                SystemRegInfo regInfo = XmlHelper.GetSystemRegInfo(path, "Software");
                PiEncryptHelper.EncFile(path);
                if (regInfo == null)
                {
                    MessageBox.Show(@"读取授权文件失败!", @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //DialogResult = DialogResult.OK;
                    RegSuccess = false;
                    return;
                }

                if (regInfo.RegKey != CheckRegInfo.AesLocalKey)
                {
                    MessageBox.Show(@"该授权文件无法在该电脑上激活!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //DialogResult = DialogResult.OK;
                    RegSuccess = false;
                    return;
                }

                DateTime endTime = Convert.ToDateTime(regInfo.EndDate);
                if (DateTime.Compare(endTime, DateTime.Now) < 0)
                {
                    MessageBox.Show(@"该授权文件已过期,请重新激活!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //DialogResult = DialogResult.OK;
                    RegSuccess = false;
                    return;
                }

                DateTime startTime = Convert.ToDateTime(regInfo.StartDate);
                if (DateTime.Compare(startTime, DateTime.Now) > 0)
                {
                    MessageBox.Show(@"检测到电脑系统时间不是北京时间,请将电脑时间调整到当前北京时间!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //DialogResult = DialogResult.OK;
                    RegSuccess = false;
                    return;
                }

                if (File.Exists(_regPath))
                {
                    PiEncryptHelper.DecFile(_regPath);
                    XmlHelper.Update(_regPath, regInfo);
                }
                else
                {
                    XmlHelper.CreateRegInfoXml(_regPath, regInfo);
                }

                RegisterClass.UpdateSubKey("Nicholas", NicholasEncrypt.EncryptUTF8String("0", GetSystemInfo.EncrytionKey));
                RegisterClass.UpdateSubKey("Leo", NicholasEncrypt.EncryptUTF8String("YES", GetSystemInfo.EncrytionKey));
                RegisterClass.UpdateSubKey("NicholasLeo", NicholasEncrypt.EncryptUTF8String("Due", GetSystemInfo.EncrytionKey));

                RegSuccess = true;
                PiEncryptHelper.EncFile(_regPath);

                MessageBox.Show(@"系统成功激活!");
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="isReg"></param>
        /// <param name="errorInfo"></param>
        /// <param name="infoType">1:无法获取注册信息,2:无法在本机注册,3:未授权,4:已过期</param>
        public static void CheckReg(ref bool isReg, out string errorInfo, out int infoType, out bool isTrial)
        {
            infoType  = 0;
            errorInfo = "";
            isTrial   = false;
            try
            {
                int x = 0;
                //系统未注册
                if (GetSoftRegFlg() == "NO")
                {
                    if (GetLoginTimes() < 10)
                    {
                        isTrial = true;
                        int times = GetLoginTimes() + 1;
                        RegisterClass.UpdateSubKey("Nicholas", NicholasEncrypt.EncryptUTF8String(times.ToString(), GetSystemInfo.EncrytionKey));
                    }
                    else
                    {
                        errorInfo = "检测到系统试用次数已使用完!";
                        isReg     = false;
                        infoType  = 5;
                        RegisterClass.UpdateSubKey("NicholasLeo", NicholasEncrypt.EncryptUTF8String("NoDue", GetSystemInfo.EncrytionKey));
                        return;
                    }
                    isReg    = true;
                    infoType = 10;
                    return;
                }

                if (GetSoftDue() != "Due")
                {
                    errorInfo = "检测到系统未授权!";
                    isReg     = false;
                    infoType  = 5;
                    return;
                }


                if (!File.Exists(RegPath))
                {
                    errorInfo = "无法检测到系统注册信息!";
                    isReg     = false;
                    infoType  = 1;
                    return;
                }

                if (!PiEncryptHelper.IsFileEnc(RegPath, ref x))
                {
                    errorInfo = "授权文件出错,请联系管理员!";
                    isReg     = false;
                    infoType  = 1;
                    return;
                }

                PiEncryptHelper.DecFile(RegPath);
                SystemRegInfo regInfo = XmlHelper.GetSystemRegInfo(RegPath, "Software");
                PiEncryptHelper.EncFile(RegPath);
                if (regInfo == null)
                {
                    errorInfo = "无法检测到系统注册信息!";
                    isReg     = false;
                    infoType  = 1;
                    return;
                }
                if (regInfo.RegKey != AesLocalKey)
                {
                    errorInfo = "检测到系统无法在改电脑上使用!";
                    isReg     = false;
                    infoType  = 2;
                    return;
                }

                DateTime endTime = Convert.ToDateTime(regInfo.EndDate);
                if (DateTime.Compare(endTime, DateTime.Now) < 0)
                {
                    errorInfo = "检测到系统注册已过期,请重新激活!";
                    isReg     = false;
                    infoType  = 3;
                    return;
                }

                DateTime startTime = Convert.ToDateTime(regInfo.StartDate);
                if (DateTime.Compare(startTime, DateTime.Now) > 0)
                {
                    errorInfo = "检测到电脑系统时间不是北京时间,请将电脑时间调整到当前北京时间!";
                    isReg     = false;
                    infoType  = 3;
                    return;
                }

                if (NicholasEncrypt.DecryptUTF8String(regInfo.IsAuthorized, GetSystemInfo.EncrytionKey) != "HasAuthorized")
                {
                    errorInfo = "检测到系统未进行授权!";
                    isReg     = false;
                    infoType  = 3;
                    return;
                }
            }
            catch (Exception)
            {
                errorInfo = "授权文件出错,请重试!";
                isReg     = false;
            }
        }