static void Main(string[] args) { Program p = new Program(); double input = 20f; ConvertUnit cu = null; cu += p.MileToKm; cu += p.CelsiusToKelvin; cu += delegate(double pound) { double kg = pound * 0.45359237; Console.WriteLine($"{pound} lbs = {Math.Round(kg, 3)} kg"); return(kg); }; cu += cal => { double kj = cal * 4.184; Console.WriteLine($"{cal} cal = {Math.Round(kj, 3)} kJ"); return(kj); }; cu?.Invoke(input); Console.ReadKey(); }
private async Task UpdateCurrency(bool shouldLoad) { var unitTypeString = "currency"; if (shouldLoad) { var currencyRates = await GetCurrencyRates(); var baseType = new ConvertUnit() { Triggers = new[] { currencyRates.Base }, Modifier = decimal.One, UnitType = unitTypeString }; var range = currencyRates.ConversionRates.Select(u => new ConvertUnit() { Triggers = new[] { u.Key }, Modifier = u.Value, UnitType = unitTypeString }).ToArray(); var fileData = JsonConvert.DeserializeObject <ConvertUnit[]>( File.ReadAllText("data/units.json")); var data = JsonConvert.SerializeObject(range.Append(baseType).Concat(fileData).ToList()); _cache.Redis.GetDatabase() .StringSet("converter_units", data); } }
public MainForm() { InitializeComponent(); generatorNumber = new GeneratorNumber(lbl_numer, nud_1, nud_2, tbRandom, cbNumer); counter = new Counter(); notepadUse = new NotepadUse(rtb); generatorPassword = new GeneratorPassword(clbPassword, nudPassLenght, Password); convertUnit = new ConvertUnit(cbFrom, cbTo, tbFrom, tbTo, cbMetric); }
private async Task UpdateCurrency(bool shouldLoad) { try { var unitTypeString = "currency"; if (shouldLoad) { var currencyRates = await GetCurrencyRates(); var baseType = new ConvertUnit() { Triggers = new[] { currencyRates.Base }, Modifier = decimal.One, UnitType = unitTypeString }; var range = currencyRates.ConversionRates.Select(u => new ConvertUnit() { InternalTrigger = u.Key, Modifier = u.Value, UnitType = unitTypeString }).ToArray(); var toRemove = Units.Where(u => u.UnitType == unitTypeString); using (var uow = _db.UnitOfWork) { if (toRemove.Any()) { uow.ConverterUnits.RemoveRange(toRemove.ToArray()); } uow.ConverterUnits.Add(baseType); uow.ConverterUnits.AddRange(range); await uow.CompleteAsync().ConfigureAwait(false); } Units.RemoveAll(u => u.UnitType == unitTypeString); Units.Add(baseType); Units.AddRange(range); Units.AddRange(fileData); } else { using (var uow = _db.UnitOfWork) { Units.RemoveAll(u => u.UnitType == unitTypeString); Units.AddRange(uow.ConverterUnits.GetAll().ToArray()); } } } catch { _log.Warn("Failed updating currency. Ignore this."); } }
static void Main(string[] args) { Program p = new Program(); double input = 20f; ConvertUnit cu = new ConvertUnit(p.MileToKm); double km = cu(input); Console.WriteLine($"{input} miles = {Math.Round(km, 3)} km"); Console.ReadKey(); }
void UpdateSize(float size) { if (randomNaming == true) { if (Dificulty.level >= 3) { unitTerm = ConvertUnit.GetRandomMetricSize(); } else if (Dificulty.level == 2) { unitTerm = ConvertUnit.GetPseudoRandomMetricSize(); } } score.text = ConvertUnit.GetConverted(size, unitTerm); score.offsetZ = .1f; }
protected override void HandleUnauthorizedRequest(System.Web.Http.Controllers.HttpActionContext actionContext) { base.HandleUnauthorizedRequest(actionContext); var response = actionContext.Response = actionContext.Response ?? new HttpResponseMessage(); response.StatusCode = HttpStatusCode.Unauthorized; //response.Headers.Add("WWW-Authenticate", "Basic");//权限信息放在basic 浏览器重新登陆提示 var content = new ResultMessage { Code = (int)response.StatusCode, Success = false, Message = "服务端拒绝访问:你没有权限,或者掉线了", }; response.Content = new StringContent(ConvertUnit.DataToJson(content), Encoding.UTF8, "application/json"); }
protected void GrdReport_RowDataBound(object sender, GridViewRowEventArgs e) { try { if (e.Row.RowType == DataControlRowType.DataRow) { Opening += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Opening")); Purchase += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Purchase")); Sales += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Sales")); SalesReturn += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "SalesReturn")); Inward += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Inward")); Outward += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Outward")); OutwardReturn += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "OutwardReturn")); TransferIN += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "TransferIN")); TransferOUT += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "TransferOUT")); Damaged += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Damage")); PurReturn += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ReturnToSupplier")); Closing += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Closing")); Amount += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Amount")); Consumption += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Consumption")); ConvertUnit += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "STOCKINHANDWITHUNITCONVERT")); } if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[7].Text = "Total"; e.Row.Cells[8].Text = Opening.ToString("0.00"); e.Row.Cells[9].Text = Purchase.ToString("0.00"); e.Row.Cells[10].Text = Sales.ToString("0.00"); e.Row.Cells[11].Text = SalesReturn.ToString("0.00"); e.Row.Cells[13].Text = Inward.ToString("0.00"); e.Row.Cells[14].Text = Outward.ToString("0.00"); e.Row.Cells[15].Text = OutwardReturn.ToString("0.00"); e.Row.Cells[17].Text = TransferIN.ToString("0.00"); e.Row.Cells[18].Text = TransferOUT.ToString("0.00"); e.Row.Cells[16].Text = Damaged.ToString("0.00"); e.Row.Cells[12].Text = PurReturn.ToString("0.00"); e.Row.Cells[20].Text = Closing.ToString("0.00"); e.Row.Cells[23].Text = Amount.ToString("0.00"); e.Row.Cells[22].Text = ConvertUnit.ToString("0.00"); e.Row.Cells[19].Text = Consumption.ToString("0.00"); } } catch (Exception ex) { } }
public string Login() { string result = string.Empty; string username = HttpContext.Current.Request.Form["username"]; string password = HttpContext.Current.Request.Form["password"]; //TODO:数据库验证用户名密码 if (username == "程序员" && password == "123456") { result = SignUnit.ResultTicket <TestModel>("程序员", "123456"); } else { result = ConvertUnit.DataToJson(new ResultMessage() { Code = (int)EnumUnit.Unauthorized, Message = "用户名或密码错误!", Success = false }); } return(result); }
public static async Task UpdateCurrency() { try { var currencyRates = await UpdateCurrencyRates(); var unitTypeString = "currency"; var range = currencyRates.ConversionRates.Select(u => new ConvertUnit() { InternalTrigger = u.Key, Modifier = u.Value, UnitType = unitTypeString }).ToArray(); var baseType = new ConvertUnit() { Triggers = new[] { currencyRates.Base }, Modifier = decimal.One, UnitType = unitTypeString }; var toRemove = Units.Where(u => u.UnitType == unitTypeString); using (var uow = DbHandler.UnitOfWork()) { uow.ConverterUnits.RemoveRange(toRemove.ToArray()); uow.ConverterUnits.Add(baseType); uow.ConverterUnits.AddRange(range); await uow.CompleteAsync().ConfigureAwait(false); } Units.RemoveAll(u => u.UnitType == unitTypeString); Units.Add(baseType); Units.AddRange(range); _log.Info("Updated Currency"); } catch { _log.Warn("Failed updating currency. Ignore this."); } }
private void extractData() { foreach (File myFile in Store.ListOfFile) { try { //Console.WriteLine(myFile.fileName); Store.myDataTable.Rows.Add(new Object[] { myFile.fileName, myFile.fileExtension, myFile.fileLocation, myFile.fileSHA, ConvertUnit.BytesToString(myFile.fileSize), myFile.fileModifyDate }); } catch (Exception) { } } }