using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Text;
|
using System.Windows.Forms;
|
|
namespace WarM
|
{
|
public partial class Kf_InitStockBill : Form
|
{
|
private int HItemIDCol = 0;
|
private int HNumberCol = 0;
|
private int HWHID;
|
|
public DBUtility.frm_B_BillQueryCondition_New frmCondition;
|
const string ViewName = "h_v_Kf_InitStockBill";
|
const string ModName = "物料";
|
public DBUtility.ClsPub.Enum_InputMode InputMode; //录入状态标志(0-非录入状态 1-增加 2-修改)
|
public long HItemID;//项目ID
|
public string sCondition; //过滤条件
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
DataSet Ds = new DataSet();
|
TreeNode CurNode = new TreeNode();
|
public Kf_InitStockBill()
|
{
|
InitializeComponent();
|
}
|
//以下代码基本不需要修改
|
#region 固定代码
|
//保存GRID列宽
|
private void Kf_InitStockBill_FormClosing(object sender, FormClosingEventArgs e)
|
{
|
DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
|
}
|
//窗体加载
|
private void Kf_InitStockBill_Load(object sender, EventArgs e)
|
{
|
frmCondition = new DBUtility.frm_B_BillQueryCondition_New();
|
LoadTree();
|
initGrid();
|
InputMode = DBUtility.ClsPub.Enum_InputMode.InputMode_View;
|
RefreshTool();
|
}
|
//加载子结点
|
private void LoadAllNodes(TreeNode sNode)
|
{
|
if (sNode != null)
|
{
|
try
|
{
|
long sName = Convert.ToInt64(sNode.Name.Substring(1, sNode.Name.Length - 1));
|
sNode.Nodes.Clear();
|
DataSet Ds = oCn.RunProcReturn("select hitemid,hnumber,hname from Gy_Warehouse where HParentID='" + sName + "'", "Gy_Warehouse");
|
for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
|
{
|
TreeNode oNode = sNode.Nodes.Add("T" + Ds.Tables[0].Rows[i]["HItemID"].ToString(), Ds.Tables[0].Rows[i]["HNumber"].ToString() + "-" + Ds.Tables[0].Rows[i]["HName"].ToString(), 0,1);
|
}
|
sNode.Expand();
|
}
|
catch (Exception e)
|
{
|
MessageBox.Show("加载子项目失败!" + e.Message, "提示");
|
}
|
}
|
}
|
//加载树形
|
private void LoadTree()
|
{
|
try
|
{
|
tv.Nodes.Clear();
|
tv.ImageList = imageList1;
|
TreeNode sNode = tv.Nodes.Add("T0", this.Text, 0, 1);
|
LoadAllNodes(sNode);
|
}
|
catch (Exception e )
|
{
|
MessageBox.Show("加载树型失败!" + e.Message, "提示");
|
}
|
}
|
|
|
//退出模块
|
private void tc_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
//刷新
|
private void xs_Click(object sender, EventArgs e)
|
{
|
if (HWHID != 0)
|
{
|
Display();
|
}
|
}
|
|
//得到对应列
|
private Int32 Fun_GetCol(string sCol)
|
{
|
return DBUtility.Gy_BaseFun.Fun_GetCol(sCol, grdMain);
|
}
|
//刷新TOOLBAR
|
private void RefreshTool()
|
{
|
if (InputMode == DBUtility.ClsPub.Enum_InputMode.InputMode_View)
|
{
|
grdMain.Enabled = true;
|
tc.Enabled = true;
|
yl.Enabled = true;
|
}
|
else
|
{
|
grdMain.Enabled = false;
|
tc.Enabled = true;
|
yl.Enabled = false;
|
}
|
}
|
|
|
|
//树型 单击
|
private void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
|
{
|
if (CurNode.Text != "" && CurNode.Text != "期初录入")
|
{
|
if (MessageBox.Show("是否要保存记录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
|
{
|
save();
|
}
|
}
|
CurNode = e.Node;
|
if (CurNode != null)
|
{
|
if (CurNode.Nodes.Count == 0)
|
LoadAllNodes(CurNode);
|
//找到选中结点
|
FindRow(CurNode.Text);
|
}
|
}
|
//查找结点
|
private void FindRow(string sCode)
|
{
|
DBUtility.Gy_BaseFun.FindRow(sCode, ModName, ref sCondition);
|
Display();
|
|
}
|
|
|
//选中行是否正常
|
//private bool AllowRow()
|
//{
|
// if (grdMain.Rows >= grdMain.FixedRows && grdMain.Row <= grdMain.Rows - 1)
|
// return true;
|
// else
|
// return false;
|
//}
|
|
//
|
|
|
|
private void bclk_Click(object sender, EventArgs e)
|
{
|
//保存列宽
|
DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
|
}
|
|
private void mrlk_Click(object sender, EventArgs e)
|
{
|
DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
|
}
|
//时间控件
|
private void timer1_Tick(object sender, EventArgs e)
|
{
|
timer1.Enabled = false;
|
if (HWHID != 0)
|
{
|
Display();
|
}
|
}
|
|
//初始化GRID
|
private void initGrid()
|
{
|
grdMain.RowTemplate.Height = 18;
|
grdMain.RowTemplate.MinimumHeight = 18;
|
grdMain.ColumnHeadersHeight = 40;
|
grdMain.RowHeadersVisible = false;
|
grdMain.ColumnHeadersVisible = true;
|
grdMain.ColumnCount = 0;
|
grdMain.RowCount = 0;
|
//格式化
|
//表格设置
|
grdMain.RowsDefaultCellStyle.SelectionForeColor = Color.White;
|
grdMain.RowsDefaultCellStyle.SelectionBackColor = Color.DarkCyan;
|
grdMain.DefaultCellStyle.SelectionBackColor = Color.DarkCyan;
|
grdMain.DefaultCellStyle.SelectionForeColor = Color.White;
|
grdMain.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
|
grdMain.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
grdMain.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
grdMain.ReadOnly = false;
|
grdMain.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //允许用户调整列宽
|
grdMain.EnableHeadersVisualStyles = false; //网格标题 样式
|
grdMain.AllowUserToAddRows = false; //是否允许自增--否
|
grdMain.AllowUserToDeleteRows = false; //是否允许删除--否
|
grdMain.AllowUserToResizeColumns = true; //允许调整列宽--是
|
grdMain.AllowUserToResizeRows = false; //允许调整行高--否
|
grdMain.AllowUserToOrderColumns = true; //允许 拖拽列
|
grdMain.BackgroundColor = Color.White;
|
grdMain.GridColor = Color.LightGray; //网格线颜色
|
grdMain.ShowCellToolTips = true;
|
grdMain.CellBorderStyle = DataGridViewCellBorderStyle.Raised;
|
//grdMain.ColumnHeadersDefaultCellStyle.BackColor = Color.AliceBlue;
|
//
|
DBUtility.ClsPub.GetGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath);//设置列宽
|
}
|
//显示列表
|
private void Display()
|
{
|
SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN();
|
DataSet DSet;
|
string sSql = "";
|
string sWhere = "";
|
//刷新树形
|
//LoadTree();
|
//过滤条件
|
|
//sSql = "Select * from " + ViewName + " order by " + ModName + "代码";
|
sSql = "exec h_p_Kf_InitStockBill " + HWHID;
|
//执行SQL
|
DSet = SubCn.RunProcReturn(sSql, ViewName);
|
//生成首行标题
|
//
|
for (int i = 0; i < grdMain.ColumnCount; i++)
|
{
|
grdMain.Columns[i].Frozen = false;
|
}
|
//
|
grdMain.DataSource = DSet.Tables[0].DefaultView;
|
|
//设置可编辑列和合计列
|
|
int HMaterNumberCol = Fun_GetCol("物料代码");
|
int HMaterNameCol = Fun_GetCol("物料名称");
|
int HMaterModelCol = Fun_GetCol("规格型号");
|
int HUnitNameCol = Fun_GetCol("单位");
|
int HPriceCol = Fun_GetCol("单价");
|
int HQtyCol = Fun_GetCol("数量");
|
int HMoneyCol = Fun_GetCol("金额");
|
grdMain.Columns[HMaterNumberCol].ReadOnly = true;
|
grdMain.Columns[HMaterNameCol].ReadOnly = true;
|
grdMain.Columns[HMaterModelCol].ReadOnly = true;
|
grdMain.Columns[HUnitNameCol].ReadOnly = true;
|
double HQty=0;
|
double HMoney=0;
|
double HPrice = 0;
|
for (int i = 0; i < grdMain.RowCount; i++)
|
{
|
HQty = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HQtyCol].Value);
|
HMoney = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HMoneyCol].Value);
|
HPrice = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HPriceCol].Value);
|
if (HQty == 0)
|
{
|
grdMain.Rows[i].Cells[HPriceCol].Value = 0;
|
}
|
else
|
{
|
HPrice= HMoney / HQty;
|
grdMain.Rows[i].Cells[HPriceCol].Value = HPrice;
|
}
|
grdMain.Rows[i].Cells[HMoneyCol].Value = HMoney;
|
grdMain.Rows[i].Cells[HQtyCol].Value = HQty;
|
}
|
//加载列宽,隐藏列
|
DBUtility.Gy_BaseFun.DisplayGrid(grdMain, this.Name);
|
}
|
|
#endregion
|
|
private void bc_Click(object sender, EventArgs e)
|
{
|
save();
|
}
|
private void save()
|
{
|
int HMaterIDCol = Fun_GetCol("hmaterid");
|
int HUnitIDCol = Fun_GetCol("hunitid");
|
int HBatchNoCol = Fun_GetCol("批次");
|
int HQtyCol = Fun_GetCol("数量");
|
int HMoneyCol = Fun_GetCol("金额");
|
int HRemarkCol = Fun_GetCol("备注");
|
int HMaterID = 0;
|
int HUnitID = 0;
|
string HBatchNo = "";
|
double HQty = 0;
|
double HPrice = 0;
|
double HMoney = 0;
|
string HRemark = "";
|
int HSpID = 0;
|
double HReceiveQty = 0;
|
double HSendQty = 0;
|
double HEndQty = 0;
|
double HReceiveBal = 0;
|
double HSendBal = 0;
|
double HEndBal = 0;
|
int sYear = 0;
|
int sPeriod = 0;
|
DBUtility.ClsPub.Sub_GetPeriodByDate(DBUtility.ClsPub.isDate(DBUtility.ClsPub.GetServerDate(-1), 0), ref sYear, ref sPeriod);
|
oCn.RunProc("delete Kf_InitStockBill where hwhid=" + HWHID);
|
for (int i = 0; i <= grdMain.RowCount - 1; i++)
|
{
|
if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HQtyCol].Value) != 0)
|
{
|
//
|
HMaterID = DBUtility.ClsPub.isInt(grdMain.Rows[i].Cells[HMaterIDCol].Value);
|
HUnitID = DBUtility.ClsPub.isInt(grdMain.Rows[i].Cells[HUnitIDCol].Value);
|
HQty = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HQtyCol].Value);
|
HMoney = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HMoneyCol].Value);
|
HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HBatchNoCol].Value);
|
HRemark = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HRemarkCol].Value);
|
//
|
HSpID = 0;
|
HReceiveQty = 0;
|
HSendQty = 0;
|
HEndQty = 0;
|
HReceiveBal = 0;
|
HSendBal = 0;
|
HEndBal = 0;
|
oCn.RunProc("Insert into Kf_InitStockBill " +
|
" (HYear,HPeriod,HBillType,HDate,HMaterID,HUnitID,HWHID" +
|
",HBeginQty,HBeginBal,HMaker,HMakeDate" +
|
",HSpID,HReceiveQty,HSendQty,HEndQty,HReceiveBal,HSendBal,HEndBal" +
|
",HRemark,HBatchNo)" +
|
" values("
|
+ sYear + "," + sPeriod + ",'1299','" + DBUtility.ClsPub.GetServerDate(-1) + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HWHID.ToString() +
|
"," + HQty.ToString() + "," + HMoney.ToString() + ",'" + DBUtility.ClsPub.CurUserName + "','" + DBUtility.ClsPub.GetServerDate(-1) +
|
"'," + HSpID.ToString() + "," + HReceiveQty.ToString() + "," + HSendQty.ToString() + "," + HEndQty.ToString() + "," + HReceiveBal.ToString() + "," + HSendBal.ToString() + "," + HEndBal.ToString() +
|
",'" + HRemark + "','" + HBatchNo + "') ");
|
}
|
|
}
|
}
|
private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
|
{
|
|
int HPriceCol = Fun_GetCol("单价");
|
int HQtyCol = Fun_GetCol("数量");
|
int HMoneyCol = Fun_GetCol("金额");
|
double HPrice = DBUtility.ClsPub.isDoule(grdMain.Rows[e.RowIndex].Cells[HPriceCol].Value);
|
double HQty = DBUtility.ClsPub.isDoule(grdMain.Rows[e.RowIndex].Cells[HQtyCol].Value);
|
double HMoney = DBUtility.ClsPub.isDoule(grdMain.Rows[e.RowIndex].Cells[HMoneyCol].Value);
|
if (e.ColumnIndex == HPriceCol)
|
{
|
HMoney = HPrice * HQty;
|
grdMain.Rows[e.RowIndex].Cells[HMoneyCol].Value = HMoney.ToString();
|
}
|
else if (e.ColumnIndex == HMoneyCol)
|
{
|
if (HQty == 0)
|
{
|
grdMain.Rows[e.RowIndex].Cells[HPriceCol].Value = 0;
|
}
|
else
|
{
|
HPrice = HMoney / HQty;
|
grdMain.Rows[e.RowIndex].Cells[HPriceCol].Value = HPrice.ToString();
|
}
|
}
|
}
|
|
}
|
}
|