/// <summary> /// 重新改尺寸 /// </summary> public void Resize() { if (IsOpenKeyWindow && OperatesService.GetOperates().IsExpired == false && OperatesService.GetOperates().IsAdminUsing == false && Resources.GetRes().SERVER_SESSION != null) { this.IsOpenKeyWindow = false; } }
/// <summary> /// Key命令输入 /// </summary> /// <param name="no"></param> private void SetKeyCommand(string no) { // 重试 if (no == "Retry") { if (OperatesService.GetOperates().IsExpired || OperatesService.GetOperates().IsAdminUsing) { this.Key.KeyMsgMode = 0; this.MsgList.Clear(); this.Msg.AlertMsgMode = false; OperatesService.GetOperates().IsExpired = false; Resources.GetRes().SERVER_SESSION = null; _reLogin(); return; } else { Session.Instance.Keep(false); } } // 退出 else if (no == "Exit") { Exit(); } }
private void btnUpdate_Click(object sender, EventArgs e) { string value = "0"; if (!cbRemove.Checked) { if (string.IsNullOrWhiteSpace(txtId.Text) || string.IsNullOrWhiteSpace(txtInterval.Text) || string.IsNullOrWhiteSpace(txtZh.Text) || string.IsNullOrWhiteSpace(txtUg.Text) || string.IsNullOrWhiteSpace(txtEn.Text)) { KryptonMessageBox.Show(this, "请完整输入信息!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Scroll scroll = new Scroll(); scroll.Interval = int.Parse(txtInterval.Text); scroll.MsgZH = txtZh.Text; scroll.MsgUG = txtUg.Text; scroll.MsgEN = txtEn.Text; value = Encrypt(JsonConvert.SerializeObject(scroll), txtId.Text.Trim(), Encoding.UTF8.GetBytes("OybabCorp8888000")); } StartLoad(this, null); Task.Factory.StartNew(() => { try { string countent = null; bool result = OperatesService.GetOperates().ServiceSetContent(value, out countent, cbRemove.Checked, cbIsRestart.Checked); this.BeginInvoke(new Action(() => { if (result) { KryptonMessageBox.Show(this, Oybab.Res.Resources.GetRes().GetString("SaveSuccess"), Oybab.Res.Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { KryptonMessageBox.Show(this, Oybab.Res.Resources.GetRes().GetString("SaveFailt"), Oybab.Res.Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Oybab.Res.Resources.GetRes().GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); })); })); } StopLoad(this, null); }); }
private int Count = 0; //错误次数 /// <summary> /// 检测并提示用户! /// </summary> /// <param name="alert"></param> /// <param name="close"></param> public void CheckAndAlert(Action <string> alert, Action close = null) { do { //链接到服务器检测会话 bool IsSuccess = false; string message = null; try { IsSuccess = Res.Server.OperatesService.GetOperates().ServiceSession(true); } catch (Exception ex) { if (ex is OybabException) { message = ex.Message; } ExceptionPro.ExpLog(ex); } if (OperatesService.GetOperates().IsExpired || OperatesService.GetOperates().IsAdminUsing) { Count = 3; Session.Instance.ChangeInterval(false); } else if (!IsSuccess) { ++Count; Session.Instance.ChangeInterval(false); } else { Count = 0; Session.Instance.ChangeInterval(true); } if (Count >= 3) { if (null != alert) { alert(message); } } else { if (null != close) { close(); } break; } } while (1 == 1); }
protected void btnAdd_Click(object sender, EventArgs e) { OperatesService service = new OperatesService(); bool isOk = service.AddUser(int.Parse(ddlDepartment.SelectedValue)); if (isOk) { lblInfo.Text = "新增成功"; } else { lblError.Text = "新增失败"; } }
/// <summary> /// 加载 /// </summary> /// <param name="adminNo"></param> /// <param name="password"></param> /// <returns></returns> public ResultModel Load(string adminNo, string password) { ResultModel result = new ResultModel(); //自动校准服务器时间到客户端 if (Resources.GetRes().AutoSyncClientTime) { if (Resources.GetRes().SERVER_ADDRESS != "127.0.0.1" && Resources.GetRes().SERVER_ADDRESS != "::1") { SyncTime.GetSyncTime().SyncServerTimeToClient(); } } // 如果登录的IP是本地, 查看有没有服务, 有就查是否启动了, 没启动就启动它 if (Resources.GetRes().SERVER_ADDRESS == "127.0.0.1" || Resources.GetRes().SERVER_ADDRESS == "::1") { try { // 获取本地的服务 ServiceController ctl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == "OybabTradingSystemService"); if (ctl != null) { // 如果服务停止了, 则启动它 if (ctl.Status == ServiceControllerStatus.Stopped) { ctl.Start(); ctl.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 15)); } } } catch { } } //新请求 if (!Resources.GetRes().IsSessionExists()) { result = OperatesService.GetOperates().NewRequest(adminNo, password); } return(result); }
/// <summary> /// 消息命令输入 /// </summary> /// <param name="no"></param> private void SetMsgCommand(string no) { // 确定 if (no == "OK") { } // 是 else if (no == "Yes") { } // 否 else if (no == "No") { } PopupRoutedEventArgs popupArgs = MsgList.Dequeue(); if (null != popupArgs.Operate) { popupArgs.Operate(no); } if (OperatesService.GetOperates().IsExpired || OperatesService.GetOperates().IsAdminUsing) { this.Key.KeyMsgMode = 0; this.IsOpenKeyWindow = true; this.MsgList.Clear(); this.Msg.AlertMsgMode = false; OperatesService.GetOperates().IsExpired = false; Resources.GetRes().SERVER_SESSION = null; _reLogin(); return; } Msg.AlertMsgMode = false; InitialMsg(); }
/// <summary> /// 发送 /// </summary> private void Send(List <long> RoomsId, string ErrMsgName, int SendType, ExtendInfo info, Action success = null) { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOn)); Task.Factory.StartNew(() => { try { bool result = OperatesService.GetOperates().ServiceSend(RoomsId, SendType, JsonConvert.SerializeObject(info)); // 如果成功则提示 if (result) { _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, string.Format(Resources.GetRes().GetString("OperateSuccess"), ErrMsgName), (x) => { //if (x == "OK") //{ if (null != success) { success(); } //} }, PopupType.Information)); })); } } catch (Exception ex) { _element.Dispatcher.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, message, null, PopupType.Error)); }), false, string.Format(Resources.GetRes().GetString("OperateFaild"), ErrMsgName)); })); } _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOff)); })); }); }
private void btnDownload_Click(object sender, EventArgs e) { StartLoad(this, null); Task.Factory.StartNew(() => { try { string content = null; bool result = OperatesService.GetOperates().ServiceSetContent("-1", out content, false, false); this.BeginInvoke(new Action(() => { if (result) { content = Decrypt(content, txtId.Text.Trim(), Encoding.UTF8.GetBytes("OybabCorp8888000")); Scroll scroll = content.DeserializeObject <Scroll>(); txtInterval.Text = scroll.Interval.ToString(); txtZh.Text = scroll.MsgZH; txtUg.Text = scroll.MsgUG; txtEn.Text = scroll.MsgEN; } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Oybab.Res.Resources.GetRes().GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); })); })); } StopLoad(this, null); }); }
/// <summary> /// 修改服务端配置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void krpbChangeServer_Click(object sender, EventArgs e) { StartLoad(this, null); Task.Factory.StartNew(() => { try { bool result = OperatesService.GetOperates().ServiceSetCon(printInfo); this.BeginInvoke(new Action(() => { if (result) { krplPrintInfoAlert.Visible = false; krplGlobalSettingAlert.Visible = false; KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateSuccess"), Resources.GetRes().GetString("Change")), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateFaild"), Resources.GetRes().GetString("Change")), Resources.GetRes().GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Stop); } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); }
/// <summary> /// 初始化 /// </summary> public void Init() { AdminNo = ""; Password = ""; TempPassword = ""; IsDisPlayKeyboard = false; IsLoading = false; IsMsg = false; Msg = ""; AdminNoEnable = false; PasswordEnable = false; AlertMsg = ""; AlertMsgMode = 0; ClearFocus(); Common.GetCommon().ReadBak(); if (!string.IsNullOrWhiteSpace(Resources.GetRes().LastLoginAdminNo)) { AdminNo = Resources.GetRes().LastLoginAdminNo; } if (InitCount > 0) { HideSetting = true; if (OperatesService.GetOperates().IsAdminUsing) { OperatesService.GetOperates().IsAdminUsing = false; SystemSounds.Asterisk.Play(); IsMsg = true; Msg = string.Format(Resources.GetRes().GetString("Exception_AdminExists"), Common.GetCommon().GetFormat()); } } ++InitCount; }
/// <summary> /// 初始化 /// </summary> internal void InitBalance() { StartLoad(this, null); Task.Factory.StartNew(() => { try { List <Log> logs; List <Balance> Balances; bool result = OperatesService.GetOperates().ServiceGetLog(1, -1, 0, 0, out Balances, out logs); //如果验证成功 //修改成功 this.BeginInvoke(new Action(() => { if (result) { // 更新支付余额 ReloadBalanceList(Balances); } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); })); })); } StopLoad(this, null); }); }
/// <summary> /// 发送 /// </summary> private void Send(List <long> RoomsId, string ErrMsgName, int SendType, ExtendInfo info, Action success = null) { StartLoad(this, null); Task.Factory.StartNew(() => { try { bool result = OperatesService.GetOperates().ServiceSend(RoomsId, SendType, JsonConvert.SerializeObject(info)); // 如果成功则提示 if (result) { this.BeginInvoke(new Action(() => { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateSuccess"), ErrMsgName), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); if (null != success) { success(); } })); } } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, string.Format(Resources.GetRes().GetString("OperateFaild"), ErrMsgName)); })); } StopLoad(this, null); }); }
/// <summary> /// 从服务器刷新 /// </summary> /// <param name="RoomsId"></param> private void RefreshSomeFromServer(List <long> RoomsId) { Task.Factory.StartNew(() => { try { bool result = OperatesService.GetOperates().ServiceSession(false, RoomsId.ToArray()); // 如果成功, 则新增产品 if (result) { // 更新该订单信息 RefreshSome(RoomsId); } else { // 发出错误 _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("RefreshOrderFailed"), null, PopupType.Warn)); })); } } catch (Exception ex) { // 发出错误 ExceptionPro.ExpLog(ex, new Action <string>((message) => { _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, message, null, PopupType.Error)); })); }), false, Resources.GetRes().GetString("RefreshOrderFailed")); } }); }
/// <summary> /// 保存新增或改动的数据 /// </summary> private void Save() { if (null != krpdgList.SelectedRows[0]) { //如果是插入 if (krpdgList.SelectedRows[0].Cells["krpcmSupplierPayId"].Value.ToString().Equals("-1")) { SupplierPay supplierPay = new SupplierPay(); try { supplierPay.SupplierPayId = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmSupplierPayId"].Value.ToString()); supplierPay.Price = Math.Round(double.Parse(krpdgList.SelectedRows[0].Cells["krpcmPrice"].Value.ToString()), 2); supplierPay.BalanceId = GetBalanceTypeId(krpdgList.SelectedRows[0].Cells["krpcmBalanceType"].Value.ToString()); supplierPay.Remark = GetValueOrNull(krpdgList.SelectedRows[0].Cells["krpcmRemark"].Value.ToString()); supplierPay.SupplierId = this.Supplier.SupplierId; if (this.Supplier.IsAllowBorrow == 0 && this.Supplier.BalancePrice + supplierPay.Price < 0) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SupplierBalanceNotEnough"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); return; } StartLoad(this, null); Task.Factory.StartNew(() => { ResultModel result = new ResultModel(); double originalBalancePrice = Supplier.BalancePrice; try { Supplier.BalancePrice = Supplier.BalancePrice + supplierPay.Price; Supplier newSupplier; SupplierPay newSupplierPay; result = OperatesService.GetOperates().ServiceAddSupplierPay(Supplier, supplierPay, out newSupplier, out newSupplierPay); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); krpdgList.SelectedRows[0].Cells["krpcmSupplierPayId"].Value = newSupplierPay.SupplierPayId; krpdgList.SelectedRows[0].Cells["krpcmEdit"].Value = ""; krpdgList.SelectedRows[0].Cells["krpcmAddTime"].Value = DateTime.ParseExact(newSupplierPay.AddTime.ToString(), "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd HH:mm"); this.Supplier = newSupplier; this.ReturnValue = newSupplier; this.resultList.Insert(0, newSupplierPay); this.commonPayList.Insert(0, new CommonPayModel(newSupplierPay)); krpdgList.SelectedRows[0].Cells["krpcmPrice"].ReadOnly = true; krpdgList.SelectedRows[0].Cells["krpcmBalanceType"].ReadOnly = true; krpdgList.SelectedRows[0].Cells["krpcmRemark"].ReadOnly = true; krptbEndTime.Text = DateTime.Now.AddMinutes(5).ToString("yyyyMMddHHmm"); } else { if (result.IsDataHasRefrence) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUsed"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (result.UpdateModel) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUnSame"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { if (result.Result) { Supplier.BalancePrice = originalBalancePrice; } KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); } //如果是编辑 else { // 没有编辑, 也不能编辑 } } }
/// <summary> /// 删除数据 /// </summary> private void Delete() { long Id = -1; try { //确认删除 var confirm = KryptonMessageBox.Show(this, Resources.GetRes().GetString("SureDelete"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm != DialogResult.Yes) { return; } Id = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmRequestId"].Value.ToString()); //如果是没添加过的记录,就直接删除 if (Id == -1) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("DeleteSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); krpdgList.Rows.Remove(krpdgList.SelectedRows[0]); return; } //否则先删除数据库 } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("DeleteFailt")); return; } StartLoad(this, null); Task.Factory.StartNew(() => { try { ResultModel result = OperatesService.GetOperates().ServiceDelRequest(Resources.GetRes().Requests.Where(x => x.RequestId == Id).FirstOrDefault()); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("DeleteSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); Request oldModel = Resources.GetRes().Requests.Where(x => x.RequestId == Id).FirstOrDefault(); krpdgList.Rows.Remove(krpdgList.SelectedRows[0]); resultList.Remove(oldModel); Resources.GetRes().Requests.Remove(oldModel); ReloadRequestTextbox(); } else { if (result.IsDataHasRefrence) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUsed"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("DeleteFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("DeleteFailt")); })); } StopLoad(this, null); }); }
/// <summary> /// 查找 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void krpbSearch_Click(object sender, EventArgs e) { //为未保存数据而忽略当前操作 if (!IgnoreOperateForSave()) { return; } DateTime startDateTime = DateTime.Now; DateTime endDateTime = DateTime.Now; try { startDateTime = krptbStartTime.Value; endDateTime = krptbEndTime.Value; } catch (Exception ex) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("PropertyError"), Resources.GetRes().GetString("Time")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); ExceptionPro.ExpLog(ex); return; } if ((endDateTime - startDateTime).TotalMinutes <= 0 || !((endDateTime - startDateTime).TotalMinutes <= TimeLimit.TotalMinutes)) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("TimeLimit"), TimeLimit.TotalDays), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } long startTimeFinal = long.Parse(startDateTime.ToString("yyyyMMddHHmmss")); long endTimeFinal = long.Parse(endDateTime.ToString("yyyyMMddHHmmss")); long balanceType = krpcbPayType.SelectedIndex; StartLoad(this, null); Task.Factory.StartNew(() => { try { List <SupplierPay> supplierPays; List <ImportPay> importPays; bool result = OperatesService.GetOperates().ServiceGetSupplierPay(balanceType, Supplier.SupplierId, startTimeFinal, endTimeFinal, -1, out supplierPays, out importPays); this.BeginInvoke(new Action(() => { if (result) { List <CommonPayModel> commonPays = new List <CommonPayModel>(); commonPays.AddRange(importPays.Select(x => new CommonPayModel(x))); commonPays.AddRange(supplierPays.Select(x => new CommonPayModel(x))); this.resultList = supplierPays.OrderByDescending(x => x.SupplierPayId).ToList(); this.commonPayList = commonPays.OrderByDescending(x => x.AddTime).ToList(); //设定页面数据 ResetPage(); if (commonPayList.Count() > 0) { AllPage = (int)((commonPayList.Count() - 1 + ListCount) / ListCount); krplPageCount.Text = AllPage.ToString(); CurrentPage = 1; krptCurrentPage.Text = CurrentPage.ToString(); //打开第一页 OpenPageTo(CurrentPage, false); } else { krpdgList.Rows.Clear(); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, string.Format(Resources.GetRes().GetString("OperateFaild"), Resources.GetRes().GetString("Search"))); })); } StopLoad(this, null); // 防止滚动条比例没准确显示导致不显示底部的数据 this.BeginInvoke(new Action(() => { krpdgList.PerformLayout(); })); }); }
/// <summary> /// 初始化 /// </summary> internal void Init() { if (string.IsNullOrWhiteSpace(Resources.GetRes().RegTimeRequestCode)) { if (IsModalMode) { StartLoad(this, null); } else { //先不让用户单击按钮 krpbReg.Enabled = false; krpbClose.Enabled = false; krpbHelp.Enabled = false; } Task.Factory.StartNew(() => { try { bool result = OperatesService.GetOperates().ServiceRequestTimeCode(); //如果验证成功 //修改成功 this.BeginInvoke(new Action(() => { if (result) { krplRequestCodeValue.Text = Resources.GetRes().RegTimeRequestCode; } else { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("PropertyNotFound"), Resources.GetRes().GetString("MachineNo")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); })); })); } if (IsModalMode) { StopLoad(this, null); } else { this.BeginInvoke(new Action(() => { krpbReg.Enabled = true; krpbClose.Enabled = true; krpbHelp.Enabled = true; })); } }); } else { krplRequestCodeValue.Text = Resources.GetRes().RegTimeRequestCode; } }
/// <summary> /// 保存新增或改动的数据 /// </summary> private void Save() { if (null != krpdgList.SelectedRows[0]) { //如果是插入 if (krpdgList.SelectedRows[0].Cells["krpcmRequestId"].Value.ToString().Equals("-1")) { Request model = new Request(); try { // 隐藏功能时先把必要的复制掉(比如语言) Common.GetCommon().CopyForHide(krpdgList.SelectedRows[0].Cells["krpcmRequestName0"], krpdgList.SelectedRows[0].Cells["krpcmRequestName1"], krpdgList.SelectedRows[0].Cells["krpcmRequestName2"], true, false, krpcbMultipleLanguage.Checked); model.RequestId = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmRequestId"].Value.ToString()); model.RequestName0 = krpdgList.SelectedRows[0].Cells["krpcmRequestName0"].Value.ToString().Trim(); model.RequestName1 = krpdgList.SelectedRows[0].Cells["krpcmRequestName1"].Value.ToString().Trim(); model.RequestName2 = krpdgList.SelectedRows[0].Cells["krpcmRequestName2"].Value.ToString().Trim(); model.Order = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmOrder"].Value.ToString()); model.IsEnable = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmIsEnable"].Value.ToString()); //判断空 if (string.IsNullOrWhiteSpace(model.RequestName0) || string.IsNullOrWhiteSpace(model.RequestName1) || string.IsNullOrWhiteSpace(model.RequestName2)) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("CompleteInput"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //判断是否已存在 if (Resources.GetRes().Requests.Where(x => (x.RequestName0.Equals(model.RequestName0, StringComparison.OrdinalIgnoreCase) || x.RequestName1.Equals(model.RequestName1, StringComparison.OrdinalIgnoreCase) || x.RequestName2.Equals(model.RequestName2, StringComparison.OrdinalIgnoreCase))).Count() > 0) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("PropertyExists"), Resources.GetRes().GetString("RequestName")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); return; } StartLoad(this, null); Task.Factory.StartNew(() => { try { bool result = OperatesService.GetOperates().ServiceAddRequest(model); this.BeginInvoke(new Action(() => { if (result) { krpdgList.SelectedRows[0].Cells["krpcmRequestId"].Value = model.RequestId; KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); krpdgList.SelectedRows[0].Cells["krpcmEdit"].Value = ""; resultList.Insert(0, model); Resources.GetRes().Requests.Add(model); ReloadRequestTextbox(); } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); } //如果是编辑 else { Request model = new Request(); try { model.RequestId = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmRequestId"].Value.ToString()); model = Resources.GetRes().Requests.Where(x => x.RequestId == model.RequestId).FirstOrDefault().FastCopy(); // 隐藏功能时先把必要的复制掉(比如语言) Common.GetCommon().CopyForHide(krpdgList.SelectedRows[0].Cells["krpcmRequestName0"], krpdgList.SelectedRows[0].Cells["krpcmRequestName1"], krpdgList.SelectedRows[0].Cells["krpcmRequestName2"], false, Ext.AllSame(model.RequestName0, model.RequestName1, model.RequestName2), krpcbMultipleLanguage.Checked); model.RequestName0 = krpdgList.SelectedRows[0].Cells["krpcmRequestName0"].Value.ToString().Trim(); model.RequestName1 = krpdgList.SelectedRows[0].Cells["krpcmRequestName1"].Value.ToString().Trim(); model.RequestName2 = krpdgList.SelectedRows[0].Cells["krpcmRequestName2"].Value.ToString().Trim(); model.Order = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmOrder"].Value.ToString()); model.IsEnable = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmIsEnable"].Value.ToString()); //判断空 if (string.IsNullOrWhiteSpace(model.RequestName0) || string.IsNullOrWhiteSpace(model.RequestName1) || string.IsNullOrWhiteSpace(model.RequestName2)) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("CompleteInput"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //判断是否已存在 if (Resources.GetRes().Requests.Where(x => x.RequestId != model.RequestId && (x.RequestName0.Equals(model.RequestName0, StringComparison.OrdinalIgnoreCase) || x.RequestName1.Equals(model.RequestName1, StringComparison.OrdinalIgnoreCase) || x.RequestName2.Equals(model.RequestName2, StringComparison.OrdinalIgnoreCase))).Count() > 0) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("PropertyExists"), Resources.GetRes().GetString("RequestName")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); return; } StartLoad(this, null); Task.Factory.StartNew(() => { try { ResultModel result = OperatesService.GetOperates().ServiceEditRequest(model); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); krpdgList.SelectedRows[0].Cells["krpcmEdit"].Value = ""; Request oldModel = resultList.Where(x => x.RequestId == model.RequestId).FirstOrDefault(); int no = resultList.IndexOf(oldModel); resultList.RemoveAt(no); resultList.Insert(no, model); no = Resources.GetRes().Requests.IndexOf(oldModel); Resources.GetRes().Requests.RemoveAt(no); Resources.GetRes().Requests.Insert(no, model); ReloadRequestTextbox(); } else { if (result.UpdateModel) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUnSame"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); } } }
/// <summary> /// 增加会员支付 /// </summary> private void AddMemberPay() { MemberPay memberpay = new MemberPay(); memberpay.MemberPayId = -1; memberpay.Price = Math.Round(double.Parse(NewPrice), 2); memberpay.MemberId = this.member.MemberId; _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOn)); Task.Factory.StartNew(() => { ResultModel result = new ResultModel(); double originalBalancePrice = member.BalancePrice; try { member.BalancePrice = member.BalancePrice + memberpay.Price; Member newMember; MemberPay newMemberPay; result = OperatesService.GetOperates().ServiceAddMemberPay(member, memberpay, out newMember, out newMemberPay); _element.Dispatcher.BeginInvoke(new Action(() => { if (result.Result) { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("SaveSuccess"), null, PopupType.Information)); this.member = newMember; if (null != Recalc) { Recalc(this.member); } this.Hide(); } else { if (result.IsDataHasRefrence) { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("PropertyUsed"), null, PopupType.Warn)); } else if (result.UpdateModel) { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("PropertyUsed"), null, PopupType.Warn)); } else { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("SaveFailt"), null, PopupType.Warn)); } } })); } catch (Exception ex) { _element.Dispatcher.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { if (result.Result) { member.BalancePrice = originalBalancePrice; } _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, message, null, PopupType.Error)); }), false, Resources.GetRes().GetString("SaveFailt")); })); } _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOff)); })); }); }
/// <summary> /// 注册时间 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void krpbReg_Click(object sender, EventArgs e) { //判断是否空 if (krptRegCode.Text.Trim().Equals("")) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("LoginValid"), krplRegCode.Text), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (IsModalMode) { StartLoad(this, null); } else { //先不让用户单击按钮 krpbReg.Enabled = false; krpbClose.Enabled = false; krpbHelp.Enabled = false; } Task.Factory.StartNew(() => { try { bool result = OperatesService.GetOperates().ServiceRegTime(krptRegCode.Text.Trim()); //如果验证成功 //修改成功 this.BeginInvoke(new Action(() => { if (result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("RegisterSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); System.Environment.Exit(0); } else { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateFaild"), Resources.GetRes().GetString("Register")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); })); })); } if (IsModalMode) { StopLoad(this, null); } else { this.BeginInvoke(new Action(() => { krpbReg.Enabled = true; krpbClose.Enabled = true; krpbHelp.Enabled = true; })); } }); } }
/// <summary> /// 删除数据 /// </summary> private void Delete() { long Id = -1; try { //确认删除 var confirm = KryptonMessageBox.Show(this, Resources.GetRes().GetString("SureDelete"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm != DialogResult.Yes) { return; } Id = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmSupplierPayId"].Value.ToString()); //如果是没添加过的记录,就直接删除 if (Id == -1) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("DeleteSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); krpdgList.Rows.Remove(krpdgList.SelectedRows[0]); return; } } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("DeleteFailt")); return; } StartLoad(this, null); Task.Factory.StartNew(() => { SupplierPay supplierPay = resultList.Where(x => x.SupplierPayId == Id).FirstOrDefault(); double originalBalancePrice = Supplier.BalancePrice; ResultModel result = new ResultModel(); try { Supplier.BalancePrice = Supplier.BalancePrice - supplierPay.Price; Supplier newSupplier; result = OperatesService.GetOperates().ServiceDelSupplierPay(Supplier, supplierPay, out newSupplier); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("DeleteSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); SupplierPay oldModel = resultList.Where(x => x.SupplierPayId == Id).FirstOrDefault(); krpdgList.Rows.Remove(krpdgList.SelectedRows[0]); resultList.Remove(oldModel); CommonPayModel oldCommonModel = this.commonPayList.Where(x => x.PayId == Id && x.Type == "SupplierPay").FirstOrDefault(); commonPayList.Remove(oldCommonModel); this.ReturnValue = newSupplier; this.Supplier = newSupplier; } else { if (result.IsDataHasRefrence) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUsed"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (result.UpdateModel) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUnSame"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("DeleteFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { if (result.Result) { Supplier.BalancePrice = originalBalancePrice; } KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("DeleteFailt")); })); } StopLoad(this, null); }); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void krpbSave_Click(object sender, EventArgs e) { long newRoomId = Resources.GetRes().RoomsModel.Where(x => x.RoomNo == krpcbNewRoom.SelectedItem.ToString()).Select(x => x.RoomId).FirstOrDefault(); string ErrMsgName, SucMsgName; ErrMsgName = SucMsgName = Resources.GetRes().GetString("ReplaceRoom"); string oldRoomSessionResult, newRoomSessionResult; StartLoad(this, null); Task.Factory.StartNew(() => { try { RoomModel newModel = Resources.GetRes().RoomsModel.Where(x => x.RoomId == newRoomId).FirstOrDefault(); ICollection <OrderDetail> oldOrderDetails = null; ICollection <OrderDetail> newOrderDetails = null; ICollection <OrderPay> oldOrderPays = null; ICollection <OrderPay> newOrderPays = null; if (null != oldModel.PayOrder && null != oldModel.PayOrder.tb_orderdetail) { oldOrderDetails = oldModel.PayOrder.tb_orderdetail; } if (null != newModel.PayOrder && null != newModel.PayOrder.tb_orderdetail) { newOrderDetails = newModel.PayOrder.tb_orderdetail; } if (null != oldModel.PayOrder && null != oldModel.PayOrder.tb_orderpay) { oldOrderPays = oldModel.PayOrder.tb_orderpay; } if (null != newModel.PayOrder && null != newModel.PayOrder.tb_orderpay) { newOrderPays = newModel.PayOrder.tb_orderpay; } Room oldRoom = Resources.GetRes().Rooms.Where(x => x.RoomId == oldModel.RoomId).FirstOrDefault(); Room newRoom = Resources.GetRes().Rooms.Where(x => x.RoomId == newRoomId).FirstOrDefault(); Order oldOrder = oldModel.PayOrder; Order newOrder = newModel.PayOrder; // 重新根据彼此的信息完全复制订单信息 Order tempOldOrder = new Order(); Order tempNewOrder = new Order(); // 更新老订单包厢价格信息 if (null != oldOrder) { tempNewOrder = ReCalcOrder(oldOrder, newOrder, oldRoom, newRoom); } // 更新新订单包厢价格信息 if (null != newOrder) { tempOldOrder = ReCalcOrder(newOrder, oldOrder, newRoom, oldRoom); } ResultModel result = OperatesService.GetOperates().ServiceReplaceOrder(oldModel.RoomId, newRoomId, tempOldOrder, tempNewOrder, oldModelSession, newModel.OrderSession, out oldRoomSessionResult, out newRoomSessionResult); if (result.Result) { long tempOld = 0; long tempNew = 0; if (null != oldOrder) { tempOld = oldOrder.RoomId; } else { tempOld = oldModel.RoomId; } if (null != newOrder) { tempNew = newOrder.RoomId; } else { tempNew = newModel.RoomId; } if (null != oldOrder) { oldOrder.RoomId = tempNew; } if (null != newOrder) { newOrder.RoomId = tempOld; } //删除老的房间中的订单并替换新的 if (null != tempNewOrder && tempNewOrder.OrderId > 0) { newModel.PayOrder = tempNewOrder; } else { newModel.PayOrder = null; } //删除新的订单中的订单并替换老的 if (null != tempOldOrder && tempOldOrder.OrderId > 0) { oldModel.PayOrder = tempOldOrder; } else { oldModel.PayOrder = null; } oldModel.OrderSession = oldRoomSessionResult; newModel.OrderSession = newRoomSessionResult; // 恢复对应的订单详情 if (null != oldOrderDetails) { newModel.PayOrder.tb_orderdetail = oldOrderDetails; } if (null != newOrderDetails) { oldModel.PayOrder.tb_orderdetail = newOrderDetails; } if (null != oldOrderPays) { newModel.PayOrder.tb_orderpay = oldOrderPays; } if (null != newOrderPays) { oldModel.PayOrder.tb_orderpay = newOrderPays; } } this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateSuccess"), SucMsgName), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); ReturnValue = newRoomId; DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } else { if (result.IsRefreshSessionModel) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("FaildThenRefreshModel"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); if (oldRoomSessionResult == "-1") { ReturnValue = oldModel.RoomId; } else if (newRoomSessionResult == "-1") { ReturnValue = newRoomId; } DialogResult = System.Windows.Forms.DialogResult.Retry; this.Close(); } else if (result.IsSessionModelSameTimeOperate) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("FaildThenWaitRetry"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateFaild"), ErrMsgName), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, string.Format(Resources.GetRes().GetString("OperateFaild"), ErrMsgName)); })); } StopLoad(this, null); }); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void krpbSave_Click(object sender, EventArgs e) { double price = double.Parse(krptChangePrice.Text); if (price <= 0) { return; } string newBalanceName = krpcbNewBalanceName.SelectedItem.ToString(); if (Resources.GetRes().MainLangIndex == 0) { NewBalance = Resources.GetRes().Balances.Where(x => x.BalanceName0 == newBalanceName).FirstOrDefault(); } else if (Resources.GetRes().MainLangIndex == 1) { NewBalance = Resources.GetRes().Balances.Where(x => x.BalanceName1 == newBalanceName).FirstOrDefault(); } else if (Resources.GetRes().MainLangIndex == 2) { NewBalance = Resources.GetRes().Balances.Where(x => x.BalanceName2 == newBalanceName).FirstOrDefault(); } BalancePay balancePay1 = new BalancePay(); balancePay1.BalanceId = NewBalance.BalanceId; balancePay1.Price = price; BalancePay balancePay2 = new BalancePay(); balancePay2.BalanceId = OldBalance.BalanceId; balancePay2.Price = -price; StartLoad(this, null); Task.Factory.StartNew(() => { ResultModel result = new ResultModel(); try { BalancePay newBalancePay1; BalancePay newBalancePay2; Balance newBalance1; Balance newBalance2; result = OperatesService.GetOperates().ServiceTransferBalancePay(balancePay1, balancePay2, out newBalancePay1, out newBalance1, out newBalancePay2, out newBalance2); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); ReturnValue = true; this.Close(); } else { if (result.IsDataHasRefrence) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUsed"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (result.UpdateModel) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUnSame"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); }
/// <summary> /// 结账 /// </summary> private void Checkout() { order.State = 1; bool IsRechecked = false; string newRoomSessionId; string ErrMsgName, SucMsgName; ErrMsgName = SucMsgName = Resources.GetRes().GetString("CheckoutOrder"); if (order.Remark != ChangePaidPrice.Remark) { if (!string.IsNullOrWhiteSpace(ChangePaidPrice.Remark)) { order.Remark = this.ChangePaidPrice.Remark; } else { order.Remark = null; } } _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOn)); Task.Factory.StartNew(() => { ResultModel result = new ResultModel(); try { long UpdateTime; result = OperatesService.GetOperates().ServiceEditOrder(order, null, tempPayList.Where(x => x.AddTime == 0).Select(x => { x.OrderId = order.OrderId; return(x); }).ToList(), RoomSession, IsRechecked, out newRoomSessionId, out UpdateTime); if (result.Result) { if (!IsRechecked) { RoomModel model = Resources.GetRes().RoomsModel.Where(x => x.RoomId == RoomId).FirstOrDefault(); model.OrderSession = newRoomSessionId; model.PayOrder = null; if (Resources.GetRes().CallNotifications.ContainsKey(RoomId)) { Resources.GetRes().CallNotifications.Remove(RoomId); } // 更新会员信息 foreach (var item in tempPayList.Where(x => x.AddTime == 0)) { if (null != item.MemberId) { Notification.Instance.ActionMember(this, new Member() { MemberId = item.MemberId.Value }, null); } } } } _element.Dispatcher.BeginInvoke(new Action(() => { if (result.Result) { Print.Instance.PrintOrderAfterCheckout(order, details); _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, string.Format(Resources.GetRes().GetString("OperateSuccess"), SucMsgName), (x) => { if (x == "OK") { _element.RaiseEvent(new ForwardRoutedEventArgs(PublicEvents.ForwardEvent, null, PageType.Room, (long)-1)); } }, PopupType.Information)); } else { if (result.IsRefreshSessionModel) { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("FaildThenRefreshModel"), null, PopupType.Warn)); _element.RaiseEvent(new ForwardRoutedEventArgs(PublicEvents.ForwardEvent, null, PageType.Room, this.RoomId)); } else if (result.IsSessionModelSameTimeOperate) { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, Resources.GetRes().GetString("FaildThenWaitRetry"), null, PopupType.Warn)); } else { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, string.Format(Resources.GetRes().GetString("OperateFaild"), ErrMsgName), null, PopupType.Warn)); } } })); } catch (Exception ex) { _element.Dispatcher.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, message, null, PopupType.Error)); }), false, string.Format(Resources.GetRes().GetString("OperateFaild"), ErrMsgName)); })); } _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOff)); })); }); }
/// <summary> /// 处理睡眠或者环形 /// </summary> /// <param name="s"></param> /// <param name="e"></param> private void SystemEvents_PowerModeChanged(object s, PowerModeChangedEventArgs e) { switch (e.Mode) { case PowerModes.Resume: if (Resources.GetRes().IsSessionExists()) { OperatesService.GetOperates().AbortService(); _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOn)); })); Task.Factory.StartNew(() => { // 刚启动时给点时间网络连接好 System.Threading.Thread.Sleep(3000); try { OperatesService.GetOperates().ServiceSession(false, null, true); } catch (Exception ex) { ExceptionPro.ExpLog(ex); } finally { if (OperatesService.GetOperates().IsExpired || OperatesService.GetOperates().IsExpired) { _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOff)); this.Key.KeyMsgMode = 0; this.IsOpenKeyWindow = true; this.MsgList.Clear(); this.Msg.AlertMsgMode = false; OperatesService.GetOperates().IsExpired = false; Resources.GetRes().SERVER_SESSION = null; _reLogin(); return; })); } else { System.Threading.Thread.Sleep(1000); if (_refreshRoomList != null) { _refreshRoomList(); } _element.Dispatcher.BeginInvoke(new Action(() => { _element.RaiseEvent(new PopupRoutedEventArgs(PublicEvents.PopupEvent, null, null, null, PopupType.AnimationOff)); })); } Session.Instance.Start(); } }); } break; case PowerModes.Suspend: Session.Instance.Stop(); if (Resources.GetRes().IsSessionExists()) { OperatesService.GetOperates().AbortService(); } break; } }
/// <summary> /// 结账 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void krpbCheckout_Click(object sender, EventArgs e) { //余额不平确认 if (order.BorrowPrice != 0 || order.KeepPrice != 0) { var confirm = KryptonMessageBox.Show(this, Resources.GetRes().GetString("ConfirmBalanceInjustice"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm != DialogResult.Yes) { return; } } // 退的钱如果比付的钱还要多(就看是否允许退钱了) if (!Common.GetCommon().IsReturnMoney() && Math.Round(tempPayList.Sum(x => x.OriginalPrice), 2) < 0) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("CanNotExceed"), Math.Round(tempPayList.Sum(x => x.OriginalPrice), 2)), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (order.PaidPrice == 0 && order.MemberPaidPrice == 0) { var confirm = KryptonMessageBox.Show(this, Resources.GetRes().GetString("ConfirmNotPay"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm != DialogResult.Yes) { return; } } order.State = 1; string newRoomSessionId; string ErrMsgName, SucMsgName; ErrMsgName = SucMsgName = Resources.GetRes().GetString("CheckoutOrder"); StartLoad(this, null); Task.Factory.StartNew(() => { ResultModel result = new ResultModel(); bool IsClose = false; try { long UpdateTime; result = OperatesService.GetOperates().ServiceEditOrder(order, null, tempPayList.Where(x => x.AddTime == 0).Select(x => { x.OrderId = order.OrderId; return(x); }).ToList(), RoomSession, IsRechecked, out newRoomSessionId, out UpdateTime); if (result.Result) { if (!IsRechecked) { RoomModel model = Resources.GetRes().RoomsModel.Where(x => x.RoomId == RoomId).FirstOrDefault(); model.OrderSession = newRoomSessionId; model.PayOrder = null; if (Resources.GetRes().CallNotifications.ContainsKey(RoomId)) { Resources.GetRes().CallNotifications.Remove(RoomId); } // 更新会员信息 foreach (var item in tempPayList.Where(x => x.AddTime == 0)) { if (null != item.MemberId) { Notification.Instance.ActionMember(this, new Member() { MemberId = item.MemberId.Value }, null); } } } } this.BeginInvoke(new Action(() => { if (result.Result) { Print.Instance.PrintOrderAfterCheckout(order, details); KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateSuccess"), SucMsgName), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = System.Windows.Forms.DialogResult.OK; IsClose = true; } else { if (result.IsRefreshSessionModel) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("FaildThenRefreshModel"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); DialogResult = System.Windows.Forms.DialogResult.Retry; IsClose = true; } else if (result.IsSessionModelSameTimeOperate) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("FaildThenWaitRetry"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("OperateFaild"), ErrMsgName), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, string.Format(Resources.GetRes().GetString("OperateFaild"), ErrMsgName)); })); } if (IsClose) { this.BeginInvoke(new Action(() => { this.Close(); })); } StopLoad(this, null); }); }
/// <summary> /// 保存新增或改动的数据 /// </summary> private void Save() { if (null != krpdgList.SelectedRows[0]) { //如果是插入 if (krpdgList.SelectedRows[0].Cells["krpcmAdminLogId"].Value.ToString().Equals("-1")) { AdminLog model = new AdminLog(); try { model.AdminLogId = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmAdminLogId"].Value.ToString()); model.LogTitle = krpdgList.SelectedRows[0].Cells["krpcmLogTitle"].Value.ToString().Trim(); model.LogContent = GetValueOrNull(krpdgList.SelectedRows[0].Cells["krpcmLogContent"].Value.ToString()); //判断空 if (string.IsNullOrWhiteSpace(model.LogTitle)) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("CompleteInput"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); return; } StartLoad(this, null); Task.Factory.StartNew(() => { try { bool result = OperatesService.GetOperates().ServiceAddAdminLog(model); this.BeginInvoke(new Action(() => { if (result) { krpdgList.SelectedRows[0].Cells["krpcmAdminLogId"].Value = model.AdminLogId; KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); krpdgList.SelectedRows[0].Cells["krpcmEdit"].Value = ""; resultList.Insert(0, model); krpdgList.SelectedRows[0].ReadOnly = true; } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); } //如果是编辑 else { AdminLog model = new AdminLog(); try { model.AdminLogId = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmAdminLogId"].Value.ToString()); model = this.resultList.Where(x => x.AdminLogId == model.AdminLogId).FirstOrDefault().FastCopy(); model.AdminLogId = long.Parse(krpdgList.SelectedRows[0].Cells["krpcmAdminLogId"].Value.ToString()); model.LogTitle = krpdgList.SelectedRows[0].Cells["krpcmLogTitle"].Value.ToString().Trim(); model.LogContent = GetValueOrNull(krpdgList.SelectedRows[0].Cells["krpcmLogContent"].Value.ToString()); //判断空 if (string.IsNullOrWhiteSpace(model.LogTitle)) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("CompleteInput"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); return; } StartLoad(this, null); Task.Factory.StartNew(() => { try { ResultModel result = OperatesService.GetOperates().ServiceEditAdminLog(model); this.BeginInvoke(new Action(() => { if (result.Result) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveSuccess"), Resources.GetRes().GetString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information); krpdgList.SelectedRows[0].Cells["krpcmEdit"].Value = ""; AdminLog oldModel = resultList.Where(x => x.AdminLogId == model.AdminLogId).FirstOrDefault(); int no = resultList.IndexOf(oldModel); resultList.RemoveAt(no); resultList.Insert(no, model); } else { if (result.UpdateModel) { KryptonMessageBox.Show(this, Resources.GetRes().GetString("PropertyUnSame"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { KryptonMessageBox.Show(this, Resources.GetRes().GetString("SaveFailt"), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, Resources.GetRes().GetString("SaveFailt")); })); } StopLoad(this, null); }); } } }
/// <summary> /// 查找 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void krpbSearch_Click(object sender, EventArgs e) { //为未保存数据而忽略当前操作 if (!IgnoreOperateForSave()) { return; } DateTime startDateTime = DateTime.Now; DateTime endDateTime = DateTime.Now; try { startDateTime = krptbStartTime.Value; endDateTime = krptbEndTime.Value; } catch (Exception ex) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("PropertyError"), Resources.GetRes().GetString("Time")), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); ExceptionPro.ExpLog(ex); return; } if ((endDateTime - startDateTime).TotalMinutes <= 0 || !((endDateTime - startDateTime).TotalMinutes <= TimeLimit.TotalMinutes)) { KryptonMessageBox.Show(this, string.Format(Resources.GetRes().GetString("TimeLimit"), TimeLimit.TotalDays), Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } long addTimeStart = long.Parse(startDateTime.ToString("yyyyMMddHHmmss")); long addTimeEnd = long.Parse(endDateTime.ToString("yyyyMMddHHmmss")); StartLoad(this, null); Task.Factory.StartNew(() => { try { List <Log> logs; List <Balance> Balances; bool result = OperatesService.GetOperates().ServiceGetLog(2, 1, addTimeStart, addTimeEnd, out Balances, out logs); this.BeginInvoke(new Action(() => { if (result) { // 更新支付余额 ReloadBalanceList(Balances); this.resultList = logs.OrderBy(x => x.AddTime).ThenBy(x => x.LogId).ToList(); //设定页面数据 ResetPage(); if (resultList.Count() > 0) { AllPage = (int)((resultList.Count() - 1 + ListCount) / ListCount); krplPageCount.Text = AllPage.ToString(); CurrentPage = 1; krptCurrentPage.Text = CurrentPage.ToString(); //打开第一页 OpenPageTo(CurrentPage, false); } else { krpdgList.Rows.Clear(); } } })); } catch (Exception ex) { this.BeginInvoke(new Action(() => { ExceptionPro.ExpLog(ex, new Action <string>((message) => { KryptonMessageBox.Show(this, message, Resources.GetRes().GetString("Warn"), MessageBoxButtons.OK, MessageBoxIcon.Warning); }), false, string.Format(Resources.GetRes().GetString("OperateFaild"), Resources.GetRes().GetString("Search"))); })); } StopLoad(this, null); // 防止滚动条比例没准确显示导致不显示底部的数据 this.BeginInvoke(new Action(() => { krpdgList.PerformLayout(); })); }); }
/// <summary> /// 初始化机器码 /// </summary> internal void InitMachineNo() { if ((RegType == 0 && string.IsNullOrWhiteSpace(Resources.GetRes().RegTimeRequestCode)) || (RegType == 1 && string.IsNullOrWhiteSpace(Resources.GetRes().RegCountRequestCode))) { IsLoading = true; Task.Factory.StartNew(() => { try { bool result = false; if (RegType == 0) { result = OperatesService.GetOperates().ServiceRequestTimeCode(); } else if (RegType == 1) { result = OperatesService.GetOperates().ServiceRequestTimeCode(); } //如果验证成功 if (result) { if (RegType == 0) { MachineNo = Resources.GetRes().RegTimeRequestCode; } else if (RegType == 1) { MachineNo = Resources.GetRes().RegCountRequestCode; } } else { IsMsg = true; Msg = string.Format(Resources.GetRes().GetString("PropertyNotFound"), Resources.GetRes().GetString("MachineNo")); } } catch (Exception ex) { ExceptionPro.ExpLog(ex, new Action <string>((message) => { IsMsg = true; Msg = message; })); } IsLoading = false; }); } else { if (RegType == 0) { MachineNo = Resources.GetRes().RegTimeRequestCode; } else if (RegType == 1) { MachineNo = Resources.GetRes().RegCountRequestCode; } } }