Exemple #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(TH.clsU8.Model.rdrecords08 model)
        {
            StringBuilder strSql  = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();

            if (model.AutoID != null)
            {
                strSql1.Append("AutoID,");
                strSql2.Append("" + model.AutoID + ",");
            }
            if (model.ID != null)
            {
                strSql1.Append("ID,");
                strSql2.Append("" + model.ID + ",");
            }
            if (model.cInvCode != null)
            {
                strSql1.Append("cInvCode,");
                strSql2.Append("'" + model.cInvCode + "',");
            }
            if (model.iNum != null)
            {
                strSql1.Append("iNum,");
                strSql2.Append("" + model.iNum + ",");
            }
            if (model.iQuantity != null)
            {
                strSql1.Append("iQuantity,");
                strSql2.Append("" + model.iQuantity + ",");
            }
            if (model.iUnitCost != null)
            {
                strSql1.Append("iUnitCost,");
                strSql2.Append("" + model.iUnitCost + ",");
            }
            if (model.iPrice != null)
            {
                strSql1.Append("iPrice,");
                strSql2.Append("" + model.iPrice + ",");
            }
            if (model.iAPrice != null)
            {
                strSql1.Append("iAPrice,");
                strSql2.Append("" + model.iAPrice + ",");
            }
            if (model.iPUnitCost != null)
            {
                strSql1.Append("iPUnitCost,");
                strSql2.Append("" + model.iPUnitCost + ",");
            }
            if (model.iPPrice != null)
            {
                strSql1.Append("iPPrice,");
                strSql2.Append("" + model.iPPrice + ",");
            }
            if (model.cBatch != null)
            {
                strSql1.Append("cBatch,");
                strSql2.Append("'" + model.cBatch + "',");
            }
            if (model.cVouchCode != null)
            {
                strSql1.Append("cVouchCode,");
                strSql2.Append("" + model.cVouchCode + ",");
            }
            if (model.cInVouchCode != null)
            {
                strSql1.Append("cInVouchCode,");
                strSql2.Append("'" + model.cInVouchCode + "',");
            }
            if (model.cinvouchtype != null)
            {
                strSql1.Append("cinvouchtype,");
                strSql2.Append("'" + model.cinvouchtype + "',");
            }
            if (model.iSOutQuantity != null)
            {
                strSql1.Append("iSOutQuantity,");
                strSql2.Append("" + model.iSOutQuantity + ",");
            }
            if (model.iSOutNum != null)
            {
                strSql1.Append("iSOutNum,");
                strSql2.Append("" + model.iSOutNum + ",");
            }
            if (model.cFree1 != null)
            {
                strSql1.Append("cFree1,");
                strSql2.Append("'" + model.cFree1 + "',");
            }
            if (model.cFree2 != null)
            {
                strSql1.Append("cFree2,");
                strSql2.Append("'" + model.cFree2 + "',");
            }
            if (model.iFlag != null)
            {
                strSql1.Append("iFlag,");
                strSql2.Append("" + model.iFlag + ",");
            }
            if (model.iFNum != null)
            {
                strSql1.Append("iFNum,");
                strSql2.Append("" + model.iFNum + ",");
            }
            if (model.iFQuantity != null)
            {
                strSql1.Append("iFQuantity,");
                strSql2.Append("" + model.iFQuantity + ",");
            }
            if (model.dVDate != null)
            {
                strSql1.Append("dVDate,");
                strSql2.Append("'" + model.dVDate + "',");
            }
            if (model.iTrIds != null)
            {
                strSql1.Append("iTrIds,");
                strSql2.Append("" + model.iTrIds + ",");
            }
            if (model.cPosition != null)
            {
                strSql1.Append("cPosition,");
                strSql2.Append("'" + model.cPosition + "',");
            }
            if (model.cDefine22 != null)
            {
                strSql1.Append("cDefine22,");
                strSql2.Append("'" + model.cDefine22 + "',");
            }
            if (model.cDefine23 != null)
            {
                strSql1.Append("cDefine23,");
                strSql2.Append("'" + model.cDefine23 + "',");
            }
            if (model.cDefine24 != null)
            {
                strSql1.Append("cDefine24,");
                strSql2.Append("'" + model.cDefine24 + "',");
            }
            if (model.cDefine25 != null)
            {
                strSql1.Append("cDefine25,");
                strSql2.Append("'" + model.cDefine25 + "',");
            }
            if (model.cDefine26 != null)
            {
                strSql1.Append("cDefine26,");
                strSql2.Append("" + model.cDefine26 + ",");
            }
            if (model.cDefine27 != null)
            {
                strSql1.Append("cDefine27,");
                strSql2.Append("" + model.cDefine27 + ",");
            }
            if (model.cItem_class != null)
            {
                strSql1.Append("cItem_class,");
                strSql2.Append("'" + model.cItem_class + "',");
            }
            if (model.cItemCode != null)
            {
                strSql1.Append("cItemCode,");
                strSql2.Append("'" + model.cItemCode + "',");
            }
            if (model.cName != null)
            {
                strSql1.Append("cName,");
                strSql2.Append("'" + model.cName + "',");
            }
            if (model.cItemCName != null)
            {
                strSql1.Append("cItemCName,");
                strSql2.Append("'" + model.cItemCName + "',");
            }
            if (model.cFree3 != null)
            {
                strSql1.Append("cFree3,");
                strSql2.Append("'" + model.cFree3 + "',");
            }
            if (model.cFree4 != null)
            {
                strSql1.Append("cFree4,");
                strSql2.Append("'" + model.cFree4 + "',");
            }
            if (model.cFree5 != null)
            {
                strSql1.Append("cFree5,");
                strSql2.Append("'" + model.cFree5 + "',");
            }
            if (model.cFree6 != null)
            {
                strSql1.Append("cFree6,");
                strSql2.Append("'" + model.cFree6 + "',");
            }
            if (model.cFree7 != null)
            {
                strSql1.Append("cFree7,");
                strSql2.Append("'" + model.cFree7 + "',");
            }
            if (model.cFree8 != null)
            {
                strSql1.Append("cFree8,");
                strSql2.Append("'" + model.cFree8 + "',");
            }
            if (model.cFree9 != null)
            {
                strSql1.Append("cFree9,");
                strSql2.Append("'" + model.cFree9 + "',");
            }
            if (model.cFree10 != null)
            {
                strSql1.Append("cFree10,");
                strSql2.Append("'" + model.cFree10 + "',");
            }
            if (model.cBarCode != null)
            {
                strSql1.Append("cBarCode,");
                strSql2.Append("'" + model.cBarCode + "',");
            }
            if (model.iNQuantity != null)
            {
                strSql1.Append("iNQuantity,");
                strSql2.Append("" + model.iNQuantity + ",");
            }
            if (model.iNNum != null)
            {
                strSql1.Append("iNNum,");
                strSql2.Append("" + model.iNNum + ",");
            }
            if (model.cAssUnit != null)
            {
                strSql1.Append("cAssUnit,");
                strSql2.Append("'" + model.cAssUnit + "',");
            }
            if (model.dMadeDate != null)
            {
                strSql1.Append("dMadeDate,");
                strSql2.Append("'" + model.dMadeDate + "',");
            }
            if (model.iMassDate != null)
            {
                strSql1.Append("iMassDate,");
                strSql2.Append("" + model.iMassDate + ",");
            }
            if (model.cDefine28 != null)
            {
                strSql1.Append("cDefine28,");
                strSql2.Append("'" + model.cDefine28 + "',");
            }
            if (model.cDefine29 != null)
            {
                strSql1.Append("cDefine29,");
                strSql2.Append("'" + model.cDefine29 + "',");
            }
            if (model.cDefine30 != null)
            {
                strSql1.Append("cDefine30,");
                strSql2.Append("'" + model.cDefine30 + "',");
            }
            if (model.cDefine31 != null)
            {
                strSql1.Append("cDefine31,");
                strSql2.Append("'" + model.cDefine31 + "',");
            }
            if (model.cDefine32 != null)
            {
                strSql1.Append("cDefine32,");
                strSql2.Append("'" + model.cDefine32 + "',");
            }
            if (model.cDefine33 != null)
            {
                strSql1.Append("cDefine33,");
                strSql2.Append("'" + model.cDefine33 + "',");
            }
            if (model.cDefine34 != null)
            {
                strSql1.Append("cDefine34,");
                strSql2.Append("" + model.cDefine34 + ",");
            }
            if (model.cDefine35 != null)
            {
                strSql1.Append("cDefine35,");
                strSql2.Append("" + model.cDefine35 + ",");
            }
            if (model.cDefine36 != null)
            {
                strSql1.Append("cDefine36,");
                strSql2.Append("'" + model.cDefine36 + "',");
            }
            if (model.cDefine37 != null)
            {
                strSql1.Append("cDefine37,");
                strSql2.Append("'" + model.cDefine37 + "',");
            }
            if (model.iCheckIds != null)
            {
                strSql1.Append("iCheckIds,");
                strSql2.Append("" + model.iCheckIds + ",");
            }
            if (model.cBVencode != null)
            {
                strSql1.Append("cBVencode,");
                strSql2.Append("'" + model.cBVencode + "',");
            }
            if (model.chVencode != null)
            {
                strSql1.Append("chVencode,");
                strSql2.Append("'" + model.chVencode + "',");
            }
            if (model.bGsp != null)
            {
                strSql1.Append("bGsp,");
                strSql2.Append("" + (model.bGsp ? 1 : 0) + ",");
            }
            if (model.cGspState != null)
            {
                strSql1.Append("cGspState,");
                strSql2.Append("'" + model.cGspState + "',");
            }
            if (model.cCheckCode != null)
            {
                strSql1.Append("cCheckCode,");
                strSql2.Append("'" + model.cCheckCode + "',");
            }
            if (model.iCheckIdBaks != null)
            {
                strSql1.Append("iCheckIdBaks,");
                strSql2.Append("" + model.iCheckIdBaks + ",");
            }
            if (model.cRejectCode != null)
            {
                strSql1.Append("cRejectCode,");
                strSql2.Append("'" + model.cRejectCode + "',");
            }
            if (model.iRejectIds != null)
            {
                strSql1.Append("iRejectIds,");
                strSql2.Append("" + model.iRejectIds + ",");
            }
            if (model.cCheckPersonCode != null)
            {
                strSql1.Append("cCheckPersonCode,");
                strSql2.Append("'" + model.cCheckPersonCode + "',");
            }
            if (model.dCheckDate != null)
            {
                strSql1.Append("dCheckDate,");
                strSql2.Append("'" + model.dCheckDate + "',");
            }
            if (model.cMassUnit != null)
            {
                strSql1.Append("cMassUnit,");
                strSql2.Append("" + model.cMassUnit + ",");
            }
            if (model.bChecked != null)
            {
                strSql1.Append("bChecked,");
                strSql2.Append("" + (model.bChecked ? 1 : 0) + ",");
            }
            if (model.bLPUseFree != null)
            {
                strSql1.Append("bLPUseFree,");
                strSql2.Append("" + (model.bLPUseFree ? 1 : 0) + ",");
            }
            if (model.iRSRowNO != null)
            {
                strSql1.Append("iRSRowNO,");
                strSql2.Append("" + model.iRSRowNO + ",");
            }
            if (model.iOriTrackID != null)
            {
                strSql1.Append("iOriTrackID,");
                strSql2.Append("" + model.iOriTrackID + ",");
            }
            if (model.coritracktype != null)
            {
                strSql1.Append("coritracktype,");
                strSql2.Append("'" + model.coritracktype + "',");
            }
            if (model.cbaccounter != null)
            {
                strSql1.Append("cbaccounter,");
                strSql2.Append("'" + model.cbaccounter + "',");
            }
            if (model.dbKeepDate != null)
            {
                strSql1.Append("dbKeepDate,");
                strSql2.Append("'" + model.dbKeepDate + "',");
            }
            if (model.bCosting != null)
            {
                strSql1.Append("bCosting,");
                strSql2.Append("" + (model.bCosting ? 1 : 0) + ",");
            }
            if (model.bVMIUsed != null)
            {
                strSql1.Append("bVMIUsed,");
                strSql2.Append("" + (model.bVMIUsed ? 1 : 0) + ",");
            }
            if (model.iVMISettleQuantity != null)
            {
                strSql1.Append("iVMISettleQuantity,");
                strSql2.Append("" + model.iVMISettleQuantity + ",");
            }
            if (model.iVMISettleNum != null)
            {
                strSql1.Append("iVMISettleNum,");
                strSql2.Append("" + model.iVMISettleNum + ",");
            }
            if (model.cvmivencode != null)
            {
                strSql1.Append("cvmivencode,");
                strSql2.Append("'" + model.cvmivencode + "',");
            }
            if (model.iInvSNCount != null)
            {
                strSql1.Append("iInvSNCount,");
                strSql2.Append("" + model.iInvSNCount + ",");
            }
            if (model.cwhpersoncode != null)
            {
                strSql1.Append("cwhpersoncode,");
                strSql2.Append("'" + model.cwhpersoncode + "',");
            }
            if (model.cwhpersonname != null)
            {
                strSql1.Append("cwhpersonname,");
                strSql2.Append("'" + model.cwhpersonname + "',");
            }
            if (model.cserviceoid != null)
            {
                strSql1.Append("cserviceoid,");
                strSql2.Append("'" + model.cserviceoid + "',");
            }
            if (model.cbserviceoid != null)
            {
                strSql1.Append("cbserviceoid,");
                strSql2.Append("'" + model.cbserviceoid + "',");
            }
            if (model.iinvexchrate != null)
            {
                strSql1.Append("iinvexchrate,");
                strSql2.Append("" + model.iinvexchrate + ",");
            }
            if (model.corufts != null)
            {
                strSql1.Append("corufts,");
                strSql2.Append("'" + model.corufts + "',");
            }
            if (model.strContractGUID != null)
            {
                strSql1.Append("strContractGUID,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.iExpiratDateCalcu != null)
            {
                strSql1.Append("iExpiratDateCalcu,");
                strSql2.Append("" + model.iExpiratDateCalcu + ",");
            }
            if (model.cExpirationdate != null)
            {
                strSql1.Append("cExpirationdate,");
                strSql2.Append("'" + model.cExpirationdate + "',");
            }
            if (model.dExpirationdate != null)
            {
                strSql1.Append("dExpirationdate,");
                strSql2.Append("'" + model.dExpirationdate + "',");
            }
            if (model.cciqbookcode != null)
            {
                strSql1.Append("cciqbookcode,");
                strSql2.Append("'" + model.cciqbookcode + "',");
            }
            if (model.iBondedSumQty != null)
            {
                strSql1.Append("iBondedSumQty,");
                strSql2.Append("" + model.iBondedSumQty + ",");
            }
            if (model.iorderdid != null)
            {
                strSql1.Append("iorderdid,");
                strSql2.Append("" + model.iorderdid + ",");
            }
            if (model.iordertype != null)
            {
                strSql1.Append("iordertype,");
                strSql2.Append("" + model.iordertype + ",");
            }
            if (model.iordercode != null)
            {
                strSql1.Append("iordercode,");
                strSql2.Append("'" + model.iordercode + "',");
            }
            if (model.iorderseq != null)
            {
                strSql1.Append("iorderseq,");
                strSql2.Append("" + model.iorderseq + ",");
            }
            if (model.isodid != null)
            {
                strSql1.Append("isodid,");
                strSql2.Append("'" + model.isodid + "',");
            }
            if (model.isotype != null)
            {
                strSql1.Append("isotype,");
                strSql2.Append("" + model.isotype + ",");
            }
            if (model.csocode != null)
            {
                strSql1.Append("csocode,");
                strSql2.Append("'" + model.csocode + "',");
            }
            if (model.isoseq != null)
            {
                strSql1.Append("isoseq,");
                strSql2.Append("" + model.isoseq + ",");
            }
            if (model.cBatchProperty1 != null)
            {
                strSql1.Append("cBatchProperty1,");
                strSql2.Append("" + model.cBatchProperty1 + ",");
            }
            if (model.cBatchProperty2 != null)
            {
                strSql1.Append("cBatchProperty2,");
                strSql2.Append("" + model.cBatchProperty2 + ",");
            }
            if (model.cBatchProperty3 != null)
            {
                strSql1.Append("cBatchProperty3,");
                strSql2.Append("" + model.cBatchProperty3 + ",");
            }
            if (model.cBatchProperty4 != null)
            {
                strSql1.Append("cBatchProperty4,");
                strSql2.Append("" + model.cBatchProperty4 + ",");
            }
            if (model.cBatchProperty5 != null)
            {
                strSql1.Append("cBatchProperty5,");
                strSql2.Append("" + model.cBatchProperty5 + ",");
            }
            if (model.cBatchProperty6 != null)
            {
                strSql1.Append("cBatchProperty6,");
                strSql2.Append("'" + model.cBatchProperty6 + "',");
            }
            if (model.cBatchProperty7 != null)
            {
                strSql1.Append("cBatchProperty7,");
                strSql2.Append("'" + model.cBatchProperty7 + "',");
            }
            if (model.cBatchProperty8 != null)
            {
                strSql1.Append("cBatchProperty8,");
                strSql2.Append("'" + model.cBatchProperty8 + "',");
            }
            if (model.cBatchProperty9 != null)
            {
                strSql1.Append("cBatchProperty9,");
                strSql2.Append("'" + model.cBatchProperty9 + "',");
            }
            if (model.cBatchProperty10 != null)
            {
                strSql1.Append("cBatchProperty10,");
                strSql2.Append("'" + model.cBatchProperty10 + "',");
            }
            if (model.cbMemo != null)
            {
                strSql1.Append("cbMemo,");
                strSql2.Append("'" + model.cbMemo + "',");
            }
            if (model.irowno != null)
            {
                strSql1.Append("irowno,");
                strSql2.Append("" + model.irowno + ",");
            }
            if (model.strowguid != null)
            {
                strSql1.Append("strowguid,");
                strSql2.Append("'" + Guid.NewGuid().ToString() + "',");
            }
            if (model.rowufts != null)
            {
                strSql1.Append("rowufts,");
                strSql2.Append("" + model.rowufts + ",");
            }
            if (model.ipreuseqty != null)
            {
                strSql1.Append("ipreuseqty,");
                strSql2.Append("" + model.ipreuseqty + ",");
            }
            if (model.ipreuseinum != null)
            {
                strSql1.Append("ipreuseinum,");
                strSql2.Append("" + model.ipreuseinum + ",");
            }
            if (model.cbsourcecodels != null)
            {
                strSql1.Append("cbsourcecodels,");
                strSql2.Append("'" + model.cbsourcecodels + "',");
            }
            if (model.iGroupNO != null)
            {
                strSql1.Append("iGroupNO,");
                strSql2.Append("" + model.iGroupNO + ",");
            }
            if (model.iDebitIDs != null)
            {
                strSql1.Append("iDebitIDs,");
                strSql2.Append("" + model.iDebitIDs + ",");
            }
            if (model.idebitchildids != null)
            {
                strSql1.Append("idebitchildids,");
                strSql2.Append("" + model.idebitchildids + ",");
            }
            if (model.OutCopiedQuantity != null)
            {
                strSql1.Append("OutCopiedQuantity,");
                strSql2.Append("" + model.OutCopiedQuantity + ",");
            }
            if (model.cbsysbarcode != null)
            {
                strSql1.Append("cbsysbarcode,");
                strSql2.Append("'" + model.cbsysbarcode + "',");
            }
            strSql.Append("insert into rdrecords08(");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            return(strSql.ToString());
        }
Exemple #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                gridView1.PostEditor();
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                if (lookUpEditRd_Style.EditValue == null || lookUpEditRd_Style.EditValue.ToString().Trim() == "")
                {
                    throw new Exception("Please choose inventory-in type");
                }
                if (lookUpEditcWhCode.EditValue == null || lookUpEditcWhCode.EditValue.ToString().Trim() == "")
                {
                    throw new Exception("Please choose warehouse");
                }

                string        sErr   = "";
                int           iCount = 0;
                SqlConnection conn   = new SqlConnection(sConnString);
                conn.Open();
                //启用事务
                SqlTransaction tran = conn.BeginTransaction();
                try
                {
                    string   sSQL     = "select getdate()";
                    DateTime dNow     = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]);
                    DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd"));

                    if (dtSOMain == null || dtSOMain.Rows.Count == 0)
                    {
                        throw new Exception("Sale Order not exists err");
                    }

                    string sCTCode = dtSOMain.Rows[0]["cSTCode"].ToString().Trim();

                    sSQL = @"
select a.cCode,b.cSoCode 
from rdrecord08 a inner join rdrecords08 b on a.id = b.id
where b.cSoCode = 'aaaaaa'
";
                    sSQL = sSQL.Replace("aaaaaa", s单据号);
                    DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        throw new Exception("exist \n" + dt.Rows[0]["cCode"].ToString().Trim());
                    }

                    DateTime dDate = BaseFunction.ReturnDate(dtSOMain.Rows[0]["dDate"]);

                    sSQL = "select isnull(bflag_ST,0) as bflag from GL_mend where iYPeriod = '" + dDate.ToString("yyyyMM") + "'";
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];
                    if (dt == null || dt.Rows.Count == 0)
                    {
                        throw new Exception("Access module state failure");
                    }
                    int i结账 = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]);
                    if (i结账 > 0)
                    {
                        throw new Exception(dDate.ToString("yyyy-MM") + " have checked out");
                    }

                    //获得单据号
                    sSQL = "select cNumber from VoucherHistory with (ROWLOCK) WHERE (CardNumber = '0301') AND (cContent = '日期') AND (cContentRule = 'YYYY') AND (cSeed = 'aaaaaa')";
                    sSQL = sSQL.Replace("aaaaaa", dDate.ToString("yyyy"));
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    long lCodeRD = 0;
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        lCodeRD = BaseFunction.ReturnLong(dt.Rows[0]["cNumber"]);
                    }
                    else
                    {
                        lCodeRD = 0;
                    }

                    long lID          = -1;
                    long lIDRDDetails = -1;
                    sSQL = @"
