202 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			202 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Data.SqlClient;
							 | 
						|||
| 
								 | 
							
								using System.Data;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using BLL;
							 | 
						|||
| 
								 | 
							
								using Newtonsoft.Json.Linq;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace FineUIPro.Web.HJGL.MaterialManage
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public partial class StockMove : PageBase
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        protected void Page_Load(object sender, EventArgs e)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (!IsPostBack)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                BLL.UserService.InitUsersDropDownList(this.drpMoveInMan, this.CurrUser.LoginProjectId, true, null);
							 | 
						|||
| 
								 | 
							
								                drpMoveInMan.SelectedValue = CurrUser.UserId;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                BLL.UnitStoreService.InitUnitStoreDropDownList(drpUnitStoreOut, string.Empty, true);
							 | 
						|||
| 
								 | 
							
								                BLL.UnitStoreService.InitUnitStoreDropDownList(drpUnitStoreIn, string.Empty, true);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                this.txtMoveInDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                Grid1.Hidden = true;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        protected void btnSave_Click(object sender, EventArgs e)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (this.drpUnitStoreOut.SelectedValue == Const._Null)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Alert.ShowInTop("请选择要移出的仓库!", MessageBoxIcon.Warning);
							 | 
						|||
| 
								 | 
							
								                return;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            if (drpUnitStoreIn.SelectedValue == Const._Null)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Alert.ShowInTop("请选择要移入的仓库!", MessageBoxIcon.Warning);
							 | 
						|||
| 
								 | 
							
								                return;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            var outStort = from x in Funs.DB.Weld_StockIn where x.Flag == "1" && x.UnitStoreId == drpUnitStoreOut.SelectedValue select x;
							 | 
						|||
| 
								 | 
							
								            int num = outStort.Count();
							 | 
						|||
| 
								 | 
							
								            if (num > 0)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                if (rdIsAll.SelectedValue == "1")
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    foreach (var q in outStort)
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        q.UnitStoreId = drpUnitStoreIn.SelectedValue;
							 | 
						|||
| 
								 | 
							
								                        q.MoveInStoreId = drpUnitStoreOut.SelectedValue;
							 | 
						|||
| 
								 | 
							
								                        q.MoveInManId = CurrUser.UserId;
							 | 
						|||
| 
								 | 
							
								                        q.MoveInDate = DateTime.Now;
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                    Funs.DB.SubmitChanges();
							 | 
						|||
| 
								 | 
							
								                    ShowNotify("成功移库" + num.ToString() + "个!", MessageBoxIcon.Success);
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    if (Grid1.SelectedRowIDArray.Count() > 0)
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        JArray mergedData = Grid1.GetMergedData();
							 | 
						|||
| 
								 | 
							
								                        foreach (JObject mergedRow in mergedData)
							 | 
						|||
