using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CoreFS.CA06;using Pur.Entity;
using Pur.Entity.ck;
using Pur.require_plan;
using Pur.Entity.configureEntity;
using Core.Mes.Client.Comm.Control;
using com.hnshituo.pur.vo;
using Pur.configure;
using Infragistics.Win;
using Pur.PublicTools;
using Infragistics.Win.UltraWinGrid;
using Pur.Pop_upWindow;
using Core.Mes.Client.Comm.Tool;
using System.Collections;
namespace Pur.ck
{
public partial class FrmCkStorageConfirm : FrmPmsBase
{
public FrmCkStorageConfirm()
{
InitializeComponent();
txt_createTimeE.Value = System.DateTime.Now;
txt_createTimeS.Value = ((DateTime)txt_createTimeE.Value).AddMonths(-1);
//ultraGrid1.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False;
}
//菜单按钮事件
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
if (ultraTabControl2.SelectedTab.Key=="0")
{
GetPUR_CK_STORAGE();
getPur_Ck_StorageSuorce();
}
else
{
getPur_Ck_StorageSuorce();
}
break;
case "cockInv":
cockInv();
break;
case "unCockInv":
unCockInv();
break;
case "MovingInvPhy":
MovingInvPhy();
break;
case "CanCelMovingInvPhy":
CanCelMovingInvPhy();
break;
case "doexport":
doexport();
break;
}
}
public void doexport()
{
if (ultraTabControl2.ActiveTab.Key == "0")
GridHelper.ulGridToExcel(ultraGrid1, ultraGrid1.Text);
else
GridHelper.ulGridToExcel(ultraGrid5, ultraGrid5.Text);
}
///
/// 查询
///
private void GetPUR_CK_STORAGE()
{
dataTable2.Rows.Clear();
dataTable3.Rows.Clear();
CkStorage CkSto = new CkStorage();
CkSto.InvId = txt_InvId.Text;
CkSto.ItemCode = txt_itemCode.Text;
CkSto.ItemName = txt_itemName.Text;
CkSto.SuppName = txt_suppName.Text;
CkSto.OrderId = txt_orderId.Text;
CkSto.InStockNo = txt_inStockNo.Text;
CkSto.InvQty = Convert.ToDouble(txt_invOrigQty.Value);
CkSto.CreateName = txtItemClass.Text;
if (!string.IsNullOrEmpty(txt_createTimeS.Text) && !string.IsNullOrEmpty(txt_createTimeE.Text))
{
CkSto.CreateTime = Convert.ToDateTime(txt_createTimeS.Text);
CkSto.UpdateTime = Convert.ToDateTime(txt_createTimeE.Text).AddDays(1);
}
CkSto.YkStatus = "1";
string depid = this.UserInfo.GetDeptid();
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStorageService", "find_StorageByStatus", new object[] { CkSto, depid });
GridHelper.CopyDataToDatatable(dt, dataTable1, true);
GridHelper.RefreshAndAutoSize(ultraGrid1);
//publicPms.autoGridColumnWSize(ultraGrid1.DisplayLayout.Bands[0]);
foreach (UltraGridRow ugr in ultraGrid1.Rows)
{
//标记待检状态入库单
if (ugr.Cells["USESTATUS"].Value.ToString() == "不可用")
{
ugr.Cells["USESTATUS"].Appearance.ForeColor = Color.Red;// System.Drawing.Color.FromArgb(255, 128, 0);
ugr.Cells["STATUS"].Appearance.ForeColor = Color.Red;// System.Drawing.Color.FromArgb(255, 128, 0);
}
else
{
ugr.Cells["USESTATUS"].Appearance.ForeColor = Color.Black;
ugr.Cells["STATUS"].Appearance.ForeColor = Color.Black;// System.Drawing.Color.FromArgb(255, 128, 0);
}
}
}
///
/// 获取移库记录
///
private void getPur_Ck_StorageSuorce()
{
//dataTable7.Rows.Clear();
//CkStorage CkSto = new CkStorage();
//CkSto.InvId = txt_InvId.Text;
//CkSto.ItemCode = txt_itemCode.Text;
//CkSto.ItemName = txt_itemName.Text;
//if (txt_invBin.Value != null)
//{
// CkSto.DeleteName = txt_invBin.Text;
//}
////CkSto.InvLogic = txt_invLogic.Text;
//if (txt_invPhysic.Value != null)
//{
// CkSto.DeleteUserid = txt_invPhysic.Text;
//}
//CkSto.SuppName = txt_suppName.Text;
//CkSto.OrderId = txt_orderId.Text;
//CkSto.InStockNo = txt_inStockNo.Text;
//CkSto.InvQty = Convert.ToDouble(txt_invOrigQty.Value);
//if (!string.IsNullOrEmpty(txt_createTimeS.Text) && !string.IsNullOrEmpty(txt_createTimeE.Text))
//{
// CkSto.CreateTime = Convert.ToDateTime(txt_createTimeS.Text);
// CkSto.UpdateTime = Convert.ToDateTime(txt_createTimeE.Text).AddDays(1);
//}
////查询源移库记录
//CkSto.Status = "11";
//DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStorageService", "find_Storage", new object[] { CkSto });
//GridHelper.CopyDataToDatatable(dt, dataTable4, true);
//GridHelper.RefreshAndAutoSize(ultraGrid2);
dataTable6.Rows.Clear();
CkStorage CkSto = new CkStorage();
CkSto.InvId = txt_InvId.Text;
CkSto.ItemCode = txt_itemCode.Text;
CkSto.ItemName = txt_itemName.Text;
//CkSto.InvLogic = txt_invLogic.Text;
CkSto.SuppName = txt_suppName.Text;
CkSto.OrderId = txt_orderId.Text;
CkSto.InStockNo = txt_inStockNo.Text;
CkSto.InvQty = Convert.ToDouble(txt_invOrigQty.Value);
if (!string.IsNullOrEmpty(txt_createTimeS.Text) && !string.IsNullOrEmpty(txt_createTimeE.Text))
{
CkSto.CreateTime = Convert.ToDateTime(txt_createTimeS.Text);
CkSto.UpdateTime = Convert.ToDateTime(txt_createTimeE.Text).AddDays(1);
}
string[] datePurviewIds = this.ValidDataPurviewIds;
//查询源移库记录
//CkSto.Status = "11";
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStorageUseService", "getCkConfirm", new object[] { CkSto,UserInfo.GetDeptid() });
GridHelper.CopyDataToDatatable(dt, dataTable6, true);
GridHelper.RefreshAndAutoSize(ultraGrid5);
}
///
/// 解冻库存
///
private void unCockInv()
{
UltraGridRow ugr = ultraGrid1.ActiveRow;
CkStorage ck = new CkStorage();
ck.InvId = ugr.Cells["InvId"].Value.ToString();
ck.UseStatus = "1";
if (MessageUtil.ShowYesNoAndQuestion("确定解冻库存【" + ck.InvId + "】?").Equals(DialogResult.No))
{
return;
}
CoreResult re1 = this.execute("com.hnshituo.pur.ck.service.CkStorageService", "doUpdate", new object[] { ck });
if (re1.Resultcode == -1)
{
MessageBox.Show("解冻失败:" + re1.Resultmsg, "");
return;
}
MessageBox.Show("解冻成功!");
GetPUR_CK_STORAGE();
getPur_Ck_StorageSuorce();
}
///
/// 冻结库存
///
private void cockInv()
{
UltraGridRow ugr = ultraGrid1.ActiveRow;
CkStorage ck = new CkStorage();
ck.InvId = ugr.Cells["InvId"].Value.ToString();
ck.UseStatus = "0";
if (MessageUtil.ShowYesNoAndQuestion("确定冻结库存【" + ck.InvId + "】?").Equals(DialogResult.No))
{
return;
}
CoreResult re1 = this.execute("com.hnshituo.pur.ck.service.CkStorageService", "doUpdate", new object[] { ck });
if (re1.Resultcode == -1)
{
MessageBox.Show("冻结失败:" + re1.Resultmsg, "");
return;
}
MessageBox.Show("冻结成功!");
GetPUR_CK_STORAGE();
getPur_Ck_StorageSuorce();
}
///
/// 物料弹窗
///
///
///
private void txt_itemCode_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
{
FrmPurPlanMat mat = new FrmPurPlanMat(this.ob);
mat.ShowDialog();
if (mat.getItemCode() != null)
{
txt_itemCode.Text = mat.getItemCode().ToString();
txt_itemName.Text = mat.getItemName().ToString();
}
}
///
/// 界面加载,库区下拉框加载
///
///
///
private void PurCkStorage_Load(object sender, EventArgs e)
{
txt_createTimeS.Text = DateTime.Now.AddMonths(-1).ToString();
//获取
PurCkInBillEntity CkInBillEntity = new PurCkInBillEntity();
DataTable dt_GropByItem = this.execute("com.hnshituo.pur.ck.service.CkInBillService", "GetCkInBill_GropByItem", new object[] { CkInBillEntity });
comm.FilComboboxAdd(txtItemClass, dt_GropByItem, "basecode", "basename", "", true, "", "");
//LogicWareHouseEntity lhouse = new LogicWareHouseEntity();
//lhouse.Validflag = "1";
//DataTable dt = this.execute("com.hnshituo.pur.configure.service.LogicSeatService", "getLogicSeat", new object[] { lhouse, 0, 0 });
//if (dt.Rows.Count > 0)
//{
// txt_invLogic.DataSource = dt;
// this.txt_invLogic.DisplayMember = "invLogicName";
// this.txt_invLogic.ValueMember = "invLogic";
//}
//PhysicSeatEntity Phouse = new PhysicSeatEntity();
//Phouse.Validflag = "1";
//DataTable dt1 = this.execute("com.hnshituo.pur.configure.service.ActualSeatService", "getActualSeat", new object[] { Phouse, 0, 0 });
//if (dt1.Rows.Count > 0)
//{
// txt_invPhysic.DataSource = dt1;
// this.txt_invPhysic.DisplayMember = "invPhysicName";
// this.txt_invPhysic.ValueMember = "invPhysic";
//}
//ActualSeatPosEntity PosEntity = new ActualSeatPosEntity();
//PosEntity.Validflag = "1";
//DataTable dt3 = this.execute("com.hnshituo.pur.configure.service.ActualSeatPosService", "find", new object[] { PosEntity, 0, 0 });
//if (dt3.Rows.Count > 0)
//{
// txt_invBin.DataSource = dt3;
// this.txt_invBin.DisplayMember = "invPosName";
// this.txt_invBin.ValueMember = "invPos";
//}
GridHelper.SetExcludeColumnsActive(ultraGrid5.DisplayLayout.Bands[0]);
GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], "Check", "MoveQtyKC", "MoveQty");
//GetPUR_CK_STORAGE();
}
///
/// 供应商弹窗
///
///
///
private void txt_suppName_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
{
Supp Sp = new Supp();
Sp.Validflag = "1";
//DataTable dt = this.execute("com.hnshituo.pur.configure.service.SuppService", "find", new object[] {Sp,0,0 });
frmSuppSel Sky = new frmSuppSel(this.ob);
Sky.ShowDialog();
if (Sky.strSUPP_CODE == null)
return;
txt_suppName.Text = Sky.strSUPP_NAME.ToString();
//Supp_Code = Sky.strSUPP_CODE.ToString();
}
///
/// 激活库存表
///
///
///
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
//GetPUR_CK_STORAGE_USE();
//GetPUR_CK_STORAGE_POS();
}
///
/// 查询库存使用表
///
private void GetPUR_CK_STORAGE_USE()
{
if (ultraGrid1.ActiveRow != null)
{
PurCkStorageUseEntity CkStorageUseEntity = new PurCkStorageUseEntity();
CkStorageUseEntity.InvId = ultraGrid1.ActiveRow.Cells["INVID"].Value.ToString();
CkStorageUseEntity.Validflag = "1";
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStorageUseService", "find", new object[] { CkStorageUseEntity,0,0 });
//按创建时间降序
if (dt.Rows.Count > 1)
{
dt.DefaultView.Sort = "CREATETIME DESC";
dt = dt.DefaultView.ToTable();
}
GridHelper.CopyDataToDatatable(dt, dataTable3, true);
}
}
///
/// 查询库存库位
///
private void GetPUR_CK_STORAGE_POS()
{
if (ultraGrid1.ActiveRow != null)
{
PurCkStoragePosEntity CkStoragePosEntity = new PurCkStoragePosEntity();
CkStoragePosEntity.InvId = ultraGrid1.ActiveRow.Cells["INVID"].Value.ToString();
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStoragePosService", "getCkStoragePos_ByInvId", new object[] { CkStoragePosEntity });
//按创建时间降序
if (dt.Rows.Count > 1)
{
dt.DefaultView.Sort = "CREATETIME DESC";
dt = dt.DefaultView.ToTable();
}
GridHelper.CopyDataToDatatable(dt, dataTable2, true);
}
//publicPms.autoGridColumnWSize(ultraGrid2.DisplayLayout.Bands[0]);
}
///
/// 勾选库存记录
///
///
///
private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
object o = e.Cell.Value;
ultraGrid1.UpdateData();
//UltraGridRow[] ugrs = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "Check" }, new string[] { e.Cell.Value.ToString()});
//判断库区是否全相同
//UltraGridRow[] ugrsPhysic = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "Check","invPhysic" }, new string[] { e.Cell.Value.ToString(),e.Cell.Row.Cells["invPhysic"].Value.ToString() });
//判断库位是否全相同
//UltraGridRow[] ugrsPhysicPos = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "Check", "invPos" }, new string[] { e.Cell.Value.ToString(), e.Cell.Row.Cells["invPos"].Value.ToString() });
if (e.Cell.Column.Key == "MoveQtyKC")
{
double bMoveQtyKC = 0;
double.TryParse(e.Cell.Row.Cells["MoveQtyKC"].Value.ToString(), out bMoveQtyKC);
double bINVQTYWEIGHT = 0;
double.TryParse(e.Cell.Row.Cells["INVQTYWEIGHT"].Value.ToString(), out bINVQTYWEIGHT);
double bITEMUOMCONEFFICIENT = 0;
double.TryParse(e.Cell.Row.Cells["ITEMUOMCONEFFICIENT"].Value.ToString(), out bITEMUOMCONEFFICIENT);
if(bMoveQtyKC>bINVQTYWEIGHT)
{
MessageUtil.ShowTips("移库数量不能>库存数量");
e.Cell.Value = o;
return;
}
else
{
if (e.Cell.Row.Cells["itemUom"].Value.ToString() == "基吨")
{
e.Cell.Row.Cells["MoveQty"].Value = Math.Round(bMoveQtyKC * bITEMUOMCONEFFICIENT, 3);
}
else
{
e.Cell.Row.Cells["MoveQty"].Value = Math.Round(bMoveQtyKC / bITEMUOMCONEFFICIENT, 3);
}
}
}
if (e.Cell.Column.Key == "MoveQty")
{
double bMoveQty = 0;
double.TryParse(e.Cell.Row.Cells["MoveQty"].Value.ToString(), out bMoveQty);
double bINVQTY = 0;
double.TryParse(e.Cell.Row.Cells["INVQTY"].Value.ToString(), out bINVQTY);
double bITEMUOMCONEFFICIENT = 0;
double.TryParse(e.Cell.Row.Cells["ITEMUOMCONEFFICIENT"].Value.ToString(), out bITEMUOMCONEFFICIENT);
if (bMoveQty > bINVQTY)
{
MessageUtil.ShowTips("移库数量不能>采购数量");
e.Cell.Value = o;
return;
}
else
{
if (e.Cell.Row.Cells["itemUom"].Value.ToString() == "基吨")
{
e.Cell.Row.Cells["MoveQtyKC"].Value = Math.Round(bMoveQty / bITEMUOMCONEFFICIENT, 3);
}
else
{
e.Cell.Row.Cells["MoveQtyKC"].Value = Math.Round(bMoveQty * bITEMUOMCONEFFICIENT, 3);
}
}
}
}
///
/// 移库操作
///
///
///
private void btn_MovePhysic_Click(object sender, EventArgs e)
{
MovingInvPhy();
}
///
/// 确认
///
private void MovingInvPhy()
{
ultraGrid1.UpdateData();
if (ultraTabControl2.SelectedTab.Key != "0")
{
MessageUtil.ShowTips("请切换tab页面到“库存记录”,再进行操作");
return;
}
ArrayList al = new ArrayList();
foreach (UltraGridRow ugr in ultraGrid1.Rows)
{
if ((bool)ugr.Cells["Check"].Value)
{
al.Add(ugr.Cells["InvId"].Value.ToString());
}
}
if (ultraGrid1.Rows.Where(t => t.Selected).Count() > 0 && al.Count <= 0)
{
foreach (UltraGridRow ugr in ultraGrid1.Rows.Where(t => t.Selected))
{
al.Add(ugr.Cells["InvId"].Value.ToString());
}
}
if(al.Count<1)
{
MessageUtil.ShowTips("请勾选需要确认的记录");
return;
}
CoreResult re1 = this.execute("com.hnshituo.pur.ck.service.CkStorageService", "MoveInvConfirm", new object[] { al, UserInfo.GetUserName() });
if (re1.Resultcode == -1)
{
MessageBox.Show("操作失败:" + re1.Resultmsg, "");
return;
}
MessageBox.Show("确认成功!");
GetPUR_CK_STORAGE();
getPur_Ck_StorageSuorce();
}
///
/// 撤销移库
///
private void CanCelMovingInvPhy()
{
if (ultraTabControl2.SelectedTab.Key != "1")
{
MessageUtil.ShowTips("请切换tab页面到“移库记录”,再撤销移库确认");
return;
}
if(ultraGrid5.ActiveRow!=null)
{
if (comm.ConfirmOption("确定撤销库存记录号【" + ultraGrid5.ActiveRow.Cells["INVIDNEW"].Value.ToString() + "】的移库确认"))
{
CkStorage ck = new CkStorage();
ck.InvId = ultraGrid5.ActiveRow.Cells["INVIDNEW"].Value.ToString();
ck.UpdateName = UserInfo.GetUserName();
ck.UpdateUserid = UserInfo.GetUserID();
CoreResult re1 = this.execute("com.hnshituo.pur.ck.service.CkStorageService", "CancelMoveInvConfirm", new object[] { ck });
if (re1.Resultcode == -1)
{
MessageBox.Show("撤销失败:" + re1.Resultmsg, "");
return;
}
MessageBox.Show("撤销成功!");
GetPUR_CK_STORAGE();
getPur_Ck_StorageSuorce();
}
}
else
{
MessageUtil.ShowTips("请选择移库记录");
return;
}
}
///
/// 选择新库位
///
///
///
private void txtPhysicPosNew_ValueChanged(object sender, EventArgs e)
{
//获取库位编码
}
private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
{
CkStorage CkSto = new CkStorage();
CkSto.InvIdSource = ultraGrid2.ActiveRow.Cells["InvId"].Value.ToString();
DataTable dt = this.execute("com.hnshituo.pur.ck.service.CkStorageService", "find_Storage", new object[] { CkSto });
GridHelper.CopyDataToDatatable(dt, dataTable7, true);
GridHelper.RefreshAndAutoSize(ultraGrid4);
}
}
}