/// <summary>
 /// 明细参数设置
 /// </summary>
 /// <param name="comm"></param>
 /// <param name="model"></param>
 private static void EditInitailDetailInfo(SqlCommand comm, StorageInProcessDetailModel model)
 {
     //@InNo,@ProductID,@StorageID,@ProductCount,@FromLineNo,getdate(),@ModifiedUserID,@SortNo,@Remark,@CompanyCD,@UnitPrice,@TotalPrice
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD ", model.CompanyCD));//公司代码
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@InNo ", model.InNo));//入库单编号
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@ProductID ", model.ProductID));//物品ID
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@StorageID ", model.StorageID));//仓库ID
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@UnitPrice ", model.UnitPrice));//入库单价
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@TotalPrice ", model.TotalPrice));//金额
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@ProductCount ", model.ProductCount));//入库数量
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@Remark ", model.Remark));//备注
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedUserID ", model.ModifiedUserID));//最后更新用户ID(对应操作用户表中的UserID)
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@SortNo ", model.SortNo));//
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@FromLineNo ", model.FromLineNo));//
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@BatchNo ", model.BatchNo));//批次
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@UsedUnitID ", model.UsedUnitID));
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@UsedUnitCount ", model.UsedUnitCount));
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@UsedPrice ", model.UsedPrice));
     comm.Parameters.Add(SqlHelper.GetParameterFromString("@ExRate ", model.ExRate));
 }
        public static bool ConfirmBill(StorageInProcessModel model)
        {
            ArrayList lstConfirm = new ArrayList();
            StringBuilder sql = new StringBuilder();
            sql.AppendLine(" UPDATE officedba.StorageInProcess SET");
            sql.AppendLine(" Confirmor          = @Confirmor,");
            sql.AppendLine(" confirmDate      = getdate(),");
            sql.AppendLine(" BillStatus              = 2,");
            sql.AppendLine(" ModifiedUserID      = @ModifiedUserID,");
            sql.AppendLine(" ModifiedDate                = getdate()");
            sql.AppendLine(" Where  CompanyCD=@CompanyCD and ID=@ID");

            SqlCommand comm = new SqlCommand();
            comm.CommandText = sql.ToString();
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@Confirmor", model.Confirmor));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ModifiedUserID", model.ModifiedUserID));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@CompanyCD", model.CompanyCD));
            comm.Parameters.Add(SqlHelper.GetParameterFromString("@ID", model.ID));

            lstConfirm.Add(comm);


            List<StorageInProcessDetailModel> modelList = new List<StorageInProcessDetailModel>();
            string sqlSele = "select a.CompanyCD,a.ProductID,a.StorageID,a.BatchNo,a.InNo,a.UnitPrice,a.UsedUnitCount,"
                            + " Convert(varchar(10),c.EnterDate,23) HappenDate,a.ProductCount,a.Remark,a.ProductCount,a.FromLineNo,b.StorageID as DefaultStorageID"
                            + " from officedba.StorageInProcessDetail a"
                            + " left join officedba.ProductInfo b on b.ID=a.ProductID"
                            + " left join officedba.StorageInProcess c on c.InNo=a.InNo and a.CompanyCD = c.CompanyCD "
                            + " where a.CompanyCD='" + model.CompanyCD + "' and a.InNo=(select InNo from officedba.StorageInProcess where ID=" + model.ID + ")";
           
            DataTable dt = SqlHelper.ExecuteSql(sqlSele);
            if (dt != null && dt.Rows.Count > 0)
            {

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    StorageInProcessDetailModel modelDetail = new StorageInProcessDetailModel();
                    StorageAccountModel StorageAccountM = new StorageAccountModel();

                    StorageAccountM.CompanyCD = dt.Rows[i]["CompanyCD"].ToString();
                    StorageAccountM.BillType = 4;
                    if (dt.Rows[i]["BatchNo"].ToString() != "")
                    {
                        modelDetail.BatchNo = dt.Rows[i]["BatchNo"].ToString();
                        StorageAccountM.BatchNo = dt.Rows[i]["BatchNo"].ToString();
                    }
                    StorageAccountM.BillNo = dt.Rows[i]["InNo"].ToString();
                    StorageAccountM.Price = Convert.ToDecimal(dt.Rows[i]["UnitPrice"].ToString());
                    StorageAccountM.HappenDate = Convert.ToDateTime(dt.Rows[i]["HappenDate"].ToString());
                    StorageAccountM.Creator = ((UserInfoUtil)SessionUtil.Session["UserInfo"]).EmployeeID;
                    StorageAccountM.PageUrl = "../Office/StorageManager/StorageInProcessAdd.aspx";
                    StorageAccountM.ReMark = dt.Rows[i]["Remark"].ToString();                   

                    if (dt.Rows[i]["ProductID"].ToString() != "")
                    {
                        modelDetail.ProductID = dt.Rows[i]["ProductID"].ToString();
                        StorageAccountM.ProductID = Convert.ToInt32(dt.Rows[i]["ProductID"].ToString());
                    }
                    if (dt.Rows[i]["StorageID"].ToString() != "")
                    {
                        modelDetail.StorageID = dt.Rows[i]["StorageID"].ToString();
                        StorageAccountM.StorageID = Convert.ToInt32(dt.Rows[i]["StorageID"].ToString());
                    }
                    if (dt.Rows[i]["ProductCount"].ToString() != "")
                    {
                        modelDetail.ProductCount = dt.Rows[i]["ProductCount"].ToString();
                        StorageAccountM.HappenCount = Convert.ToDecimal(dt.Rows[i]["ProductCount"].ToString());
                        StorageAccountM.ProductCount = Convert.ToDecimal(dt.Rows[i]["ProductCount"].ToString());
                    }
                    if (dt.Rows[i]["UsedUnitCount"].ToString() != "")
                    {
                        modelDetail.UsedUnitCount = dt.Rows[i]["UsedUnitCount"].ToString();
                    }
                    if (dt.Rows[i]["FromLineNo"].ToString() != "")
                    {
                        modelDetail.FromLineNo = dt.Rows[i]["FromLineNo"].ToString();
                    }
                    if (dt.Rows[i]["DefaultStorageID"].ToString() != "")
                    {
                        modelDetail.DefaultStorageID = dt.Rows[i]["DefaultStorageID"].ToString();
                    }
                    modelList.Add(modelDetail);

                    SqlCommand commSA = new SqlCommand();
                    commSA = StorageAccountDBHelper.InsertStorageAccountCommand(StorageAccountM, "0");
                    lstConfirm.Add(commSA);
                }
            }
            if (modelList != null && modelList.Count > 0)//明细不为空的时候
            {
                StringBuilder strAddMTDetail = new StringBuilder();
                strAddMTDetail.AppendLine("update officedba.ManufactureTaskDetail set ");
                strAddMTDetail.AppendLine(" InCount =ISNULL(InCount,0)+@ReBackNum where ");
                strAddMTDetail.AppendLine(" TaskNo=(select TaskNo from officedba.ManufactureTask where ID=(select FromBillID from officedba.StorageInProcess where ID=" + model.ID + "))");
                strAddMTDetail.AppendLine(" and SortNo=@SortNo");

                for (int i = 0; i < modelList.Count; i++)
                {
                    SqlCommand commReMT = new SqlCommand();
                    commReMT.CommandText = strAddMTDetail.ToString();
                                        
                    if (modelList[i].UsedUnitCount != null)
                    {
                        commReMT.Parameters.Add(SqlHelper.GetParameterFromString("@ReBackNum", modelList[i].UsedUnitCount));//回写增加的数量
                    }
                    else
                    {
                        commReMT.Parameters.Add(SqlHelper.GetParameterFromString("@ReBackNum", modelList[i].ProductCount));//回写增加的数量
                    }
                    commReMT.Parameters.Add(SqlHelper.GetParameterFromString("@SortNo", modelList[i].FromLineNo));
                    lstConfirm.Add(commReMT);//循环加入数组("已入库数量"增加)

                    SqlCommand commPD = new SqlCommand();
                    if (Exists(modelList[i].BatchNo, modelList[i].StorageID, modelList[i].ProductID, model.CompanyCD))
                    {
                        commPD = updateStorageProduct(modelList[i].BatchNo, modelList[i].ProductID, modelList[i].StorageID, modelList[i].ProductCount, model, true);
                    }
                    else
                    {
                        commPD = InsertStorageProduct(modelList[i].BatchNo,modelList[i].ProductID, modelList[i].StorageID, modelList[i].ProductCount, model.CompanyCD);
                    }
                    lstConfirm.Add(commPD);
                    SqlCommand commRoad = new SqlCommand();
                    commRoad = updateRoadCount(modelList[i].ProductID, modelList[i].DefaultStorageID, modelList[i].ProductCount, model);
                    lstConfirm.Add(commRoad);
                }
            }
            return SqlHelper.ExecuteTransWithArrayList(lstConfirm);
        }