Exemplo n.º 1
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_save_Click(object sender, EventArgs e)
        {
            obj = new T_Inventory_ti();
            if (cbo_houseName.SelectedValue.ToString() != string.Empty)//仓库
            {
                obj.HouseCode = cbo_houseName.SelectedValue.ToString().Trim();
                obj.HouseName = cbo_houseName.Text.Trim();
            }
            if (cbo_areaName.SelectedValue.ToString() != "-1")//库区
            {
                obj.StorageArea = cbo_areaName.SelectedValue.ToString();
            }
            if (cbo_PN.Text.ToString() != string.Empty)//料号
            {
                obj.PN = cbo_PN.Text.ToString().Trim();
            }
            string varMsg   = string.Empty;
            bool   isSucess = Bll_Inventory_ti.Insert(obj, out varMsg);

            if (isSucess)
            {
                this.result = DialogResult.OK;
                this.Close();
            }
            else
            {
                MsgBox.Error(varMsg);
                return;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 校验是否可以开单,并返回检验单号
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="obj"></param>
        /// <param name="varMsg"></param>
        /// <returns></returns>
        public static string CheckIsOK(DataTable dt, T_Inventory_ti obj, ref string varMsg)
        {
            string        where_housecode = string.Format(" and a.HouseCode='{0}'", obj.HouseCode);
            string        strSQL          = string.Format(@"     
            select a.InventoryCode,a.HouseCode,d.Area_SN,d.MaterialCode from dbo.T_Inventory_ti as a 
            inner join dbo.T_Inventory_Detail as b on a.InventoryCode=b.InventoryCode
			inner join dbo.T_InventoryDetail_tid as c on c.InventoryCode=a.InventoryCode
			inner join dbo.T_Bllb_StockInfo_tbsi as d on c.ReelId=d.SerialNumber
            where a.Status<>'2' {0} group by a.InventoryCode,a.HouseCode,d.Area_SN,d.MaterialCode ", where_housecode);
            DataTable     dt_Code         = NMS.QueryDataTable(PubUtils.uContext, strSQL);
            List <string> lstGroup        = new List <string>();

            if (dt_Code.Rows.Count > 0)
            {
                foreach (DataRow dr in dt_Code.Rows)
                {
                    lstGroup.Add(string.Format("{0}{1}{2}", dr["HouseCode"].ToString() == string.Empty ? "0" : dr["HouseCode"].ToString(),
                                               dr["Area_SN"].ToString() == string.Empty ? "0" : dr["Area_SN"].ToString(),
                                               dr["MaterialCode"].ToString() == string.Empty ? "0" : dr["MaterialCode"].ToString()));
                }
                if (obj.StorageArea == null && obj.PN == null)//库区为空  料号为空
                {
                    foreach (string item in lstGroup)
                    {
                        if (item.StartsWith(obj.HouseCode))
                        {
                            varMsg = "开单失败,存在未完成的盘点单!";
                            return(null);
                        }
                    }
                }
                else if (obj.StorageArea != null && obj.PN != null)//库区不为空  料号不为空
                {
                    foreach (string item in lstGroup)
                    {
                        if (item.StartsWith(string.Format("{0}00", obj.HouseCode)) ||
                            item.StartsWith(string.Format("{0}{1}", obj.HouseCode, obj.StorageArea)) ||
                            (item.StartsWith(string.Format("{0}", obj.HouseCode)) &&
                             item.EndsWith(string.Format("{0}", obj.PN))))
                        {
                            varMsg = "开单失败,存在未完成的盘点单!";
                            return(null);
                        }
                    }
                }
                else if (obj.StorageArea != null && obj.PN == null)//库区不为空  料号为空
                {
                    foreach (string item in lstGroup)
                    {
                        if (item.StartsWith(string.Format("{0}00", obj.HouseCode)) ||
                            item.StartsWith(string.Format("{0}{1}", obj.HouseCode, obj.StorageArea)))
                        {
                            varMsg = "开单失败,存在未完成的盘点单!";
                            return(null);
                        }
                    }
                }
                else if (obj.StorageArea == null && obj.PN != null)//库位为空  料号不为空
                {
                    foreach (string item in lstGroup)
                    {
                        if (item.StartsWith(string.Format("{0}00", obj.HouseCode)) ||
                            (item.StartsWith(string.Format("{0}", obj.HouseCode)) && item.EndsWith(string.Format("{0}", obj.PN))))
                        {
                            varMsg = "开单失败,存在未完成的盘点单!";
                            return(null);
                        }
                    }
                }
            }
            varMsg = "OK";
            return(GetSn());
        }
Exemplo n.º 3
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="varMsg"></param>
        /// <returns></returns>
        public static bool Insert(T_Inventory_ti obj, out string varMsg)
        {
            //1.开单
            DataTable dt_check      = new DataTable();
            string    msg           = string.Empty;
            string    inventoryCode = CheckIsOK(dt_check, obj, ref msg);

            if (msg == "OK")
            {
                obj.InventoryCode = inventoryCode;
            }
            else
            {
                varMsg = msg;
                return(false);
            }
            //2.取出对应仓库 料号的 数量
            string querypnWhere = string.Format(" where 1=1 and Lock_Flag='0' and Storage_SN='{0}'", obj.HouseCode);

            if (obj.StorageArea != null)
            {
                querypnWhere = string.Format("{0} and Area_SN='{1}'", querypnWhere, obj.StorageArea);
            }
            if (obj.PN != null)
            {
                querypnWhere = string.Format("{0} and MaterialCode='{1}'", querypnWhere, obj.PN);
            }
            string    sqlInsert = string.Format(@"
declare @Qty decimal
declare @PartNumber nvarchar(50)
--获得对应仓库 每个料号的数量
if not exists(select *  from T_Bllb_StockInfo_tbsi {8})
	begin
		select '0','仓库没有对应的料号' return
	end
else
	begin
        insert into T_Inventory_ti(InventoryCode,HouseCode,HouseName,PN,StorageArea,StorageLocation,Creator,CreateTime,Status) values('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', getdate(),'{7}')
		select MaterialCode,sum(QTY) as 'Qty' into #a from T_Bllb_StockInfo_tbsi {8} group by MaterialCode
		select '1',* from #a 
		drop table #a
		return
	end
", obj.InventoryCode, obj.HouseCode, obj.HouseName, obj.PN, obj.StorageArea == null ? string.Empty : obj.StorageArea, obj.StorageLocation == null ? string.Empty : obj.StorageLocation, PubUtils.uContext.UserName, 0, querypnWhere);
            DataTable dt_Insert = NMS.QueryDataTable(PubUtils.uContext, sqlInsert);

            if (dt_Insert.Rows.Count > 0)
            {
                //有对应的料号
                if (dt_Insert.Rows[0][0].ToString() == "1")
                {
                    foreach (DataRow dr in dt_Insert.Rows)
                    {
                        string sqlInsert_PnQty = string.Format(@"insert into T_Inventory_Detail (InventoryCode,PN,Qty,CurrentQty,UnQty,DifferQty) values('{0}','{1}','{2}',0,'{2}',0)", obj.InventoryCode, dr["MaterialCode"].ToString(), dr["QTY"].ToString());
                        NMS.ExecTransql(PubUtils.uContext, sqlInsert_PnQty);
                    }
                }
                else
                {
                    //仓库没有对应的料号
                    varMsg = "仓库没有对应的料号,开单失败!";
                    return(false);
                }
            }
            //获取对应的料盘编码
            string    sqlInsert_Reelid = string.Format(@"select SerialNumber,QTY from dbo.T_Bllb_StockInfo_tbsi {0} group by SerialNumber,QTY
                                                      select SerialNumber,QTY from #a 
                                                      drop table #a", querypnWhere);
            DataTable dt_reelidInsert  = NMS.QueryDataTable(PubUtils.uContext, sqlInsert_Reelid);

            if (dt_reelidInsert.Rows.Count > 0)
            {
                foreach (DataRow dr in dt_reelidInsert.Rows)
                {
                    string sqlInsert_ReelidQty = string.Format(@"
INSERT INTO T_InventoryDetail_tid
            ( InventoryCode ,
              ReelId ,
              Qty ,
              CurrentQty ,
              UnQty ,
              DifferQty ,
              Creator ,
              CreateTime ,
              Status
            )
     VALUES ( '{0}' ,
              '{1}' ,
              '{2}' ,
              0 ,
              '{2}' ,
              0 ,
              '{3}' ,
              GETDATE() ,
              1
            )
     UPDATE T_Bllb_StockInfo_tbsi
     SET    Lock_Flag = '1'
     WHERE  SerialNumber = '{1}'", obj.InventoryCode, dr["SerialNumber"].ToString(), dr["QTY"].ToString(),
                                                               PubUtils.uContext.UserName);
                    NMS.ExecTransql(PubUtils.uContext, sqlInsert_ReelidQty);
                }
            }
            varMsg = "OK";
            return(true);
        }