declare @p5 int
set @p5=aaaaaa
declare @p6 int
set @p6=bbbbbb
exec sp_GetId N'00',N'dddddd',N'rd',cccccc,@p5 output,@p6 output,default
select @p5, @p6
";
                    sSQL = sSQL.Replace("aaaaaa", lID.ToString());
                    sSQL = sSQL.Replace("bbbbbb", lIDRDDetails.ToString());
                    sSQL = sSQL.Replace("cccccc", 1.ToString());
                    sSQL = sSQL.Replace("dddddd", s数据库.Substring(7, 3));
                    dt   = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0];

                    lID          = BaseFunction.ReturnLong(dt.Rows[0][0]) - 1;
                    lIDRDDetails = BaseFunction.ReturnLong(dt.Rows[0][1]) - 1;

                    //ArrayList aList = new ArrayList();

                    TH.clsU8.Model.RdRecord08 model = new TH.clsU8.Model.RdRecord08();
                    lID     += 1;
                    model.ID = lID;

                    model.bRdFlag    = 1;
                    model.cVouchType = "08";
                    model.cBusType   = "其他入库";
                    model.cSource    = "库存";
                    //model.cBusCode =
                    model.cWhCode = lookUpEditcWhCode.EditValue.ToString().Trim(); //需要仓库默认值
                    model.dDate   = dDate;                                         //需要默认值

                    lCodeRD += 1;
                    string sCodeRD = lCodeRD.ToString();
                    while (sCodeRD.Length < 6)
                    {
                        sCodeRD = "0" + sCodeRD;
                    }
                    model.cCode   = "MI" + model.dDate.Year.ToString() + sCodeRD;
                    model.cRdCode = lookUpEditRd_Style.EditValue.ToString().Trim();      //需要默认值
                    //model.cDepCode = ""
                    //model.cPersonCode;
                    //model.cPTCode;
                    //model.cSTCode;
                    //model.cCusCode;
                    //model.cVenCode;
                    //model.cOrderCode;
                    //model.cARVCode;
                    //model.cBillCode;
                    //model.cDLCode;
                    //model.cProBatch;
                    model.cHandler = sUserName;
                    //model.cMemo;
                    model.bTransFlag = false;
                    //model.cAccounter;
                    model.cMaker   = sUserName;
                    model.cDefine1 = dtSOMain.Rows[0]["cDefine1"].ToString();
                    model.cDefine2 = dtSOMain.Rows[0]["cDefine2"].ToString();
                    model.cDefine3 = dtSOMain.Rows[0]["cDefine3"].ToString();

                    if (dtSOMain.Rows[0]["cDefine4"].ToString().Trim() != "")
                    {
                        model.cDefine4 = BaseFunction.ReturnDate(dtSOMain.Rows[0]["cDefine4"]);
                    }
                    if (dtSOMain.Rows[0]["cDefine5"].ToString().Trim() != "")
                    {
                        model.cDefine5 = BaseFunction.ReturnLong(dtSOMain.Rows[0]["cDefine5"]);
                    }
                    if (dtSOMain.Rows[0]["cDefine6"].ToString().Trim() != "")
                    {
                        model.cDefine6 = BaseFunction.ReturnDate(dtSOMain.Rows[0]["cDefine6"]);
                    }
                    if (dtSOMain.Rows[0]["cDefine7"].ToString().Trim() != "")
                    {
                        model.cDefine7 = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["cDefine7"]);
                    }
                    model.cDefine8  = dtSOMain.Rows[0]["cDefine8"].ToString();
                    model.cDefine9  = dtSOMain.Rows[0]["cDefine9"].ToString();
                    model.cDefine10 = dtSOMain.Rows[0]["cDefine10"].ToString();
                    //model.dKeepDate;
                    model.dVeriDate = dDate;
                    model.bpufirst  = false;
                    model.biafirst  = false;
                    //model.iMQuantity;
                    //model.dARVDate;
                    //model.cChkCode;
                    //model.dChkDate;
                    //model.cChkPerson;
                    model.VT_ID     = 67;
                    model.bIsSTQc   = false;
                    model.cDefine11 = dtSOMain.Rows[0]["cDefine11"].ToString();
                    model.cDefine12 = dtSOMain.Rows[0]["cDefine12"].ToString();
                    model.cDefine13 = dtSOMain.Rows[0]["cDefine13"].ToString();
                    //model.cDefine14 = dtSOMain.Rows[0]["cDefine14"].ToString();
                    model.cDefine14 = dtSOMain.Rows[0]["cSOCode"].ToString();

                    if (dtSOMain.Rows[0]["cDefine15"].ToString() != "")
                    {
                        model.cDefine15 = BaseFunction.ReturnLong(dtSOMain.Rows[0]["cDefine15"]);
                    }
                    if (dtSOMain.Rows[0]["cDefine16"].ToString() != "")
                    {
                        model.cDefine16 = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["cDefine16"]);
                    }
                    //model.gspcheck;
                    //model.ufts;
                    //model.iExchRate;
                    //model.cExch_Name;
                    model.bOMFirst         = false;
                    model.bFromPreYear     = false;
                    model.bIsLsQuery       = false;
                    model.bIsComplement    = 0;
                    model.iDiscountTaxType = 0;
                    model.ireturncount     = 0;
                    model.iverifystate     = 0;
                    model.iswfcontrolled   = 0;
                    //model.cModifyPerson;
                    //model.dModifyDate;
                    //model.dnmaketime;
                    //model.dnmodifytime;
                    //model.dnverifytime;
                    model.bredvouch = 0;
                    //model.iFlowId;
                    //model.cPZID;
                    //model.cSourceLs;
                    //model.cSourceCodeLs;
                    model.iPrintCount = 0;
                    //model.ctransflag;
                    //model.csysbarcode;
                    //model.cCurrentAuditor;
                    TH.clsU8.DAL.RdRecord08 dal = new TH.clsU8.DAL.RdRecord08();
                    sSQL = dal.Add(model);
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    for (int i = 0; i < dtSOMain.Rows.Count; i++)
                    {
                        lIDRDDetails += 1;

                        TH.clsU8.Model.rdrecords08 modelsRD = new TH.clsU8.Model.rdrecords08();
                        modelsRD.AutoID = lIDRDDetails;


                        modelsRD.ID       = model.ID;
                        modelsRD.cInvCode = dtSOMain.Rows[i]["cInvCode"].ToString().Trim();

                        if (dtSOMain.Rows[i]["iNum"].ToString().Trim() != "")
                        {
                            modelsRD.iNum = BaseFunction.ReturnDecimal(dtSOMain.Rows[i]["iNum"]);
                        }
                        modelsRD.iQuantity = BaseFunction.ReturnDecimal(dtSOMain.Rows[i]["iQuantity"]);
                        //modelsRD.iUnitCost;
                        //modelsRD.iPrice;
                        //modelsRD.iAPrice;
                        //modelsRD.iPUnitCost;
                        //modelsRD.iPPrice;

                        bool bBatch = BaseFunction.ReturnBool(dtSOMain.Rows[i]["bInvBatch"]);
                        if (bBatch)
                        {
                            modelsRD.cBatch = dtSOMain.Rows[i]["cDefine25"].ToString().Trim();
                            if (modelsRD.cBatch == "")
                            {
                                modelsRD.cBatch = dNow.ToString("yyyyMMdd");
                            }
                        }
                        //modelsRD.cVouchCode;
                        //modelsRD.cInVouchCode;
                        //modelsRD.cinvouchtype;
                        //modelsRD.iSOutQuantity;
                        //modelsRD.iSOutNum;
                        //modelsRD.cFree1;
                        //modelsRD.cFree2;
                        modelsRD.iFlag = 0;
                        //modelsRD.iFNum;
                        //modelsRD.iFQuantity;
                        //modelsRD.dVDate;
                        //modelsRD.iTrIds;
                        //modelsRD.cPosition;
                        //modelsRD.cDefine22;
                        //modelsRD.cDefine23;
                        //modelsRD.cDefine24;
                        //modelsRD.cDefine25;
                        //modelsRD.cDefine26;
                        //modelsRD.cDefine27;
                        //modelsRD.cItem_class;
                        //modelsRD.cItemCode;
                        //modelsRD.cName;
                        //modelsRD.cItemCName;
                        //modelsRD.cFree3;
                        //modelsRD.cFree4;
                        //modelsRD.cFree5;
                        //modelsRD.cFree6;
                        //modelsRD.cFree7;
                        //modelsRD.cFree8;
                        //modelsRD.cFree9;
                        //modelsRD.cFree10;
                        //modelsRD.cBarCode;
                        //modelsRD.iNQuantity;
                        //modelsRD.iNNum;
                        //modelsRD.cAssUnit;
                        //modelsRD.dMadeDate;
                        //modelsRD.iMassDate;
                        //modelsRD.cDefine28;
                        //modelsRD.cDefine29;
                        //modelsRD.cDefine30;
                        //modelsRD.cDefine31;
                        //modelsRD.cDefine32;
                        //modelsRD.cDefine33;
                        //modelsRD.cDefine34;
                        //modelsRD.cDefine35;
                        //modelsRD.cDefine36;
                        //modelsRD.cDefine37;
                        //modelsRD.iCheckIds;
                        //modelsRD.cBVencode;
                        //modelsRD.chVencode;
                        //modelsRD.bGsp;
                        //modelsRD.cGspState;
                        //modelsRD.cCheckCode;
                        //modelsRD.iCheckIdBaks;
                        //modelsRD.cRejectCode;
                        //modelsRD.iRejectIds;
                        //modelsRD.cCheckPersonCode;
                        //modelsRD.dCheckDate;
                        //modelsRD.cMassUnit;
                        //modelsRD.bChecked;
                        modelsRD.bLPUseFree = false;
                        //modelsRD.iRSRowNO;
                        //modelsRD.iOriTrackID;
                        //modelsRD.coritracktype;
                        //modelsRD.cbaccounter;
                        //modelsRD.dbKeepDate;
                        modelsRD.bCosting = true;
                        modelsRD.bVMIUsed = false;
                        //modelsRD.iVMISettleQuantity;
                        //modelsRD.iVMISettleNum;
                        //modelsRD.cvmivencode;
                        //modelsRD.iInvSNCount;
                        //modelsRD.cwhpersoncode;
                        //modelsRD.cwhpersonname;
                        //modelsRD.cserviceoid;
                        //modelsRD.cbserviceoid;
                        //modelsRD.iinvexchrate;
                        //modelsRD.corufts;
                        //modelsRD.strContractGUID;
                        modelsRD.iExpiratDateCalcu = 0;
                        //modelsRD.cExpirationdate;
                        //modelsRD.dExpirationdate;
                        //modelsRD.cciqbookcode;
                        //modelsRD.iBondedSumQty;
                        //modelsRD.iorderdid;
                        modelsRD.iordertype = 0;
                        //modelsRD.iordercode;
                        //modelsRD.iorderseq;
                        modelsRD.isodid  = dtSOMain.Rows[i]["isosid"].ToString().Trim();
                        modelsRD.isotype = 0;
                        modelsRD.csocode = s单据号;
                        modelsRD.isoseq  = BaseFunction.ReturnInt(dtSOMain.Rows[i]["iRowNo"]);
                        //modelsRD.cBatchProperty1;
                        //modelsRD.cBatchProperty2;
                        //modelsRD.cBatchProperty3;
                        //modelsRD.cBatchProperty4;
                        //modelsRD.cBatchProperty5;
                        //modelsRD.cBatchProperty6;
                        //modelsRD.cBatchProperty7;
                        //modelsRD.cBatchProperty8;
                        //modelsRD.cBatchProperty9;
                        //modelsRD.cBatchProperty10;
                        //modelsRD.cbMemo;
                        modelsRD.irowno = i + 1;
                        //modelsRD.strowguid;
                        //modelsRD.rowufts;
                        //modelsRD.ipreuseqty;
                        //modelsRD.ipreuseinum;
                        //modelsRD.cbsourcecodels;
                        //modelsRD.iGroupNO;
                        //modelsRD.iDebitIDs;
                        //modelsRD.idebitchildids;
                        //modelsRD.OutCopiedQuantity;
                        //modelsRD.cbsysbarcode

                        TH.clsU8.DAL.rdrecords08 dalsRD = new TH.clsU8.DAL.rdrecords08();
                        sSQL   = dalsRD.Add(modelsRD);
                        iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                        sSQL = @"
if exists
    (select * from  CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode'
        and isnull(cFree1,'') = @cFree1 
        and isnull(cFree2,'') = @cFree2
        and isnull(cFree3,'') = @cFree3
        and isnull(cFree4,'') = @cFree4
        and isnull(cFree5,'') = @cFree5
        and isnull(cFree6,'') = @cFree6
        and isnull(cFree7,'') = @cFree7
        and isnull(cFree8,'') = @cFree8
        and isnull(cFree9,'') = @cFree9
        and isnull(cFree10,'') = @cFree10
        and isnull(cBatch,'') = @cBatch 
    )
    update  CurrentStock set iQuantity = isnull(iQuantity,0) + @iQuantity  
    where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' 
        and isnull(cFree1,'') = @cFree1 
        and isnull(cFree2,'') = @cFree2
        and isnull(cFree3,'') = @cFree3
        and isnull(cFree4,'') = @cFree4
        and isnull(cFree5,'') = @cFree5
        and isnull(cFree6,'') = @cFree6
        and isnull(cFree7,'') = @cFree7
        and isnull(cFree8,'') = @cFree8
        and isnull(cFree9,'') = @cFree9
        and isnull(cFree10,'') = @cFree10
        and isnull(cBatch,'') = @cBatch 
else 
    begin 
        declare @itemid varchar(20); 
        declare @iCount int;  
        select @iCount=count(itemid) from CurrentStock where cInvCode = '@cInvCode';
        if( @iCount > 0 )
	        select @itemid=itemid from CurrentStock where cInvCode = '@cInvCode';
        else  
            select @itemid=max(itemid+1) from CurrentStock  
            insert into CurrentStock(cWhCode,cInvCode,iQuantity,itemid, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,cBatch,iSoDid)
            values('@cWhCode','@cInvCode', @iQuantity,isnull(@itemid,1), @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,@cBatch,'') 
    end
";
                        sSQL = sSQL.Replace("@cInvCode", modelsRD.cInvCode);
                        sSQL = sSQL.Replace("@cWhCode", model.cWhCode);
                        sSQL = sSQL.Replace("@iQuantity", modelsRD.iQuantity.ToString());
                        sSQL = sSQL.Replace("@iNum", modelsRD.iNum.ToString());
                        sSQL = sSQL.Replace("@cFree10", modelsRD.cFree10 == null ? "''" : "'" + modelsRD.cFree10 + "'");
                        sSQL = sSQL.Replace("@cFree1", modelsRD.cFree1 == null ? "''" : "'" + modelsRD.cFree1 + "'");
                        sSQL = sSQL.Replace("@cFree2", modelsRD.cFree2 == null ? "''" : "'" + modelsRD.cFree2 + "'");
                        sSQL = sSQL.Replace("@cFree3", modelsRD.cFree3 == null ? "''" : "'" + modelsRD.cFree3 + "'");
                        sSQL = sSQL.Replace("@cFree4", modelsRD.cFree4 == null ? "''" : "'" + modelsRD.cFree4 + "'");
                        sSQL = sSQL.Replace("@cFree5", modelsRD.cFree5 == null ? "''" : "'" + modelsRD.cFree5 + "'");
                        sSQL = sSQL.Replace("@cFree6", modelsRD.cFree6 == null ? "''" : "'" + modelsRD.cFree6 + "'");
                        sSQL = sSQL.Replace("@cFree7", modelsRD.cFree7 == null ? "''" : "'" + modelsRD.cFree7 + "'");
                        sSQL = sSQL.Replace("@cFree8", modelsRD.cFree8 == null ? "''" : "'" + modelsRD.cFree8 + "'");
                        sSQL = sSQL.Replace("@cFree9", modelsRD.cFree9 == null ? "''" : "'" + modelsRD.cFree9 + "'");
                        sSQL = sSQL.Replace("@cBatch", modelsRD.cBatch == null ? "''" : "'" + modelsRD.cBatch + "'");
                        DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);
                    }


                    if (sErr != "")
                    {
                        throw new Exception(sErr);
                    }

                    sSQL = @"
