You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

360 lines
12 KiB
C#

using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar.SuperGrid;
using POSV.Card;
using POSV.Component;
using POSV.Report;
using POSV.Template;
using POSV.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace POSV.Stock
{
public partial class StoreStorageLossListForm : BusinessForm
{
public StoreStorageLossListForm()
{
InitializeComponent();
this.controlBox1.Text = "报损单";
this.controlBox1.ShowApplicationVersion = false;
//默认设置一周的查询时间
this.startPicker.Value = Convert.ToDateTime(DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd 00:00:00"));
this.endPicker.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
BuilderOrderGrid();
BuilderOrderDetailGrid();
Task.Factory.StartNew(() =>
{
this.Invoke(new Action(() =>
{
OnQueryClick(this, null);
}));
});
}
private void BuilderOrderGrid()
{
var panel = orderGrid.PrimaryGrid;
panel.RowHeaderIndexOffset = 1;
panel.DefaultRowHeight = 40;
var cols = ReportUtils.GetGridObject("POSV.Stock.", "StoreStorageLossTicket.json");
if(cols != null)
{
foreach(var col in cols)
{
panel.Columns.Add(new DevComponents.DotNetBar.SuperGrid.GridColumn()
{
Name = col.Name,
HeaderText = col.HeaderText,
DataPropertyName = col.DataPropertyName,
Visible = col.Display,
Width = col.Width
});
}
}
else
{
panel.NoRowsText = "加载报表错误,请联系管理员";
}
}
private void BuilderOrderDetailGrid()
{
var panel = detailGrid.PrimaryGrid;
panel.RowHeaderIndexOffset = 1;
panel.DefaultRowHeight = 40;
var cols = ReportUtils.GetGridObject("POSV.Stock.", "StoreStorageLossTicketDetail.json");
if (cols != null)
{
foreach (var col in cols)
{
panel.Columns.Add(new DevComponents.DotNetBar.SuperGrid.GridColumn()
{
Name = col.Name,
HeaderText = col.HeaderText,
DataPropertyName = col.DataPropertyName,
Visible = col.Display,
Width = col.Width
});
}
}
else
{
panel.NoRowsText = "加载报表错误,请联系管理员";
}
}
private int _orderStatus = 0;
/// <summary>
/// 状态变更,触发查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnStatusCheckedChanged(object sender, EventArgs e)
{
if(sender is CheckBoxX)
{
var obj = sender as CheckBoxX;
if (obj.Checked)
{
_orderStatus = StringUtils.GetInt(obj.Tag);
}
}
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnQueryClick(object sender, EventArgs e)
{
QueryOrder(1, this.orderPaper.RowsPerPage);
}
private void QueryOrder(int pageNumber, int pageSize)
{
var startTime = startPicker.Value.ToString("yyyy-MM-dd HH:mm:ss");
var endTime = endPicker.Value.ToString("yyyy-MM-dd HH:mm:ss");
var queryNo = this.txtNo.Text.Trim();
var res = StockUtils.QueryStoreStorageOutTicketList("1", "no", queryNo, pageNumber, pageSize, _orderStatus.ToString(), startTime, endTime);
if (res.Item1)
{
if (this.IsDisposed || !this.IsHandleCreated) return;
orderGrid.PrimaryGrid.DataSource = res.Item3.List;
this.orderPaper.TotalPage = res.Item3.PageCount;
this.orderPaper.CurrentPage = res.Item3.PageNumber;
this.orderPaper.RecordCount = res.Item3.TotalCount;
this.orderPaper.RowsPerPage = res.Item3.PageSize;
}
else
{
this.ShowToastNotify(this, res.Item2);
}
}
private string _ticketId = null;
private void OnOrderRowActivated(object sender, DevComponents.DotNetBar.SuperGrid.GridRowActivatedEventArgs e)
{
if(e.NewActiveRow != null)
{
GridRow row = e.NewActiveRow as GridRow;
_ticketId = StringUtils.GetString(row.Cells["id"].Value);
QueryDetail(_ticketId, 1, this.detailPaper.RowsPerPage);
}
else
{
this.detailGrid.PrimaryGrid.Rows.Clear();
}
}
private void QueryDetail(string ticketId, int pageNumber, int pageSize)
{
var res = StockUtils.QueryStoreStorageOutTicketDetailList(ticketId, pageNumber, pageSize);
if (res.Item1)
{
this.detailGrid.PrimaryGrid.DataSource = res.Item3.List;
this.detailPaper.TotalPage = res.Item3.PageCount;
this.detailPaper.CurrentPage = res.Item3.PageNumber;
this.detailPaper.RecordCount = res.Item3.TotalCount;
this.detailPaper.RowsPerPage = res.Item3.PageSize;
}
else
{
this.ShowToastNotify(this, res.Item2);
}
}
private void OnOrderPageChange(object obj)
{
int cur = this.orderPaper.CurrentPage;
int rows = this.orderPaper.RowsPerPage;
QueryOrder(cur, rows);
}
private void OnDetailPageChange(object obj)
{
int cur = this.detailPaper.CurrentPage;
int rows = this.detailPaper.RowsPerPage;
if (!string.IsNullOrEmpty(_ticketId))
{
QueryDetail(_ticketId, cur, rows);
}
}
/// <summary>
/// 新增入库单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnAddStorageInClick(object sender, EventArgs e)
{
var form = new StoreStorageLossAddForm(OperateType.ADD, null);
form.OnSaveSuccess += (o, args) =>
{
//保存成功,刷新
OnQueryClick(o, args);
};
TransparentForm trans = new TransparentForm(this, form);
trans.ShowDialog(this);
}
private void OnCloseClick(object sender, EventArgs e)
{
if(this.Owner != null)
{
this.Owner.Close();
}
this.Close();
}
private void OnExistClick(object sender, EventArgs e)
{
OnCloseClick(sender, e);
}
private void OnDataBindingComplete(object sender, GridDataBindingCompleteEventArgs e)
{
var rows = e.GridPanel.Rows;
foreach(GridRow row in rows)
{
row.Cells["amount"].Value = StringUtils.FormatDataTwoDigit(Convert.ToDecimal(row.Cells["amount"].Value));
row.Cells["price"].Value = StringUtils.FormatDataTwoDigit(Convert.ToDecimal(row.Cells["price"].Value));
row.Cells["money"].Value = StringUtils.FormatDataTwoDigit(Convert.ToDecimal(row.Cells["money"].Value));
}
}
private void OnModifyClick(object sender, EventArgs e)
{
var row = this.orderGrid.ActiveRow as GridRow;
if(row == null)
{
this.ShowToastNotify(this, "请选择修改的单据");
return;
}
var id = row.Cells["id"].Value.ToString();
var status = row.Cells["status"].Value.ToString();
if(status != "0")
{
this.ShowToastNotify(this, "请选择新建状态的单据");
return;
}
var form = new StoreStorageLossAddForm(OperateType.EDIT, id);
form.OnSaveSuccess += (o, args) =>
{
//保存成功,刷新
OnQueryClick(o, args);
};
TransparentForm trans = new TransparentForm(this, form);
trans.ShowDialog(this);
}
private void OnConfirmClick(object sender, EventArgs e)
{
var row = this.orderGrid.ActiveRow as GridRow;
if (row == null)
{
this.ShowToastNotify(this, "请选择操作的单据");
return;
}
var id = row.Cells["id"].Value.ToString();
DialogForm dialog = new DialogForm("操作提示", "确定审核通过?", MessageBoxIcon.Question, MessageBoxButtons.OKCancel);
if(dialog.ShowDialog(this) == DialogResult.OK)
{
var res = StockUtils.ChangeStoreStorageOutTicketStatus(id, 2, Global.Instance.Worker.Name, null);
if (res.Item1)
{
dialog = new DialogForm("操作提示", "审核成功", MessageBoxIcon.Warning, MessageBoxButtons.OK);
dialog.ShowDialog(this);
OnQueryClick(sender, e);
}
else
{
dialog = new DialogForm("操作提示", "审核失败" + res.Item2, MessageBoxIcon.Warning, MessageBoxButtons.OK);
dialog.ShowDialog(this);
}
}
}
/// <summary>
/// 作废
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnCancelClick(object sender, EventArgs e)
{
var row = this.orderGrid.ActiveRow as GridRow;
if (row == null)
{
this.ShowToastNotify(this, "请选择操作的单据");
return;
}
var id = row.Cells["id"].Value.ToString();
DialogForm dialog = new DialogForm("操作提示", "确定作废?", MessageBoxIcon.Question, MessageBoxButtons.OKCancel);
if (dialog.ShowDialog(this) == DialogResult.OK)
{
var res = StockUtils.ChangeStoreStorageOutTicketStatus(id, 3, Global.Instance.Worker.Name, null);
if (res.Item1)
{
dialog = new DialogForm("操作提示", "作废成功", MessageBoxIcon.Warning, MessageBoxButtons.OK);
dialog.ShowDialog(this);
OnQueryClick(sender, e);
}
else
{
dialog = new DialogForm("操作提示", "作废失败" + res.Item2, MessageBoxIcon.Warning, MessageBoxButtons.OK);
dialog.ShowDialog(this);
}
}
}
private void OnMinimizedClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void OnTxtNoCustomClick(object sender, EventArgs e)
{
var obj = sender as NormalTextBox;
var txtForm = new TxtKeyboardForm(StringUtils.GetString(obj.Text));
txtForm.NotifyChanged += (o, args) =>
{
obj.Text = args.Data.ToString();
};
var trans = new TransparentForm(this, .5, txtForm);
trans.Show(this);
}
}
}