Esempio n. 1
0
        /// <summary>
        /// 数据还原
        /// </summary>
        /// <param name="fileName"></param>
        protected void DataHy(string fileName)
        {
            string    strSql    = @"SELECT spid FROM  master.dbo.sysprocesses , master.dbo.sysdatabases WHERE sysprocesses.dbid=sysdatabases.dbid AND sysdatabases.Name='" + CommTools.GetConfigName("dbName") + "'";
            Database  db        = DatabaseFactory.CreateDatabase("conMaster");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            IDataReader dr;

            dr = db.ExecuteReader(dbCommand);
            ArrayList list = new ArrayList();

            while (dr.Read())
            {
                list.Add(dr.GetInt16(0));
            }
            dr.Close();
            for (int i = 0; i < list.Count; i++)
            {
                dbCommand = db.GetSqlStringCommand(string.Format("KILL {0}", list[i]));
                db.ExecuteNonQuery(dbCommand);
            }

            string    restoreSql = @"use master;restore database " + CommTools.GetConfigName("dbName") + " from disk='" + fileName + "' WITH REPLACE  ";
            DbCommand cmdRT      = db.GetSqlStringCommand(restoreSql.ToString());

            try
            {
                db.ExecuteNonQuery(cmdRT);
                MessageBox.Show(this, "数据还原成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "数据还原失败");
            }
        }
Esempio n. 2
0
        protected void DataBackUp(string filepath)
        {
            try
            {
                string    strSql    = @"backup database " + CommTools.GetConfigName("dbName") + " to disk='" + filepath + "' with init";
                Database  db        = DatabaseFactory.CreateDatabase("conMaster");
                DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

                db.ExecuteNonQuery(dbCommand);
                string        msg    = string.Empty;
                Sys_Backup    entity = new Sys_Backup();
                Sys_BackupBLL bll    = new Sys_BackupBLL();
                entity.Backup_AddTime   = DateTime.Now;
                entity.Backup_AddUserID = CurrUserInfo().UserID;
                entity.Backup_Name      = lblFileName.Text;
                entity.Backup_Path      = filepath;
                entity.BackupID         = Guid.NewGuid().ToString();
                if (!bll.Add(entity, out msg))
                {
                    MessageBox.Show(this, msg);
                }

                MessageBox.Show(this, "数据备份成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "数据备份失败");
            }
        }
Esempio n. 3
0
        private async void btnStart_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtLogin.Text) || string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                MessageBox.Show("You must fill all the fields.");
                return;
            }

            btnStart.Enabled  = false;
            btnCancel.Enabled = false;

            var user = await CommTools.LoginUser(txtLogin.Text, txtPassword.Text);

            if (string.IsNullOrWhiteSpace(user))
            {
                MessageBox.Show("Cannot start session, check your account data.");
                btnStart.Enabled  = true;
                btnCancel.Enabled = true;
                return;
            }

            this.DialogResult = DialogResult.OK;
            LoginName         = txtLogin.Text;
            Password          = txtPassword.Text;
            this.Close();
        }
Esempio n. 4
0
        private async void QueryUnknownRoms(List <RomData> ToQuery)
        {
            foreach (var romData in ToQuery)
            {
                var rom = await CommTools.GetRomInfo(romData);

                if (rom != null)
                {
                    DbManager.AddRom(rom.Id, rom.Name, romData.PRGSHA, romData.CHRSHA, rom.PAL);
                }

                string searchTag = romData.PRGSHA + "_" + (romData.CHRSHA ?? "");;


                var item = lstRoms.Items.Cast <ListViewItem>().Where(i => i.Tag.ToString() == searchTag).FirstOrDefault();

                if (item == null)
                {
                    continue;
                }


                var pal = rom?.PAL ?? Pal.Unknown;

                item.SubItems[1].Text = rom?.Name ?? "⊗";
                item.SubItems[2].Text = pal == Pal.Yes ? "PAL" : pal == Pal.Unknown ? "⊗" : "NTSC";
            }
        }
Esempio n. 5
0
        protected void gridFiles_RowEditing(object sender, GridViewEditEventArgs e)
        {
            string fileName = gridFiles.DataKeys[e.NewEditIndex].Value.ToString();
            string filePath = Server.MapPath(CommTools.GetConfigName("dbPath")) + "\\" + fileName;

            DataHy(filePath);
            InitBind();
        }
