Example #1
0
        //update method
        public int updateLicenceDB(int id, licence licence)
        {
            int flag = 0;

            try
            {
                var result = db.licences.Where(l => l.licence_id == id && l.licence_status == 1);
                if (result != null)
                {
                    var callsignOrTrcNo = db.licences.Where(l => l.licence_callsign.Equals(licence.licence_callsign) && l.licence_status == 1).FirstOrDefault();
                    if (callsignOrTrcNo == null)
                    {
                        db.Entry(result).State  = EntityState.Detached;
                        db.Entry(licence).State = EntityState.Modified;
                        db.SaveChanges();
                        flag = 1;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(flag);
        }
Example #2
0
 public ActionResult Create(licence licence)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (licence.vessel_id != 0)
             {
                 int flag = LicencesContollerManager.saveLicence(licence);
                 if (flag == 1)
                 {
                     return(RedirectToAction("Index"));
                 }
                 else
                 {
                     TempData["licence_callsign"] = "This License Callsign or TRC File No already taken";
                 }
             }
             else
             {
                 ModelState.AddModelError("", "Warning! Vessel is not found");
             }
         }
         return(View());
     }
     catch (Exception)
     {
         return(RedirectToAction("Error", "Home", new { error = "POST/Licences/Create" }));
     }
 }
