Example #1
0
        private void BtnSingleRowDelete_Click(object sender, RoutedEventArgs e)
        {
            if (MainDataGrid.SelectedItems.Count == 1)
            {
                LabelPrintCurrencyModel model = MainDataGrid.SelectedItem as LabelPrintCurrencyModel;
                if (model.PrintStatus == "未打印")
                {
                    MessageBox.Show("只能删除已打印数据");
                    return;
                }

                string r = new LabelPrintService().DeleteCurrentPrintData(model.ID);
                if (r != null)
                {
                    (this.MainDataGrid.ItemsSource as ObservableCollection <LabelPrintCurrencyModel>).Remove(model);
                    //CurrentRecords.Remove(model);
                    this.MainDataGrid.SelectedItem = null;
                    // 删除日志
                    new LabelPrintService().DeletePrintLog(new List <int> {
                        model.ID
                    });
                    isRefreshParentDataGrid = true;
                    MessageBox.Show(r);
                    return;
                }
                MessageBox.Show("删除失败,请联系管理员");
            }
            else
            {
                MessageBox.Show("删除失败:请先选中数据,有且仅有1条数据");
            }
        }
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            var item = this.MainDataGrid.SelectedItem as QuerySchemaConfigModel;

            if (item == null)
            {
                MessageBox.Show("请先选择行");
                return;
            }

            string r = new LabelPrintService().DeleteQuerySchemaEntry(item.Id);

            if (r == null)
            {
                SchemaEntries.Remove(item);
                //界面也要移除
                (this.MainDataGrid.ItemsSource as ObservableCollection <QuerySchemaConfigModel>).Remove(item);
                this.MainDataGrid.SelectedItem = null;
                MessageBox.Show("删除成功");
            }
            else
            {
                MessageBox.Show(r);
            }
        }
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (int.TryParse(this.LastPrintCount.Text, out int count))
                {
                    int    id  = int.Parse(this.ID.Text);
                    string seq = this.Seq.Text;
                    if (!string.IsNullOrEmpty(seq))
                    {
                        _window.PrintCount = count;
                    }
                    MessageBoxResult result = MessageBox.Show($" 确认修改 开始序号为【 {seq} 】的标签  连续打印张数【 {count} 】张,", "温馨提示", MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.Yes)
                    {
                        int rows = new LabelPrintService().ModifyHistoryDataByID(id, count, seq);

                        if (rows == 1)
                        {
                            this.Close();
                            //RefreshEvent();
                            MessageBox.Show("保存成功");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("请输入正确的数字");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            var seq  = RequestNames.Max(m => m.RequestSeq) + 1;
            var name = this.TbRequestName.Text;

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("名称不能为空");
                return;
            }
            var model = new CbRequestNameModel {
                RequestSeq  = seq,
                RequestName = name,
            };

            string r = new LabelPrintService().AddRequestName(model);

            if (string.IsNullOrEmpty(r))
            {
                RequestNames.Insert(0, model);
                MessageBox.Show("添加成功");
            }
            else
            {
                MessageBox.Show(r);
            }
        }
Example #5
0
        private void BtnBatchNoDelete_Click(object sender, RoutedEventArgs e)
        {
            if (MainDataGrid.SelectedItems.Count == 1)
            {
                LabelPrintCurrencyModel model = MainDataGrid.SelectedItem as LabelPrintCurrencyModel;
                if (model.PrintStatus == "未打印")
                {
                    MessageBox.Show("只能删除已打印数据");
                    return;
                }
                var itemSource = MainDataGrid.ItemsSource as ObservableCollection <LabelPrintCurrencyModel>;

                List <int> ids = itemSource.Where(m => m.CreateTime == model.CreateTime && m.BatchNo == model.BatchNo).Select(m => m.ID).ToList <int>();

                string r = new LabelPrintService().BatchDeleteCurrentPrintData(ids);
                if (r != null)
                {
                    for (int i = 0; i < itemSource.Count; i++)
                    {
                        DateTime time    = itemSource[i].CreateTime;
                        string   batchno = itemSource[i].BatchNo;
                        // 默认提取数据是按添加时间降序
                        if (time > model.CreateTime)
                        {
                            continue;
                        }
                        else if (time == model.CreateTime)
                        {
                            if (batchno == model.BatchNo)
                            {
                                itemSource.RemoveAt(i);
                                i--;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    this.MainDataGrid.SelectedItem = null;
                    // 删除日志
                    new LabelPrintService().DeletePrintLog(ids);
                    isRefreshParentDataGrid = true;
                    MessageBox.Show(r);
                    return;
                }
                MessageBox.Show("删除失败,请联系管理员");
            }
            else
            {
                MessageBox.Show("删除失败:有且仅有1条数据");
            }
        }
        private void InitCommand()
        {
            SaveCommand = new DelegateCommand((obj) =>
            {
                //验证数据是否异常
                var r = CommonAdjustmentLists.GroupBy(x => new { x.TypeId, x.OrgId, x.Label }).Select(x => new { Rc = x.Count() });
                if (!r.Any(x => x.Rc > 1))
                {
                    // 将界面数据插入到后台
                    CommonService.LoadIEnumerableToDatabase2(CommonAdjustmentLists, "SJPrintCommonAdjustment", true);

                    // 将之前的后台数据删除
                    var ids = string.Join(",", CommonAdjustmentLists.Where(x => x.Id > 0).Select(x => x.Id));
                    if (!string.IsNullOrEmpty(ids))
                    {
                        LabelPrintService.DeletePrintCommonAdjustment(ids);
                    }
                    QueryBaseCommand.Execute(null);
                }
                else
                {
                    MessageBox.Show("类型+客户+标签 必须唯一");
                }
            });

            RemoveCommand = new DelegateCommand((obj) =>
            {
                if (PrintCommonAdjustmentSelectedItem != null)
                {
                    int id = PrintCommonAdjustmentSelectedItem.Id;
                    CommonAdjustmentLists.Remove(PrintCommonAdjustmentSelectedItem);
                    if (id > 0)
                    {
                        LabelPrintService.DeletePrintCommonAdjustment(id);
                    }
                }
            });

            CopyCommand = new DelegateCommand((obj) =>
            {
                var cloneData = PrintCommonAdjustmentSelectedItem == null ? new PrintCommonAdjustmentModel() : ObjectDeepCopyHelper <PrintCommonAdjustmentModel, PrintCommonAdjustmentModel> .Trans(PrintCommonAdjustmentSelectedItem);
                cloneData.Id  = 0;
                CommonAdjustmentLists.Insert(0, cloneData);
            });


            QueryBaseCommand = new DelegateCommand((obj) =>
            {
                CommonAdjustmentLists.Clear();
                LabelPrintService.GetLists(CommonService.GetSqlWhereString(QueryParameter)).ForEach(x => CommonAdjustmentLists.Add(x));
            });
        }
        private void BtnPrint_Click(object sender, RoutedEventArgs e)
        {
            if (this.CbPrintTemplate.Text.Length == 0 || this.CbPrinterName.Text.Length == 0 || this.DP1.SelectedDate == null)
            {
                MessageBox.Show("请选择日期、模板以及Tender打印机");
                return;
            }
            //var printHelp = new PrintHelper(user, this.DP1.SelectedDate);

            /* 获取打印数据和配置 */
            var data   = new LabelPrintDAL().GetPrintResultRecord(this.DP1.SelectedDate.Value, user.ID, "未打印").OrderBy(m => m.PrintOrder).ToList();
            var config = new PrintSchemaParameterModel
            {
                UserId           = user.ID,
                SchemaId         = globalSchemaId,
                TemplateFullName = this.CbPrintTemplate.Text,
                TemplateFileName = Path.GetFileName(this.CbPrintTemplate.Text),
                Orientation      = this.CbOrientation.Text,
                PrinterName      = this.CbPrinterName.Text,
                FolderPath       = this.tbFolderPath.Text
            };
            string r = new PrintHelper().PrintLabel(config, data);

            if (string.IsNullOrEmpty(r))
            {
                // 打印参数插入数据库
                if (globalSchemaId > 0)
                {
                    // 将对应的按钮的背景色设置为绿色
                    var btn = (Button)this.scrollViewer.FindName("Btn" + globalSchemaId.ToString());
                    btn.Foreground = System.Windows.Media.Brushes.GhostWhite;
                    var border = (Border)btn.Template.FindName("back", btn);
                    border.Background = System.Windows.Media.Brushes.Green;

                    var message = new LabelPrintService().SavePrintSchemaParameter(config);
                    if (!string.IsNullOrEmpty(r))
                    {
                        MessageBox.Show(r);
                        return;
                    }
                }
                RefreshDataGrid();
                globalSchemaId = 0;
                MessageBox.Show("打印成功");
            }
            else
            {
                MessageBox.Show(r);
            }
        }
        private void BtnUpdate_Click(object sender, RoutedEventArgs e)
        {
            var item = this.MainDataGrid.SelectedItem as LabelPrintSpecialRequestModel;

            if (item == null)
            {
                MessageBox.Show("请先选择行");
                return;
            }

            int    id    = item.ID;
            string value = this.TbRequestValue.Text;
            string label = null;

            if (item.IdentityType == 1)
            {
                label = this.TbLabel.Text;
                // 如果客户和标签存在则返回
                var custLabel = new LabelPrintService().GetAllSpecialRequest().Where(m => m.ID != id && m.OrgID.ToUpper() == item.OrgID.ToUpper() && m.Label?.ToUpper() == label.ToUpper() && m.RequestSeq == item.RequestSeq);
                if (custLabel.Count() > 0)
                {
                    MessageBox.Show("该客户标签已存在");
                    return;
                }
            }

            // 同步数据库
            string r = new LabelPrintService().UpdateLabelPrintSpecialRequestModel(id, value, label);

            if (r == null)
            {
                MessageBox.Show("更新成功");

                BindingExpression be1 = TbRequestValue.GetBindingExpression(TextBox.TextProperty);
                if (item.IdentityType == 1)
                {
                    BindingExpression be2 = TbLabel.GetBindingExpression(TextBox.TextProperty);
                    be2.UpdateSource();
                }
                be1.UpdateSource();
                isRefreshParentDataGrid = true;
                return;
            }
            else
            {
                MessageBox.Show(r);
                return;
            }
        }
Example #9
0
        private void BtnBatchDelete_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("确定要删除当前生产日期下所有未打印数据", "温馨提示", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                if (this.CbPrintStatus.Text == "已打印")
                {
                    MessageBox.Show(" 请先查询未打印数据 ");
                    return;
                }
                string r = new LabelPrintService().BatchDeleteCurrentPrintData(this.DP1.SelectedDate.Value, _user.ID);
                if (r != null)
                {
                    this.MainDataGrid.ItemsSource = null;
                    isRefreshParentDataGrid       = true;
                    MessageBox.Show(r);
                    return;
                }
                MessageBox.Show("删除失败,请联系管理员");
            }
        }
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            // 输入数据验证
            var model = ADDVerificationInput();

            if (model != null)
            {
                // 同步数据库
                int id = new LabelPrintService().AddSpecialRequest(model);
                if (id <= 0)
                {
                    MessageBox.Show("添加失败");
                    return;
                }
                model.ID = id;
                // 更改界面
                (this.MainDataGrid.ItemsSource as ObservableCollection <LabelPrintSpecialRequestModel>).Insert(0, model);
                SpecialRequests.Insert(0, model);
                this.MainDataGrid.SelectedItem = null;
                isRefreshParentDataGrid        = true;
                MessageBox.Show("添加成功");
            }
        }
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            var item = MainDataGrid.SelectedItem as LabelPrintSpecialRequestModel;

            if (item == null)
            {
                MessageBox.Show("请先选择行");
                return;
            }
            string r = new LabelPrintService().DeleteSpecialRequest(item.ID);

            if (string.IsNullOrEmpty(r))
            {
                (this.MainDataGrid.ItemsSource as ObservableCollection <LabelPrintSpecialRequestModel>).Remove(item);
                SpecialRequests.Remove(item);
                this.MainDataGrid.SelectedItem = null;
                isRefreshParentDataGrid        = true;
                MessageBox.Show("删除成功");
            }
            else
            {
                MessageBox.Show(r);
            }
        }