Esempio n. 6
0
        public void SetKey(System.Guid key)
        {
            int iso_id, ret_id, i1, i2;

            CommTools.FromGuid(key, out iso_id, out ret_id, out i1, out i2);
            IsoID      = iso_id;
            RetailerID = ret_id;
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        protected void InitBind()
        {
            //得到文件的名称
            string fileName = DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second;
            string filePath = Server.MapPath(CommTools.GetConfigName("dbPath"));

            lblFileName.Text = fileName;
            lblFilePath.Text = filePath;
        }
Esempio n. 8
0
        public ActionResult DownloadNotaDebito(int country, int office, DateTime date, int invoice)
        {
            Guid            id       = CommTools.ToGuid(country, office, date.ToInt(), invoice);
            ObjectFileCache cache    = new ObjectFileCache(Config.FILECACHEFOLDER);
            var             buffer   = cache.Get("pdf_" + id, () => ScanServiceAccess.Instance.DownloadNotaDebitoReport(country, office, date, invoice));
            string          fileName = string.Format("{0}_{1}_{2:dd-MM-yyyy}_{3}.pdf", country, office, date, invoice);

            return(base.File(buffer, "application/pdf", fileName));
        }
Esempio n. 9
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     if (TextBox3.Text.Trim() == "" || TextBox4.Text.Trim() == "" || TextBox5.Text.Trim() == "")
     {
         Response.Write("<script>alert('留言失败');</script>");
     }
     else
     {
         FeedBack ra = new FeedBack();
         ra.addfeedback(TextBox3.Text, TextBox4.Text, TextBox5.Text);
         CommTools.alert(this, "提交成功,感谢您的反馈!~");
     }
 }
Esempio n. 10
0
        private async Task Load3DNFiles(string Prg, string Chr)
        {
            Clear3DNList();

            loadedInfos = await CommTools.ListRomFiles(Prg, Chr);

            foreach (var info in loadedInfos)
            {
                var item = lst3DN.Items.Add(info.Name);
                item.SubItems.Add(info.Exact ? "✓" : "✘");
                item.SubItems.Add(info.Official ? "✓" : "✘");
            }
        }
Esempio n. 11
0
        public ActionResult ShowDetails(int country, int office, DateTime date, int invoice)
        {
            Guid id = CommTools.ToGuid(country, office, date.ToInt(), invoice);

            ObjectFileCache cache         = new ObjectFileCache(Config.FILECACHEFOLDER);
            string          bodyFileName  = string.Concat("body_", id);
            string          styleFileName = string.Concat("style_", id);
            string          body          = cache.Get(bodyFileName, () =>
            {
                var buffer1 = ScanServiceAccess.Instance.DownloadNotaDebitoReport(country, office, date, invoice, "XML");
                string xml  = Encoding.UTF8.GetString(buffer1);

                var buffer2    = ScanServiceAccess.Instance.DownloadNotaDebitoReport(country, office, date, invoice, "HTML4.0", "&rc:Toolbar=False&rc:Section=0");
                var html       = Encoding.UTF8.GetString(buffer2);
                string bodyTag = html.GetTags("body").FirstOrDefault();
                if (bodyTag == null)
                {
                    throw new ArgumentException("Body tag empty");
                }

                var builder = new StringBuilder(bodyTag);
                foreach (string v_number in xml.Search("inv_v_number2\\s*=\\s*\"(?<value>[0-9]+)\"", (Match m) => m.Groups["value"].Value))
                {
                    builder.Replace(v_number, string.Concat("<a href=", Config.SITEROOT, "/Voucher/ShowBy?iso_id=", country, "&v_number=", v_number, " >", v_number, "</a>"));
                }

                bodyTag      = builder.ToString();
                bodyTag      = bodyTag.ReplaceTags("img", new MatchEvaluator(ImgMatchEvaluator));
                var styleTag = html.GetTags("style").FirstOrDefault();
                cache.Set(styleFileName, styleTag);
                return(bodyTag);
            });
            string style = cache.Get(styleFileName, () => string.Empty);


            return(View(new string[] { body, style }));
        }
Esempio n. 12
0
        private async void btnCreate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtLogin.Text) || string.IsNullOrWhiteSpace(txtUser.Text) || string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                MessageBox.Show("You must fill all the data fields.");
                return;
            }

            if (txtPassword.Text != txtRepeat.Text)
            {
                MessageBox.Show("Passwords don't match.");
                return;
            }

            btnCreate.Enabled = false;
            btnCancel.Enabled = false;

            lblInfo.Text = "Creating account, please wait...";

            var res = await CommTools.CreateUser(txtUser.Text, txtLogin.Text, txtPassword.Text);

            if (res)
            {
                MessageBox.Show("Account created, you are logged in the system.");
                LoginName         = txtLogin.Text;
                Password          = txtPassword.Text;
                this.DialogResult = DialogResult.OK;
                this.Close();
                return;
            }

            MessageBox.Show("Cannot create account, possibly duplicated user name or login name.");

            btnCreate.Enabled = true;
            btnCancel.Enabled = true;
        }
Esempio n. 13
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void InitBind()
        {
            string path = Server.MapPath(CommTools.GetConfigName("dbPath"));

            GetFiles(path);
        }