| 
								 | 
							
								                        {
							 | 
						|||
| 
								 | 
							
								                            string status = mergedRow.Value<string>("status");
							 | 
						|||
| 
								 | 
							
								                            JObject values = mergedRow.Value<JObject>("values");
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                            string rowID = values.Value<string>("StockInId").ToString();
							 | 
						|||
| 
								 | 
							
								                            if (Grid1.SelectedRowIDArray.Contains(rowID))
							 | 
						|||
| 
								 | 
							
								                            {
							 | 
						|||
| 
								 | 
							
								                                var q = BLL.StockInService.GetStockInById(rowID);
							 | 
						|||
| 
								 | 
							
								                                if (q != null)
							 | 
						|||
| 
								 | 
							
								                                {
							 | 
						|||
| 
								 | 
							
								                                    decimal amount = Funs.GetNewDecimalOrZero(values.Value<string>("Amount").ToString());
							 | 
						|||
| 
								 | 
							
								                                    decimal needMoveAmount = Funs.GetNewDecimalOrZero(values.Value<string>("NeedMoveAmount").ToString());
							 | 
						|||
| 
								 | 
							
								                                    if (needMoveAmount == 0)
							 | 
						|||
| 
								 | 
							
								                                    {
							 | 
						|||
| 
								 | 
							
								                                        ShowNotify("需移库量不能为0!", MessageBoxIcon.Warning);
							 | 
						|||
| 
								 | 
							
								                                        return;
							 | 
						|||
| 
								 | 
							
								                                    }
							 | 
						|||
| 
								 | 
							
								                                    if (needMoveAmount > amount)
							 | 
						|||
| 
								 | 
							
								                                    {
							 | 
						|||
| 
								 | 
							
								                                        ShowNotify("需移库量大于焊材库存量!", MessageBoxIcon.Warning);
							 | 
						|||
| 
								 | 
							
								                                        return;
							 | 
						|||
| 
								 | 
							
								                                    }
							 | 
						|||
| 
								 | 
							
								                                    else if (needMoveAmount == amount)
							 | 
						|||
| 
								 | 
							
								                                    {
							 | 
						|||
| 
								 | 
							
								                                        q.UnitStoreId = drpUnitStoreIn.SelectedValue;
							 | 
						|||
| 
								 | 
							
								                                        q.MoveInStoreId = drpUnitStoreOut.SelectedValue;
							 | 
						|||
| 
								 | 
							
								                                        q.MoveInManId = CurrUser.UserId;
							 | 
						|||
| 
								 | 
							
								                                        q.MoveInDate = DateTime.Now;
							 | 
						|||
| 
								 | 
							
								                                    }
							 | 
						|||
| 
								 | 
							
								                                    else
							 | 
						|||
| 
								 | 
							
								                                    {
							 | 
						|||
| 
								 | 
							
								                                        q.Amount = amount - needMoveAmount;
							 | 
						|||
| 
								 | 
							
								                                        Model.Weld_StockIn newStockIn = new Model.Weld_StockIn();
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.StockInId = SQLHelper.GetNewID();
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.WeldId = q.WeldId;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.Amount = needMoveAmount;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.Materialman = this.CurrUser.UserId;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.InStockDate = DateTime.Now;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.ReviewDate = q.ReviewDate;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.Warrantybook = q.Warrantybook;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.Flag = "1";
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.HeartNo = q.HeartNo;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.UnitStoreId = drpUnitStoreIn.SelectedValue;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.MoveInStoreId = drpUnitStoreOut.SelectedValue;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.MoveInManId = CurrUser.UserId;
							 | 
						|||
| 
								 | 
							
								                                        newStockIn.MoveInDate = DateTime.Now;
							 | 
						|||
| 
								 | 
							
								                                        Funs.DB.Weld_StockIn.InsertOnSubmit(newStockIn);
							 | 
						|||
| 
								 | 
							
								                                    }
							 | 
						|||
| 
								 | 
							
								                                    Funs.DB.SubmitChanges();
							 | 
						|||
| 
								 | 
							
								                                }
							 | 
						|||
| 
								 | 
							
								                            }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                        ShowNotify("成功移库" + Grid1.SelectedRowIDArray.Count().ToString() + "个!", MessageBoxIcon.Success);
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                    else
							 | 
						|||
| 
								 | 
							
								                    {
							 | 
						|||
| 
								 | 
							
								                        Alert.ShowInTop("请选择要移出的焊材!", MessageBoxIcon.Warning);
							 | 
						|||
| 
								 | 
							
								                        return;
							 | 
						|||
| 
								 | 
							
								                    }
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            else
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Alert.ShowInTop("未发现移出仓库入库信息!", MessageBoxIcon.Warning);
							 | 
						|||
| 
								 | 
							
								                return;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        private void BindGrid()
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            string strSql = @"SELECT StockIn.StockInId,StockIn.WeldId,Weld.ConsumablesCode,Weld.ConsumablesName,Weld.SteelFormat,StockIn.Warrantybook,StockIn.Amount,
							 | 
						|||
| 
								 | 
							
								                                    case Weld.ConsumablesType when '1' then '焊丝' when '2' then '焊条' when '3' then '焊剂' else '' end as WeldTypeName,Weld.WeldUnit
							 | 
						|||
| 
								 | 
							
								                              FROM dbo.Weld_StockIn AS StockIn
							 | 
						|||
| 
								 | 
							
								                              LEFT JOIN dbo.Base_Consumables AS Weld ON Weld.ConsumablesId=StockIn.WeldId
							 | 
						|||
| 
								 | 
							
								                              WHERE StockIn.Flag='1'  ";
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            List<SqlParameter> listStr = new List<SqlParameter>();
							 | 
						|||
| 
								 | 
							
								            if (drpUnitStoreOut.SelectedValue != BLL.Const._Null)
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                strSql += " AND StockIn.UnitStoreId = @UnitStoreId";
							 | 
						|||
| 
								 | 
							
								                listStr.Add(new SqlParameter("@UnitStoreId", drpUnitStoreOut.SelectedValue));
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            if (!string.IsNullOrEmpty(this.txtCode.Text.Trim()))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                strSql += " AND Weld.ConsumablesCode LIKE @ConsumablesCode";
							 | 
						|||
| 
								 | 
							
								                listStr.Add(new SqlParameter("@ConsumablesCode", "%" + this.txtCode.Text.Trim() + "%"));
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            if (!string.IsNullOrEmpty(this.txtWarrantybook.Text.Trim()))
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                strSql += " AND StockIn.Warrantybook LIKE @Warrantybook";
							 | 
						|||
| 
								 | 
							
								                listStr.Add(new SqlParameter("@Warrantybook", "%" + this.txtWarrantybook.Text.Trim() + "%"));
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            SqlParameter[] parameter = listStr.ToArray();
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								            Grid1.DataSource = dt;
							 | 
						|||
| 
								 | 
							
								            Grid1.DataBind();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        protected void rdIsAll_SelectedIndexChanged(object sender, EventArgs e)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            if (rdIsAll.SelectedValue == "0")
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                if (this.drpUnitStoreOut.SelectedValue == Const._Null)
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    Alert.ShowInTop("请选择要移出的仓库!", MessageBoxIcon.Warning);
							 | 
						|||
| 
								 | 
							
								                    return;
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								                else
							 | 
						|||
| 
								 | 
							
								                {
							 | 
						|||
| 
								 | 
							
								                    Grid1.Hidden = false;
							 | 
						|||
| 
								 | 
							
								                    BindGrid();
							 | 
						|||
| 
								 | 
							
								                }
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								            else
							 | 
						|||
| 
								 | 
							
								            {
							 | 
						|||
| 
								 | 
							
								                Grid1.Hidden = true;
							 | 
						|||
| 
								 | 
							
								            }
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								        /// <summary>
							 | 
						|||
| 
								 | 
							
								        /// 查询
							 | 
						|||
| 
								 | 
							
								        /// </summary>
							 | 
						|||
| 
								 | 
							
								        /// <param name="sender"></param>
							 | 
						|||
| 
								 | 
							
								        /// <param name="e"></param>
							 | 
						|||
| 
								 | 
							
								        protected void TextBox_TextChanged(object sender, EventArgs e)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            BindGrid();
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |