コード例 #1
0
        public void CreateOutputTable_Test()
        {
            // Arrange
            int         tablesCountBeforeAct = tablesDbSet.Count();
            int         lastOutputTableId    = tablesDbSet.Last().OutputTableId;
            OutputTable newOutputTable       = new OutputTable()
            {
                OutputTableId = lastOutputTableId + 1,
                Name          = "new output table",
                FileName      = "newOutputTable.xls",
                FileType      = "xls",
                CreatedAt     = DateTime.Now,
                UpdatedAt     = DateTime.Now,
                SqlQueryId    = 0
            };

            // Act
            outRepo.Create(newOutputTable);

            // Assert
            Assert.AreNotEqual(tablesDbSet.Last().OutputTableId, lastOutputTableId);
            Assert.AreEqual(tablesDbSet.Last().OutputTableId, newOutputTable.OutputTableId);
            Assert.AreEqual(tablesDbSet.Last().FileName, newOutputTable.FileName);

            Assert.IsTrue(tablesDbSet.Count() > tablesCountBeforeAct);
        }
コード例 #2
0
ファイル: Account.cs プロジェクト: yahch/BiliUPDesktopTool
        /// <summary>
        /// 初始化账号数据
        /// </summary>
        public Account()
        {
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\"))
            {
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\");
            }

            ST = new AccountTable();
            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Account.dma"))
            {
                using (FileStream fs = File.Open(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Account.dma", FileMode.Open, FileAccess.Read))
                {
                    using (StreamReader reader = new StreamReader(fs))
                    {
                        string str = reader.ReadToEnd();
                        str = EncryptHelper.DesDecrypt(str, encryptKey);
                        OutputTable <AccountTable> OT = JsonConvert.DeserializeObject <OutputTable <AccountTable> >(str);
                        ST = OT.settings;
                    }
                }
            }
            else
            {
                //Bas.account = new Account(new EmptyInit());
                LoginWindow lw = new LoginWindow(this);
                lw.ShowDialog();
            }
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: batyrkanov/Exporter
        public ActionResult Unloading(int id)
        {
            IQueryable <Parameter> parameters = unitOfWork
                                                .Parameters
                                                .GetQueryParametersByQueryId(id)
                                                .AsQueryable();

            string queryName = unitOfWork
                               .SqlQueries
                               .GetQueryNameById(id);

            OutputTable lastFormedOutputXlsFile = unitOfWork
                                                  .OutputTables
                                                  .GetQueryOutputTableByIdAndType(id, "xls");
            OutputTable lastFormedOutputCsvFile = unitOfWork
                                                  .OutputTables
                                                  .GetQueryOutputTableByIdAndType(id, "csv");

            ViewBag.Parameters = parameters;
            ViewBag.QueryId    = id;
            ViewBag.QueryName  = queryName;

            ViewBag.XlsFile = lastFormedOutputXlsFile;
            ViewBag.CsvFile = lastFormedOutputCsvFile;

            return(View());
        }
コード例 #4
0
        private static int RunWith(ListOptions opts)
        {
            var storage = new ProfileStorage();

            var output = new OutputTable();

            output.AddColumns("name", "username", "hostname")
            .AddColumn("port", "0", OutputAlignment.Right)
            .AddColumns("ssl");

            if (opts.Passwords)
            {
                output.AddColumn("password");
            }

            foreach (var profile in storage.GetProfiles(opts))
            {
                var row = output.AddRow(profile.Name, profile.UserName, profile.HostName, profile.Port, profile.Ssl);
                if (opts.Passwords)
                {
                    row.Values.Add(profile.Password);
                }
            }

            output.WriteTo(Console.Out);

            return(0);
        }
コード例 #5
0
ファイル: SqlTest.cs プロジェクト: sph001/U33A2SqlTool
 private void ResultToTable(SqlCollection result)
 {
     if (result.Rows.Count == 0)
     {
         return;
     }
     foreach (SqlType field in result.Rows[0].Fields)
     {
         OutputTable.Add(new OutputColumn(field.Name));
     }
     for (int i = 0; i < result.Count; i++)
     {
         SqlObject obj = result.Rows[i];
         for (int j = 0; j < obj.Fields.Count; j++)
         {
             if (obj.Fields[j].Type == typeof(bool) && obj.Fields[j].Name == "IsBusinessAccount")
             {
                 OutputTable[j].Add((bool)obj.Fields[j].Value ? "Business" : "Normal");
             }
             else
             {
                 OutputTable[j].Add(obj.Fields[j].FormatValue());
             }
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// 初始化账号数据
        /// </summary>
        private Account()
        {
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\"))
            {
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\");
            }

            ST = new AccountTable();
            if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Account.dma"))
            {
                using (FileStream fs = File.Open(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Account.dma", FileMode.Open, FileAccess.Read))
                {
                    using (StreamReader reader = new StreamReader(fs))
                    {
                        string str = reader.ReadToEnd();
                        str = EncryptHelper.DesDecrypt(str, encryptKey);
                        OutputTable <AccountTable> OT = JsonConvert.DeserializeObject <OutputTable <AccountTable> >(str);
                        ST      = OT.settings;
                        Islogin = true;
                    }
                }
            }

            Refresher = new Timer(new TimerCallback(GetInfo));
            Refresher.Change(0, 1800000);
        }
コード例 #7
0
        public void GetQueryOutputTableByIdAndType_Test()
        {
            // Arrange
            int    queryId     = 0;
            int    newId       = tablesDbSet.Last().OutputTableId + 1;
            string type        = "xls";
            string newName     = "New table";
            string newFileName = "newTableRandomFileName.xls";

            OutputTable newOutputTable = new OutputTable()
            {
                OutputTableId = newId,
                Name          = newName,
                FileName      = newFileName,
                FileType      = type,
                CreatedAt     = DateTime.Now,
                UpdatedAt     = DateTime.Now,
                SqlQueryId    = queryId
            };

            outRepo.Create(newOutputTable);

            // Act
            OutputTable outputTable = outRepo.GetQueryOutputTableByIdAndType(queryId, type);

            // Assert
            Assert.AreEqual(outputTable.OutputTableId, newId);
            Assert.AreEqual(outputTable.FileType, type);
            Assert.AreEqual(outputTable.Name, newName);
            Assert.AreEqual(outputTable.FileName, newFileName);
            Assert.IsTrue(
                DateTime.Today < outputTable.CreatedAt &&
                DateTime.Today < outputTable.UpdatedAt
                );
        }
コード例 #8
0
        public void UpdateOutputTable_Test()
        {
            // Arrange
            int      tablesCountBeforeAct = tablesDbSet.Count();
            int      updatedTableId       = tablesDbSet.Last().OutputTableId;
            DateTime createdDateBeforeAct = tablesDbSet.Last().CreatedAt;
            string   fileNameBeforeAct    = tablesDbSet.Last().FileName;
            string   nameBeforeAct        = tablesDbSet.Last().Name;

            string newFileName = "updatedFileName.csv";
            string newName     = "updatedName";

            // Act
            OutputTable tableToUpdate = tablesDbSet.Last();

            tableToUpdate.FileName = newFileName;
            tableToUpdate.Name     = newName;
            outRepo.Update(tableToUpdate);

            OutputTable updatedTable = tablesDbSet.Last();

            // Assert
            Assert.AreEqual(tablesCountBeforeAct, tablesDbSet.Count());

            Assert.AreEqual(updatedTableId, updatedTable.OutputTableId);
            Assert.AreEqual(newFileName, updatedTable.FileName);
            Assert.AreEqual(newName, updatedTable.Name);
            Assert.AreEqual(createdDateBeforeAct, updatedTable.CreatedAt);

            Assert.AreNotEqual(fileNameBeforeAct, updatedTable.FileName);
            Assert.AreNotEqual(nameBeforeAct, updatedTable.Name);
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: Tsyronin/XML-Lab
 private void Clear_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to clear the table?", "Clear", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         OutputTable.Clear();
     }
 }
コード例 #10
0
ファイル: SqlTest.cs プロジェクト: sph001/U33A2SqlTool
        public void LogResult()
        {
            string result;

            if (FailedReason != "")
            {
                result = "Result: Failed: " + FailedReason;
            }
            else
            {
                result = "Result: Success";
            }
            string        statement = "Statement:\n" + FormatStatement();
            List <string> lines     = new List <string> {
                $"SqlTest: {Name}", result, statement
            };

            lines.AddRange(ExpectedValues.ToList());
            lines.Add(OutputTable.Aggregate("|", (current, t) => current + t.FormatHeader() + "|"));
            if (OutputTable.Count != 0)
            {
                for (int i = 0; i < OutputTable[0].Count; i++)
                {
                    lines.Add(OutputTable.Aggregate("|", (current, t) => current + t.FormatValue(i) + "|"));
                }
            }
            Console.WriteLine($"Test: {Name}: {result.Replace("Result: ", "")}");
            Logger.PrintLines(lines.ToArray(), "./Tests/" + Name + ".txt");
        }
コード例 #11
0
 public void BuildPolir()
 {
     MakeInitializes();
     BuildPriorTable();
     loopSign     = 0;
     loopParametr = "";
     currIndex    = OutputTable.FindIndex(x => x.Name == "begin") + 2;
     for (; currIndex < OutputTable.Count - 1; currIndex++)
     {
         IdentifyLexem();
     }
 }
コード例 #12
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public virtual void Save()
        {
            OutputTable <T> OT   = new OutputTable <T>(ST);
            string          json = JsonConvert.SerializeObject(OT);

            using (FileStream fs = File.Open(savepath, FileMode.Create, FileAccess.Write))
            {
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    writer.Write(json);
                }
            }
        }
コード例 #13
0
        public void GetOutputTable_Test()
        {
            // Arrange
            int tablesCountBeforeAct = tablesDbSet.Count();
            int id = tablesDbSet.First().OutputTableId;

            // Act
            OutputTable outputTable = outRepo.Get(id);

            // Assert
            Assert.AreEqual(tablesCountBeforeAct, tablesDbSet.Count());
            Assert.AreEqual(id, outputTable.OutputTableId);
            Assert.AreEqual(outputTable.FileName, tablesDbSet.Find(id).FileName);
        }
コード例 #14
0
        public ActionResult OutputTables(int id)
        {
            OutputTable lastFormedOutputXlsFile = unitOfWork
                                                  .OutputTables
                                                  .GetQueryOutputTableByIdAndType(id, "xls");
            OutputTable lastFormedOutputCsvFile = unitOfWork
                                                  .OutputTables
                                                  .GetQueryOutputTableByIdAndType(id, "csv");

            ViewBag.XlsFile = lastFormedOutputXlsFile;
            ViewBag.CsvFile = lastFormedOutputCsvFile;

            return(View());
        }
コード例 #15
0
        /// <summary>
        /// 保存
        /// </summary>
        public override void Save()
        {
            OutputTable <AccountTable> OT = new OutputTable <AccountTable>(ST);
            string json = JsonConvert.SerializeObject(OT);

            json = EncryptHelper.DesEncrypt(json, encryptKey);
            using (FileStream fs = File.Open(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\Account.dma", FileMode.Create, FileAccess.Write))
            {
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    writer.Write(json);
                }
            }
        }
コード例 #16
0
        private static void OutputFolder(OutputTable output, IMailFolder folder, ref int messages, ref int unread, int indent = 0)
        {
            var a = folder.Open(FolderAccess.ReadOnly);

            output.AddRow("".PadRight(indent) + folder.Name, folder.Count, folder.Unread);
            var q = folder.GetQuota();

            messages += folder.Count;
            unread   += folder.Unread;

            folder.Close();

            foreach (var subFolder in folder.GetSubfolders())
            {
                OutputFolder(output, subFolder, ref messages, ref unread, indent + 1);
            }
        }
コード例 #17
0
        private static void RunWithMessages(InfoOptions opts)
        {
            var storage = new ProfileStorage();

            bool needLine = false;

            foreach (var profile in storage.GetProfiles(opts))
            {
                using (var client = profile.CreateClient())
                {
                    var output = new OutputTable();
                    output
                    .AddColumn(profile.Name)
                    .AddColumn("messages", "#,##0", OutputAlignment.Right)
                    .AddColumn("unread", "#,##0", OutputAlignment.Right);

                    var messages = 0;
                    var unread   = 0;

                    foreach (var ns in client.PersonalNamespaces)
                    {
                        foreach (var folder in client.GetFolders(ns).Where(f => f.ParentFolder.ParentFolder == null))
                        {
                            OutputFolder(output, folder, ref messages, ref unread);
                        }
                    }

                    output.AddSeparator();
                    output.AddRow(profile.UserName, messages, unread);

                    if (needLine)
                    {
                        Console.WriteLine();
                    }
                    else
                    {
                        needLine = true;
                    }

                    output.WriteTo(Console.Out);
                }
            }
        }
コード例 #18
0
        private static void RunWithNotAll(InfoOptions opts)
        {
            var storage = new ProfileStorage();

            var output = new OutputTable();

            output
            .AddColumns("name", "username")
            .AddColumn("messages", "#,##0", OutputAlignment.Right)
            .AddColumn("limit", "#,##0", OutputAlignment.Right)
            .AddColumn("storage", "#,##0", OutputAlignment.Right)
            .AddColumn("limit", "#,##0", OutputAlignment.Right);

            foreach (var profile in storage.GetProfiles(opts))
            {
                using (var client = profile.CreateClient())
                {
                    var quota = client.Inbox.GetQuota();
                    output.AddRow(profile.Name, profile.UserName, quota.CurrentMessageCount, quota.MessageLimit, quota.CurrentStorageSize, quota.StorageLimit);
                }
            }
            output.WriteTo(Console.Out);
        }
コード例 #19
0
ファイル: dataGridView.cs プロジェクト: Ciphix/DataGridView
        private void Form_Closing(object sender, FormClosingEventArgs e)
        {
            DataTable outputTable = myDataGridView.DataSource as DataTable;

            OutputTable.Set(this.contextGlobal, outputTable);
            //Get info of selected Cell
            if (this.myDataGridView.SelectedCells.Count > 0)
            {
                Dictionary <string, string> props = new Dictionary <string, string>();
                int    rowIndex    = myDataGridView.CurrentCell.RowIndex;
                int    columnIndex = myDataGridView.CurrentCell.ColumnIndex;
                String columnName  = myDataGridView.Columns[columnIndex].Name;
                String value       = myDataGridView.CurrentCell.Value.ToString();

                props.Add("rowIndex", rowIndex.ToString());
                props.Add("columnIndex", columnIndex.ToString());
                props.Add("columnName", columnName);
                props.Add("value", value);

                SelectedCell.Set(this.contextGlobal, props);
            }
            e.Cancel = false;
        }
コード例 #20
0
        /// <summary>
        /// 初始化设置
        /// </summary>
        public SettingsBase(T _ST, string _savepath)
        {
            if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\"))
            {
                Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\");
            }

            ST       = _ST;
            savepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\zhangbudademao.com\\BiliUPDesktopTool\\" + _savepath;

            if (File.Exists(savepath))
            {
                using (FileStream fs = File.OpenRead(savepath))
                {
                    using (StreamReader reader = new StreamReader(fs))
                    {
                        string          str = reader.ReadToEnd();
                        OutputTable <T> OT  = JsonConvert.DeserializeObject <OutputTable <T> >(str);
                        ST = OT.settings;
                    }
                }
            }
        }
コード例 #21
0
        public SellViewModel()
        {
            loadUserCurrentLogin();
            TotalPrice   = 0;
            IsEnableName = false;
            List         = new List <ProductTable>(DataProvider.Ins.Entities.ProductTable);
            ListSupplier = new List <SupplierTable>(DataProvider.Ins.Entities.SupplierTable);
            ListUnit     = new List <UnitTable>(DataProvider.Ins.Entities.UnitTable);
            ListBill     = new List <BillModel>();
            _ListTemp    = new List <BillModel>();

            LoadEditCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { LoadDialogAccountEdit(); });

            AddBillCommand = new RelayCommand <object>((p) =>
            {
                if (SelectedItems == null)
                {
                    return(false);
                }
                SelectedItemsBill = null;
                return(true);
            },
                                                       (p) =>
            {
                BillModel bill            = new BillModel();
                ProductTable billProduct  = new ProductTable();
                billProduct.ID            = SelectedItems.ID;
                billProduct.DisplayName   = SelectedItems.DisplayName;
                billProduct.SupplierTable = SelectedItems.SupplierTable;
                billProduct.UnitTable     = SelectedItems.UnitTable;
                int Price     = 0;
                var listPrice = DataProvider.Ins.Entities.ProductTable.Where(x => x.ID == SelectedItems.ID).Select(x => x.Price);

                foreach (var item in listPrice)
                {
                    Price = item;
                }

                bill.product      = billProduct;
                bill.Price        = Price;
                bill.Amount       = 1;
                bill.PriceItems   = Price;
                bill.AmountChange = AmountChange;

                if (LoadInventory(bill.product.ID) <= 0)
                {
                    LoadDialogError("Sản Phẩm Không Còn Trong Kho! Vui Lòng Liên Hệ Quản Trị Viên!");
                    return;
                }

                TotalPrice += Price;

                var listCheckDuplicate = _ListTemp.Where(x => x.product.ID == bill.product.ID);
                if (listCheckDuplicate.Count() != 0)
                {
                    int DuplicateProduct = _ListTemp.Where(x => x.product.ID == bill.product.ID).FirstOrDefault().Amount;
                    _ListTemp.Where(x => x.product.ID == bill.product.ID).FirstOrDefault().Amount      = DuplicateProduct + 1;
                    _ListTemp.Where(x => x.product.ID == bill.product.ID).FirstOrDefault().PriceItems += Price;
                    ListBill      = new List <BillModel>(_ListTemp);
                    SelectedItems = null;
                    return;
                }
                _ListTemp.Add(bill);
                ListBill      = new List <BillModel>(_ListTemp);
                SelectedItems = null;
            });

            DeleteItemInBill = new RelayCommand <object>((p) =>
            {
                if (SelectedItemsBill == null)
                {
                    return(false);
                }
                SelectedItems = null;
                return(true);
            },
                                                         (p) =>
            {
                var FindToDelete = _ListTemp.Where(x => x.product.ID == SelectedItemsBill.product.ID).FirstOrDefault();
                TotalPrice      -= FindToDelete.PriceItems;
                _ListTemp.Remove(FindToDelete);
                ListBill          = new List <BillModel>(_ListTemp);
                SelectedItemsBill = null;
            });

            AmountChange = new RelayCommand <object>((p) =>
            {
                return(true);
            },
                                                     (p) =>
            {
                try
                {
                    var FindToEdit        = _ListTemp.Where(x => x.product.ID == SelectedItemsBill.product.ID).FirstOrDefault();
                    TotalPrice           -= FindToEdit.PriceItems;
                    FindToEdit.Amount     = SelectedItemsBill.Amount;
                    FindToEdit.PriceItems = FindToEdit.Amount * FindToEdit.Price;
                    TotalPrice           += FindToEdit.PriceItems;
                    ListBill = new List <BillModel>(_ListTemp);
                }
                catch
                {
                    MessageBox.Show(Message);
                }
            });

            PhoneCustomerChange = new RelayCommand <object>((p) =>
            {
                if (PhoneCustomer.ToString().Length < 9)
                {
                    return(false);
                }
                return(true);
            },
                                                            (p) =>
            {
                var Customer = DataProvider.Ins.Entities.CustomerTable.Where(x => x.Phone.ToLower().Contains(PhoneCustomer.ToString())).FirstOrDefault();
                if (Customer != null)
                {
                    NameCustomer = Customer.FullName;
                    IsEnableName = false;
                    return;
                }
                NameCustomer = "";
                IsEnableName = true;
            });

            CreateBill = new RelayCommand <object>((p) =>
            {
                if (TotalPrice <= 0 || NameCustomer == null || PhoneCustomer.ToString().Length < 9)
                {
                    return(false);
                }
                return(true);
            },
                                                   (p) =>
            {
                foreach (var item in _ListTemp)
                {
                    if (LoadInventory(item.product.ID) - item.Amount < 0)
                    {
                        LoadDialogError("Số Lượng Sản Phẩm Không Đủ Đáp Ứng Nhu Cầu!");
                        return;
                    }
                }

                if (IsEnableName)
                {
                    CustomerTable customer = new CustomerTable();
                    customer.FullName      = NameCustomer;
                    customer.Phone         = "0" + PhoneCustomer.ToString();
                    customer.Address       = "";
                    DataProvider.Ins.Entities.CustomerTable.Add(customer);
                    DataProvider.Ins.Entities.SaveChanges();
                }
                var ID_Customer = DataProvider.Ins.Entities.CustomerTable.Where(x => x.Phone.ToLower().Contains(PhoneCustomer.ToString())).FirstOrDefault();

                OutputTable output = new OutputTable();
                output.ID_User     = (int)App.Current.Properties["UserID"];
                output.DateOutput  = DateTime.Now;
                output.ID_Customer = ID_Customer.ID;
                DataProvider.Ins.Entities.OutputTable.Add(output);
                DataProvider.Ins.Entities.SaveChanges();
                var ID_Output = DataProvider.Ins.Entities.OutputTable.Where(x => x.ID_User == output.ID_User &&
                                                                            x.ID_Customer == output.ID_Customer && x.DateOutput == output.DateOutput.Date).FirstOrDefault();

                int ID = ID_Output.ID;
                OutPutDetailTable outPutDetail = new OutPutDetailTable();
                foreach (var item in _ListTemp)
                {
                    outPutDetail.Count      = item.Amount;
                    outPutDetail.ID_Product = item.product.ID;
                    outPutDetail.ID_Output  = ID;
                    outPutDetail.Price      = item.Price;
                    outPutDetail.TotalPrice = item.PriceItems;
                    DataProvider.Ins.Entities.OutPutDetailTable.Add(outPutDetail);
                    DataProvider.Ins.Entities.SaveChanges();
                }
                LoadDialogSuccessSale();
                TotalPrice    = 0;
                _ListBill     = null;
                ListBill      = null;
                NameCustomer  = null;
                PhoneCustomer = 0;
                IsEnableName  = false;
            });

            DestroyCommand = new RelayCommand <object>((p) =>
            {
                return(true);
            },
                                                       (p) =>
            {
                TotalPrice    = 0;
                ListBill      = null;
                _ListBill     = null;
                NameCustomer  = null;
                PhoneCustomer = 0;
                IsEnableName  = false;
                LoadDialogDeleted();
            });

            SearchCommand = new RelayCommand <object>((p) =>
            {
                return(true);
            },
                                                      (p) =>
            {
                if (SearchTerm == null)
                {
                    return;
                }

                List = new List <ProductTable>(DataProvider.Ins.Entities.ProductTable.Where(
                                                   x => x.DisplayName.ToLower().Contains(SearchTerm) ||
                                                   x.SupplierTable.DisplayName.ToLower().Contains(SearchTerm) || x.UnitTable.Descriptions.ToLower().Contains(SearchTerm)));
            });

            OpenBillWindow = new RelayCommand <Window>((p) =>
            {
                return(true);
            },
                                                       (p) =>
            {
                p.Close();
                BillWindow wd = new BillWindow();
                wd.ShowDialog();
            });
        }
コード例 #22
0
        public SyncTransactionItems TransactionItemsGet(string transactionId, Transaction transaction = null)
        {
            if (transaction == null)
            {
                // Try to find the trx in disk
                SyncRawTransaction rawtrx = TransactionGetByHash(transactionId);

                if (rawtrx == null)
                {
                    var client = clientFactory.Create(syncConnection);

                    Client.Types.DecodedRawTransaction res = client.GetRawTransactionAsync(transactionId, 0).Result;

                    if (res.Hex == null)
                    {
                        return(null);
                    }

                    transaction = syncConnection.Network.Consensus.ConsensusFactory.CreateTransaction(res.Hex);
                    transaction.PrecomputeHash(false, true);
                }
                else
                {
                    transaction = syncConnection.Network.Consensus.ConsensusFactory.CreateTransaction(rawtrx.RawTransaction);
                    transaction.PrecomputeHash(false, true);
                }
            }

            bool hasWitness         = transaction.HasWitness;
            int  witnessScaleFactor = syncConnection.Network.Consensus.Options?.WitnessScaleFactor ?? 4;

            int size        = NBitcoin.BitcoinSerializableExtensions.GetSerializedSize(transaction, syncConnection.Network.Consensus.ConsensusFactory);
            int virtualSize = hasWitness ? transaction.GetVirtualSize(witnessScaleFactor) : size;
            int weight      = virtualSize * witnessScaleFactor - (witnessScaleFactor - 1);

            var ret = new SyncTransactionItems
            {
                RBF         = transaction.RBF,
                LockTime    = transaction.LockTime.ToString(),
                Version     = transaction.Version,
                HasWitness  = hasWitness,
                Size        = size,
                VirtualSize = virtualSize,
                Weight      = weight,
                IsCoinbase  = transaction.IsCoinBase,
                IsCoinstake = syncConnection.Network.Consensus.IsProofOfStake && transaction.IsCoinStake,
                Inputs      = transaction.Inputs.Select(v => new SyncTransactionItemInput
                {
                    PreviousTransactionHash = v.PrevOut.Hash.ToString(),
                    PreviousIndex           = (int)v.PrevOut.N,
                    WitScript    = v.WitScript.ToScript().ToHex(),
                    ScriptSig    = v.ScriptSig.ToHex(),
                    InputAddress = scriptInterpeter.GetSignerAddress(syncConnection.Network, v.ScriptSig),
                    SequenceLock = v.Sequence.ToString(),
                }).ToList(),
                Outputs = transaction.Outputs.Select((output, index) => new SyncTransactionItemOutput
                {
                    Address      = scriptInterpeter.InterpretScript(syncConnection.Network, output.ScriptPubKey)?.Addresses?.FirstOrDefault(),
                    Index        = index,
                    Value        = output.Value,
                    OutputType   = scriptInterpeter.InterpretScript(syncConnection.Network, output.ScriptPubKey)?.ScriptType, // StandardScripts.GetTemplateFromScriptPubKey(output.ScriptPubKey)?.Type.ToString(),
                    ScriptPubKey = output.ScriptPubKey.ToHex()
                }).ToList()
            };

            foreach (SyncTransactionItemInput input in ret.Inputs)
            {
                OutputTable outputTable = GetTransactionOutput(input.PreviousTransactionHash, input.PreviousIndex);
                input.InputAddress = outputTable?.Address;
                input.InputAmount  = outputTable?.Value ?? 0;
            }

            // try to fetch spent outputs
            foreach (SyncTransactionItemOutput output in ret.Outputs)
            {
                output.SpentInTransaction = GetTransactionInput(transactionId, output.Index)?.TrxHash;
            }

            if (!ret.IsCoinbase && !ret.IsCoinstake)
            {
                // calcualte fee and feePk
                ret.Fee = ret.Inputs.Sum(s => s.InputAmount) - ret.Outputs.Sum(s => s.Value);
            }

            return(ret);
        }