Esempio n. 14
0
        public byte[] DownloadVouchers(int countryId, int[] voucherIds, string s1, string s2)
        {
            DirectoryInfo session = null;

            try
            {
                SecurityCheckThrow(s1, s2);
                RecordCallHistory("DownloadReport");

                Guid guid = CommTools.ToGuid(countryId, voucherIds.Get(0), voucherIds.Get(1), voucherIds.Get(2));
                var  dir  = new DirectoryInfo(Global.Strings.DOWNLOADROOT);
                dir.EnsureDirectory();
                session = dir.Combine(guid.ToString());
                session.EnsureDirectory();
                var result = dir.CombineFileName(string.Concat(guid.ToString(), ".zip"));

                var dac = VoucherDataAccess.Instance;
                var zac = ZipFileAccess.Instance;

                CString str = "Archive created at";
                str += DateTime.Now;
                str.NewLine();
                str += "Voucher numbers :";
                str.NewLine();

                foreach (int voucherId in voucherIds)
                {
                    bool   isProtected;
                    string sessionId;
                    int    size;

                    FileInfo binFile = null;
                    FileInfo zipFile = null;
                    try
                    {
                        using (var buffer = new MemoryBuffer(MAX_BUFF_SIZE_50MB))
                        {
                            if (dac.SelectVoucherByNumber(countryId, voucherId, out isProtected, out sessionId, out size, buffer.Buffer))
                            {
                                binFile = session.CombineFileName(string.Concat(sessionId, ".bin"));
                                zipFile = session.CombineFileName(string.Concat(sessionId, ".zip"));

                                if (isProtected)
                                {
                                    binFile.WriteAllBytes(buffer.Buffer, size);
                                    binFile.DecriptFile(zipFile);
                                }
                                else
                                {
                                    zipFile.WriteAllBytes(buffer.Buffer, size);
                                }

                                str += voucherId;
                            }
                            else
                            {
                                str += string.Format("Voucher {0} not found", voucherId);
                            }
                        }

                        var files = zac.ExtractFileZip(zipFile.FullName, session.FullName);
                        foreach (var f in files)
                        {
                            if (!f.Extension.EqualNoCase(".pdf") && !f.Name.Contains("_signed"))
                            {
                                f.DeleteSafe();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        str += ex.Message;
                    }
                    finally
                    {
                        str.NewLine();
                        binFile.DeleteSafe();
                        zipFile.DeleteSafe();
                    }
                }

                zac.CreateZip(result.FullName, session.FullName, str.ToString());

                return(null);
            }
            catch (Exception ex)
            {
                throw new FaultException <MyApplicationFault>(new MyApplicationFault(), ex.Message);
            }
            finally
            {
                session.DeleteSafe();
            }
        }
Esempio n. 15
0
        public virtual void PrintVouchersInternal(int allocationId, List <int> voucherNumbers)
        {
            try
            {
                if (string.IsNullOrEmpty(m_PrinterName))
                {
                    throw new ArgumentNullException("PrinterName", "Value can not be null or empty");
                }

                if (string.IsNullOrEmpty(m_ReportType2))
                {
                    throw new ArgumentNullException("ReportType2", "Value can not be null or empty");
                }

                if (string.IsNullOrEmpty(m_PrinterXmlFilePath))
                {
                    throw new ArgumentNullException("PrinterXmlFilePath", "Value can not be null or empty");
                }

                if (!File.Exists(m_PrinterXmlFilePath))
                {
                    throw new IOException("Can not find file");
                }

                AllocationId = allocationId;

                lock (this)
                {
                    while (ms_VPItems.IndexOf(this) != 0)
                    {
                        Monitor.Wait(this, 3000);
                    }
                }

                Printing = new VoucherNumberingAllocationPrinting.VoucherNumberingAllocationPrinting();
                Manager  = new PartyManagement.PartyManagement();

                Allocation = new Func <int, VoucherAllocation>((x) => Printing.RetrieveAllocation(x)).ReTry(allocationId);

                if (Allocation == null)
                {
                    throw new ArgumentNullException("Can not get allocation:".concat(allocationId));
                }

                Retailer = new Func <int, int, Retailer>((x, y) => Manager.RetrieveRetailerDetail(x, y)).ReTry(Allocation.CountryId, Allocation.RetailerId);

                if (Retailer == null)
                {
                    throw new ArgumentNullException("Can not find retailer:".concat(" CountryId: ", Allocation.CountryId, " RetailerId: ", Allocation.RetailerId));
                }

                Office = new Func <int, int, PtfOffice>((x, y) => Manager.RetrievePtfOfficeDetail(x, y)).ReTry(Retailer.CountryId, Retailer.PrinterBranchId);

                if (Office == null)
                {
                    throw new ArgumentNullException("Can not get office:".concat(" CountryId: ", Allocation.CountryId, " PrinterBranchId:", Retailer.PrinterBranchId));
                }

                var guid = CommTools.ToGuid(Allocation.CountryId, Allocation.RetailerId);

                PrinterDetails printer = null;
                CacheManager.Instance.Get <PrinterDetails>(guid, out printer,
                                                           () => new Func <int, int, PrinterDetails>((x, y) => Manager.GetPrinterInfo(x, y)).ReTry(Retailer.CountryId, Allocation.RetailerId));

                if (printer == null || printer.IsEmpty || UseLocalFormat)
                {
                    printer = new PrinterDetails
                    {
                        Name       = "Default",
                        Path       = m_PrinterName,
                        Type2      = m_ReportType2,
                        Xml        = File.ReadAllText(m_PrinterXmlFilePath),
                        IsoID      = Retailer.CountryId,
                        RetailerID = Allocation.RetailerId,
                    };
                }

                if (UseLocalPrinter)
                {
                    printer.Path = m_PrinterName;
                }

                #region LOCAL PRINTER
                //if (!PrintManager.GetInstalledPrinters().Contains(printer.Path, StringComparer.InvariantCultureIgnoreCase))
                //    throw new ApplicationException("Can not find printer ".concat(printer.Path));
                #endregion

                int countryId = Allocation.CountryId;

                InitPrinter("Initialization_".concat(Retailer.Name, DateTime.Now.Ticks));

                RangeFrom = Allocation.RangeFrom / 10;
                RangeTo   = Allocation.RangeTo / 10;

                //  VPrinting.Documents.VoucherPrintLayout250
                Type documentType = Type.GetType(printer.Type2);
                if (documentType == null)
                {
                    throw new ArgumentNullException("documentType", "Can not find type of: ".concat(printer.Type2));
                }

                XmlSerializer formatter = new XmlSerializer(documentType);
                var           layout    = formatter.ToObject <IVoucherLayout>(printer.Xml);
                if (layout == null)
                {
                    throw new ArgumentNullException("layout", "Can not create layout from xml");
                }
                layout.Init();

                CacheManager.Instance.Table[Strings.IVoucherLayout] = layout;

                CacheManager.Instance.Table[Strings.SubRangeFrom] = RangeFrom;

                var multyLines = new Queue <IList <IPrintLine> >();

                int index = 0;

                foreach (int voucher in voucherNumbers)
                {
                    CacheManager.Instance.Table[Strings.Index] = index++;

                    VoucherNo = voucher;

                    //Counting starts from 1 for us.
                    StrVoucherNo = new Func <int, int, bool, string>((x, y, z) => Printing.CreateVoucherNumber(x, y, z)).ReTry(countryId, voucher, false);

                    layout.Clear();
                    layout.DataBind(this, StrVoucherNo, voucher, false);

                    for (int count = 0; count < Repeat[countryId]; count++)
                    {
#if DEBUGGER
                        Debug.WriteLine(string.Format("{0}\t{1}\t{2}", countryId, Retailer.Name, voucher), Strings.VRPINT);
#endif

                        multyLines.Enqueue(new List <IPrintLine>(layout.PrintLines));
                        if (!SimulatePrint && !MultyPagePrint)
                        {
                            layout.PrintVouchers(printer.Path, StrVoucherNo, layout.FormLength, layout.DocumentInitialization, multyLines);
                        }

                        if (Test != null)
                        {
                            Test(this, EventArgs.Empty);
                        }

                        if (PrintOnce)
                        {
                            break;
                        }
                    }

                    if (PrintOnce)
                    {
                        break;
                    }
                }

                if (!SimulatePrint && MultyPagePrint && multyLines.Count > 0)
                {
                    layout.PrintVouchers(printer.Path, Strings.VRPINT, layout.FormLength, layout.DocumentInitialization, multyLines);
                }

                if (!SimulatePrint)
                {
                    new Action <int, int, int>((x, y, z) => Printing.LogVoucherAllocationPrinted(x, y, z)).ReTry(allocationId, Program.currentUser.UserID, Program.currentUser.CountryID);
                    new Action <int, bool, int>((x, y, z) => Printing.SetVoucherAllocationPrinted(x, y, z)).ReTry(allocationId, true, Program.currentUser.UserID);
                }
                //set the printed status to true
            }
            catch (Exception ex)
            {
                if (Error != null)
                {
                    Error(this, new ThreadExceptionEventArgs(ex));
                }
            }
            finally
            {
                if (Done != null)
                {
                    Done(this, EventArgs.Empty);
                }
            }
        }
Esempio n. 16
0
 public System.Guid GetKey()
 {
     return(CommTools.ToGuid(IsoID, RetailerID));
 }