Example #3
0
        //update exist method
        public int updateExistLicenceDB(licence licence, int licence_id)
        {
            int flag = 0;

            try
            {
                var updateResult = db.licences.Where(l => l.licence_callsign.Equals(licence.licence_callsign) && l.licence_status == 1).FirstOrDefault();
                //Update license Date from and Date to using adding new license record
                if (updateResult != null)
                {
                    db.licences.Add(licence);
                    db.SaveChanges();
                    flag = 1;
                }

                licence existLicence = db.licences.Where(l => l.vessel_id == licence.vessel_id && l.licence_id == licence_id && l.licence_status == 1).FirstOrDefault();
                //The previous license status will change to '0' using 'license_id' to avoid displaying two or more license for one vessel
                if (existLicence != null)
                {
                    existLicence.licence_status = 0;

                    db.licences.Attach(existLicence);
                    db.Entry(existLicence).State = EntityState.Modified;
                    db.SaveChanges();
                    flag = flag + 1;    //Controller will return '2' as int value to prove that the license status has been change to '0'
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(flag);
        }
Example #4
0
 public ActionResult Delete(int id, licence licence)
 {
     try
     {
         LicencesContollerManager.deleteLicence(id, licence);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(RedirectToAction("Error", "Home", new { error = "POST/Licences/Delete/int" }));
     }
 }
        //update method
        public int updateLicence(int id, licence licence)
        {
            try
            {
                licence.licence_last_modified_date = DateTime.Now;
                licence.licence_last_modified_by   = HttpContext.Current.User.Identity.Name;

                return(LicencesService.updateLicenceDB(id, licence));
            }
            catch (Exception)
            {
                throw;
            }
        }
        //update exist method
        public int updateExistLicence(licence licence, int licence_id)
        {
            try
            {
                licence.licence_created_date       = DateTime.Now;
                licence.licence_created_by         = HttpContext.Current.User.Identity.Name;
                licence.licence_last_modified_date = DateTime.Now;
                licence.licence_last_modified_by   = HttpContext.Current.User.Identity.Name;
                licence.licence_status             = 1;

                return(LicencesService.updateExistLicenceDB(licence, licence_id));
            }
            catch (Exception)
            {
                throw;
            }
        }
        //insert invoice state method
        public int InvoiceStateCreate(licence licence)  //Callsign = "Pending"
        {
            try
            {
                licence.licence_created_date       = DateTime.Now;
                licence.licence_created_by         = HttpContext.Current.User.Identity.Name;
                licence.licence_last_modified_date = DateTime.Now;
                licence.licence_last_modified_by   = HttpContext.Current.User.Identity.Name;
                licence.licence_status             = 1;

                return(LicencesService.InvoiceStateCreateDB(licence));
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #8
0
        //select method
        public licence getLicenceDB(int id)
        {
            licence licence = null;

            try
            {
                licence = db.licences.Where(l => l.licence_status == 1 && l.licence_id == id).FirstOrDefault();
                if (licence == null)
                {
                    licence = new licence();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(licence);
        }
Example #9
0
 public ActionResult Update(licence licence, int licence_id)
 {
     try
     {
         if (ModelState.IsValid)
         {
             int flag = LicencesContollerManager.updateExistLicence(licence, licence_id);   //return '2' as int status if execute successfully
             if (flag == 2)
             {
                 return(RedirectToAction("Index"));
             }
         }
         return(View(LicencesContollerManager.getLicence(licence_id)));
     }
     catch
     {
         return(RedirectToAction("Error", "Home", new { error = "POST/Licences/Update/int" }));
     }
 }
Example #10
0
        //insert invoice state method
        public int InvoiceStateCreateDB(licence licence)
        {
            int flag = 0;

            try
            {
                var result = db.licences.Where(l => l.licence_trc_fileno.Equals(licence.licence_trc_fileno) && l.licence_status == 1).FirstOrDefault();

                if (result == null)
                {
                    db.licences.Add(licence);
                    db.SaveChanges();
                    flag = 1;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(flag);
        }
Example #11
0
 public ActionResult Edit(int id, licence licence)
 {
     try
     {
         if (ModelState.IsValid)
         {
             int flag = LicencesContollerManager.updateLicence(id, licence);
             if (flag == 1)
             {
                 return(RedirectToAction("Index"));
             }
             else
             {
                 TempData["callsign"] = "This License Callsign is already taken or you cannot save Callsign as Pending";
             }
         }
         return(View());
     }
     catch
     {
         return(RedirectToAction("Error", "Home", new { error = "POST/Licences/Edit/int" }));
     }
 }
Example #12
0
        //get Vessel Id For Renewal
        public licence getVesselIdForRenewalDB(string SearchText)
        {
            licence licence = new licence();

            try
            {
                vessel Vessel = db.vessels.Where(v => v.vessel_status == 1 && v.registration.registration_code.Equals("IMUL-A-") &&
                                                 v.vessel_no.Contains(SearchText.Substring(7, 4)) && v.district.district_code.Contains(SearchText.Substring(11, 3))).FirstOrDefault();
                //get the vessel object according to the searchText and that vessel_id will set to a new licence's vessel_id
                if (Vessel != null)
                {
                    if (Vessel.vessel_id != 0)
                    {
                        licence.vessel_id = Vessel.vessel_id;    //return vessel_id fixed licence object to the view
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(licence);
        }
Example #13
0
        //验证licence,并设置UI和本类下的netAcc字段      //本方法应另开线程,因实时检测许可
        private void UI_verifyLicence()
        {
            log.writeLog("开始循环检测许可", log.msgType.info);
            //---------当UI启动时:验证licence------------
            String  licencePath     = "C://ProgramData//licence";
            String  locaLicencePath = "licence";
            bool    firstActived    = false;
            licence lic             = new licence();

            for (;;)
            {
                if (File.Exists(licencePath))
                {
                    try
                    {
                        StreamReader sr      = new StreamReader(licencePath);
                        String       content = sr.ReadToEnd();
                        sr.Close();
                        String decryptString = lic.getNetAcc(content);
                        if (decryptString == null)
                        {
                            string cause = lic.getErrorInfo();
                            pubFun_setText_simpleButton_showUser(cause, Color.Red);
                            log.writeLog($"解析许可证时出现错误,原因:{cause}", log.msgType.error);
                        }
                        else
                        {
                            String base64encode = Convert.ToBase64String(Encoding.Default.GetBytes(decryptString)); //将解密的宽带账号base64编码
                            netAccBase64 = base64encode;                                                            //主缓存区的netAcc被赋值为base64加密后的值
                            pubfun_setText_normal_textBox_netAcc(decryptString);                                    //UI(普通模式)上显示正确的已授权账号
                            pubfun_setText_normal_textBox_netAccEasy(decryptString);                                //UI(简易模式)上显示正确的已授权账号
                            //normal_textBox_netAcc.Text = decryptString; //UI上显示正确的已授权账号

                            //如果软件目录已经存在licence则删除它
                            if (File.Exists(locaLicencePath))
                            {
                                File.Delete(locaLicencePath);
                            }
                            // 创建文件
                            FileStream   fs = new FileStream(locaLicencePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                            StreamWriter sw = new StreamWriter(fs); // 创建写入流
                            sw.WriteLine(content);                  // 写入到软件目录
                            sw.Flush();                             //清空缓冲区
                            sw.Close();                             //关闭流
                            fs.Close();                             //关闭文件
                            File.Delete(licencePath);               //删除临时licence文件
                            if (firstActived)                       //如果是首次激活
                            {
                                DevExpress.XtraEditors.XtraMessageBox.Show($"软件激活完成!\n宽带账号:'{decryptString}'已授权", "许可证", MessageBoxButtons.OK, MessageBoxIcon.None);
                                pubFun_setText_simpleButton_showUser("软件已激活", Color.White);
                            }
                            return;
                        }
                    }
                    catch
                    {
                        pubFun_setText_simpleButton_showUser("软件读取临时许可证时发生未知错误", Color.Red);
                        log.writeLog("软件读取临时许可证时发生未知错误", log.msgType.error);
                    }
                }
                else if (File.Exists(locaLicencePath))
                {
                    try
                    {
                        StreamReader sr      = new StreamReader(locaLicencePath);
                        String       content = sr.ReadToEnd();
                        sr.Close();
                        String decryptString = lic.getNetAcc(content);
                        if (decryptString == null)
                        {
                            pubFun_setText_simpleButton_showUser("许可证被损坏", Color.Red);
                            log.writeLog("许可证被损坏", log.msgType.error);
                        }
                        else
                        {
                            String base64encode = Convert.ToBase64String(Encoding.Default.GetBytes(decryptString)); //将解密的宽带账号base64编码
                            netAccBase64 = base64encode;                                                            //主缓存区的netAcc被赋值为base64加密后的值
                            pubfun_setText_normal_textBox_netAcc(decryptString);                                    //UI(普通模式)上显示正确的已授权账号
                            pubfun_setText_normal_textBox_netAccEasy(decryptString);                                //UI(简易模式)上显示正确的已授权账号
                            if (firstActived)                                                                       //如果是首次激活
                            {
                                DevExpress.XtraEditors.XtraMessageBox.Show($"软件激活完成!\n宽带账号:'{decryptString}'已授权", "许可证", MessageBoxButtons.OK, MessageBoxIcon.None);
                                pubFun_setText_simpleButton_showUser("软件已激活", Color.White);
                            }
                            return;
                        }
                    }
                    catch
                    {
                        pubFun_setText_simpleButton_showUser("读取许可证时发生未知错误", Color.Red);
                        log.writeLog("读取许可证时发生未知错误", log.msgType.error);
                    }
                }
                Thread.Sleep(1000);
                firstActived = true;
            }//end of loop for(;;)
        }