exec ST_SaveForStock N'08',N'aaaaaa',1,0 ,1
";
                    sSQL = sSQL.Replace("aaaaaa", lID.ToString());
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    sSQL = @"
exec ST_SaveForTrackStock N'08',N'aaaaaa', 0 ,1
";
                    sSQL = sSQL.Replace("aaaaaa", lID.ToString());
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    sSQL = @"
exec IA_SP_WriteUnAccountVouchForST 'aaaaaa',N'08'
";
                    sSQL = sSQL.Replace("aaaaaa", lID.ToString());
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);


                    if (lID > 1000000000)
                    {
                        lID = lID - 1000000000;
                    }
                    if (lIDRDDetails > 1000000000)
                    {
                        lIDRDDetails = lIDRDDetails - 1000000000;
                    }
                    sSQL = "update UFSystem..UA_Identity set iFatherId = " + lID.ToString() + ",iChildId = " + lIDRDDetails + " where cAcc_Id = '" + s数据库.Substring(7, 3) + "' and cVouchType = 'rd'";
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    sSQL = @"
if exists(select * from VoucherHistory where  (CardNumber = '0301') AND (cContent = '日期') AND (cContentRule = 'YYYY') AND (cSeed = 'bbbbbb'))
	update VoucherHistory set cNumber = aaaaaa  where  (CardNumber = '0301') AND (cContent = '日期') AND (cContentRule = 'YYYY') AND (cSeed = 'bbbbbb')
else
	insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty)
	values('0301','日期','YYYY','bbbbbb','1',0)
";
                    sSQL = sSQL.Replace("aaaaaa", lCodeRD.ToString());
                    sSQL = sSQL.Replace("bbbbbb", model.dDate.ToString("yyyy"));
                    DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL);

                    if (iCount > 0)
                    {
                        tran.Commit();
                        MessageBox.Show("OK\n" + model.cCode);
                        this.Close();
                    }
                    else
                    {
                        throw new Exception("Save failed");
                    }
                }
                catch (Exception error)
                {
                    tran.Rollback();
                    throw new Exception(error.Message);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }