public virtual ActionResult Update(DispatchListsTable dispatchLists)
        {
            int resultado = 0;

            try
            {
                int dispatchID = DispatchLists.UPDDispatchLists(dispatchLists.Name, dispatchLists.DispatchListID);
                int RowCount   = DispatchLists.DelDispatchLists(dispatchID);

                foreach (var account in dispatchLists.Accounts)
                {
                    DispatchsItemsParameters objE = new DispatchsItemsParameters();
                    objE.AccountNumber  = Convert.ToString(account.AccountID);
                    objE.DispatchListID = dispatchID;

                    resultado = DispatchItemsList.InsertDispatchListItems(objE);
                }
            }
            catch (Exception ex)
            {
                var exception = EntityExceptionHelper.GetAndLogNetStepsException(ex, NetSteps.Data.Entities.Constants.NetStepsExceptionType.NetStepsApplicationException);
                throw exception;
            }
            return(Json(new { result = (resultado == 0 ? false : true) }));
        }
        public virtual ActionResult DeleteDispatchLists(List <int> items)
        {
            try
            {
                string resultado = string.Empty;

                using (TransactionScope trs = new TransactionScope(TransactionScopeOption.Required))
                {
                    foreach (var item in items)
                    {
                        DispatchListsTable entidad = new DispatchListsTable();
                        entidad.DispatchListID = item;
                        resultado = DispatchLists.DeleteDispatch(entidad);
                        if (resultado.Trim().Length > 0)
                        {
                            trs.Dispose();
                            return(Json(new { result = false, message = resultado }));
                        }
                    }
                    trs.Complete();
                }
                return(Json(new { result = true, message = "" }));
            }
            catch (Exception ex)
            {
                var exception = EntityExceptionHelper.GetAndLogNetStepsException(ex, NetSteps.Data.Entities.Constants.NetStepsExceptionType.NetStepsApplicationException);
                return(JsonError(exception.PublicMessage));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 销售发货:单据装载
        /// </summary>
        /// <param name="cDLCode"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public DispatchList Load(string cDLCode, out string errMsg)
        {
            //来源主表
            BLL.Service.DispatchList sMain = Common.Instance.Service.SA_Consignment_Load(Common.Instance.User.ConnectionString, cDLCode, out errMsg);
            if (sMain == null)
            {
                return(null);
            }

            //目标主表
            DispatchList  tMain = new DispatchList();
            DispatchLists tChild;

            //转换主表
            EntityConvert.ConvertClass <BLL.Service.DispatchList, DispatchList>(sMain, tMain);
            //循环转换子表
            foreach (BLL.Service.DispatchLists sChild in sMain.List)
            {
                tChild = new DispatchLists();
                EntityConvert.ConvertClass <BLL.Service.DispatchLists, DispatchLists>(sChild, tChild);
                ////存货转换
                //tChild.Inventory = new Inventory();
                //EntityConvert.ConvertClass<BLL.Service.Inventory, Inventory>(sChild.Inventory, tChild.Inventory);
                tMain.List.Add(tChild);
            }
            return(tMain);
        }
        public virtual ActionResult Create(int?DispatchListID)
        {
            var dispatch = DispatchListID.HasValue ? DispatchLists.GetDispatchListsByDispatchListID(DispatchListID.Value) : new DispatchListsTable {
                Editable = 1
            };

            return(View(dispatch));
        }
 public virtual ActionResult Edit(int?DispatchListID)
 {
     try
     {
         var dispatch = DispatchLists.GetDispatchListsByDispatchListID(Convert.ToInt32(DispatchListID));
         dispatch.Accounts = DispatchLists.GetDispatchListItemsById(Convert.ToInt32(DispatchListID));
         DispatchListsModel model = new DispatchListsModel(dispatch);
         return(View(model));
     }
     catch (Exception ex)
     {
         var exception = EntityExceptionHelper.GetAndLogNetStepsException(ex, NetSteps.Data.Entities.Constants.NetStepsExceptionType.NetStepsApplicationException);
         throw exception;
     }
 }
        public virtual ActionResult Get(bool?status, int page, int pageSize, string orderBy, string orderByDirection)
        {
            try
            {
                if (orderByDirection == "Descending")
                {
                    orderByDirection = "desc";
                }
                else
                {
                    orderByDirection = "asc";
                }

                var dispatchLists = DispatchLists.GetFullDispatchListsTable(new PaginationParameters()
                {
                    PageSize  = pageSize,
                    PageIndex = page,
                    OrderBy   = orderBy,
                    Order     = orderByDirection
                });

                if (!dispatchLists.Any())
                {
                    return(Json(new { result = true, totalPages = 0, page = String.Format("<tr><td colspan=\"6\">{0}</td></tr>", Translation.GetTerm("ThereAreNodispatchLists", "There are no dispatcs")) }));
                }

                var builder = new StringBuilder();

                foreach (var dispatchList in dispatchLists)
                {
                    var    Status  = 1;//?DispatchListID=1
                    string editUrl = string.Format("~/Products/{0}/Edit?DispatchListID={1}", "DispatchLists", dispatchList.DispatchListID);
                    builder.Append("<tr>")
                    .AppendCheckBoxCell(value: dispatchList.DispatchListID.ToString())
                    .AppendLinkCell(editUrl, dispatchList.Name)
                    .AppendCell(dispatchList.Mercado.ToString())
                    .Append("</tr>");
                }

                return(Json(new { result = true, totalPages = dispatchLists.TotalPages, page = dispatchLists.TotalCount == 0 ? "<tr><td colspan=\"7\">There are no Dispatch</td></tr>" : builder.ToString() }));
            }
            catch (Exception ex)
            {
                var exception = EntityExceptionHelper.GetAndLogNetStepsException(ex, NetSteps.Data.Entities.Constants.NetStepsExceptionType.NetStepsApplicationException);
                return(Json(new { result = false, message = exception.PublicMessage }));
            }
        }
        public virtual ActionResult Save(DispatchListsTable dispatchLists)
        {
            int resultado = 0;

            try
            {
                if (dispatchLists.DispatchListID > 0)
                {
                    resultado = DispatchLists.UpdateDispatch(dispatchLists);
                }
                else
                {
                    using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required))
                    {
                        int dispatchListID = DispatchLists.InsertDispatch(dispatchLists);
                        if (dispatchListID < 1)
                        {
                            tran.Dispose();
                            return(Json(new { result = false, message = "No se grabó correctamente en la tabla Dispatch List" }));
                        }
                        foreach (var account in dispatchLists.Accounts)
                        {
                            DispatchsItemsParameters objE = new DispatchsItemsParameters();
                            objE.AccountNumber  = Convert.ToString(account.AccountID);
                            objE.DispatchListID = dispatchListID;

                            if (DispatchItemsList.InsertDispatchListItems(objE) < 1)
                            {
                                tran.Dispose();
                                return(Json(new { result = false, message = "No se grabó correctamente en la tabla Dispatch List" }));
                            }
                        }
                        resultado = 1;
                        tran.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                var exception = EntityExceptionHelper.GetAndLogNetStepsException(ex, NetSteps.Data.Entities.Constants.NetStepsExceptionType.NetStepsApplicationException);
                throw exception;
            }
            return(Json(new { result = (resultado == 0 ? false : true) }));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 输入标签后回来
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtBarcode_KeyPress(object sender, KeyPressEventArgs e)
        {
            string strBarcode = txtBarcode.Text.Trim();

            ///如果不为空
            if (!string.IsNullOrEmpty(strBarcode) && e.KeyChar == (char)Keys.Enter)
            {
                try
                {
                    ///分离二维码
                    barcode = strBarcode.Split(Cast.Delimiter);
                    //判断当前条码是否在来源单据中
                    dispatchLists = dispatchList.List.Find(delegate(DispatchLists temp) { return(temp.cInvCode.Equals(barcode[0]) && temp.cBatch.Equals(barcode[1])); });
                    if (dispatchLists == null)
                    {
                        MessageBox.Show("条码错误:存货编码批次不正确!");
                        txtBarcode.Focus();
                        txtBarcode.SelectAll();
                        return;
                    }
                    //判断该标签是否已经扫描过(排除同个存货多次扫描)
                    RdRecords rds = rdRecord.List.Find(
                        delegate(RdRecords temp)
                    {
                        return(temp.cInvCode.Equals(barcode[0]) && temp.cBatch.Equals(barcode[1]));
                    });
                    if (rds != null)//如果不为空,判断标签序列号
                    {
                        if (rds.SerialList.Contains(barcode[2]))
                        {
                            MessageBox.Show("条码错误:该存货已扫描!");
                            txtBarcode.Focus();
                            txtBarcode.SelectAll();
                            return;
                        }
                    }

                    //显示信息
                    lblInvName.Text = dispatchLists.cInvName;
                    lblInvStd.Text  = dispatchLists.cInvStd;
                    lblCWhName.Text = dispatchLists.cWhName;
                    //lblEnterprise.Text = details.e
                    lblProDate.Text   = dispatchLists.dMDate == DateTime.MinValue ? "" : dispatchLists.dMDate.ToString("yyyy-MM-dd");
                    lblValidDate.Text = dispatchLists.dVDate == DateTime.MinValue ? "" : dispatchLists.dVDate.AddDays(-1).ToString("yyyy-MM-dd");
                    lblBatch.Text     = dispatchLists.cBatch;
                    //dispatchLists.cBarCode = barcode[0];

                    //显示已扫描数量
                    lblScanedNum.Text = dispatchLists.iScanQuantity.ToString();

                    txtCount.Text = (dispatchLists.iQuantity / Math.Abs(dispatchLists.iQuantity)).ToString();;
                    txtCount.Focus();
                    txtCount.SelectAll();

                    //如果选择单品,则实现自动扫描
                    if (chkSingle.Checked)
                    {
                        KeyPressEventArgs args = new KeyPressEventArgs((char)Keys.Enter);
                        txtCount_KeyPress(null, args);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 把数据行转换为Dispatchlists对象
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public static DispatchLists ConvertToDispatchLists(DataRow row)
        {
            DispatchLists dispatchLists = new DispatchLists();

            dispatchLists.DLID    = Cast.ToInteger(row["DLID"]);
            dispatchLists.AutoID  = Cast.ToInteger(row["AutoID"]);
            dispatchLists.cDLCode = Cast.ToString(row["cDLCode"]);
            dispatchLists.iSOsID  = Cast.ToInteger(row["iSOsID"]);
            dispatchLists.iDLsID  = Cast.ToInteger(row["iDLsID"]);
            dispatchLists.cSoCode = Cast.ToString(row["cSoCode"]);

            dispatchLists.cWhCode = Cast.ToString(row["cWhCode"]);
            dispatchLists.cWhName = Cast.ToString(row["cWhName"]);
            //存货
            dispatchLists.cInvCode   = Cast.ToString(row["cInvCode"]);
            dispatchLists.cInvName   = Cast.ToString(row["cInvName"]);
            dispatchLists.cInvStd    = Cast.ToString(row["cInvStd"]);
            dispatchLists.cBatch     = Cast.ToString(row["cBatch"]);
            dispatchLists.cMassUnit  = Cast.ToInteger(row["cMassUnit"]);
            dispatchLists.iMassDate  = Cast.ToInteger(row["iMassDate"]);
            dispatchLists.cinvm_unit = Cast.ToString(row["cinvm_unit"]);
            //日期
            dispatchLists.dMDate            = Cast.ToDateTime(row["dMDate"]);
            dispatchLists.dVDate            = Cast.ToDateTime(row["dVDate"]);
            dispatchLists.iExpiratDateCalcu = Cast.ToInteger(row["iExpiratDateCalcu"]);
            dispatchLists.dExpirationdate   = Cast.ToDateTime(row["dExpirationdate"]);
            dispatchLists.cExpirationdate   = Cast.ToString(row["cExpirationdate"]);

            dispatchLists.iQuotedPrice = Cast.ToDouble(row["iQuotedPrice"]);
            //原币
            dispatchLists.iUnitPrice    = Cast.ToDouble(row["iUnitPrice"]);
            dispatchLists.iTaxUnitPrice = Cast.ToDouble(row["iTaxUnitPrice"]);
            dispatchLists.iMoney        = Cast.ToDouble(row["iMoney"]);
            dispatchLists.iTax          = Cast.ToDouble(row["iTax"]);
            dispatchLists.iDisCount     = Cast.ToDouble(row["iDisCount"]);
            dispatchLists.iSum          = Cast.ToDouble(row["iSum"]);

            dispatchLists.iNatUnitPrice = Cast.ToDouble(row["iNatUnitPrice"]);
            dispatchLists.iNatMoney     = Cast.ToDouble(row["iNatMoney"]);
            dispatchLists.iNatTax       = Cast.ToDouble(row["iNatTax"]);
            dispatchLists.iNatSum       = Cast.ToDouble(row["iNatSum"]);
            dispatchLists.iNatDisCount  = Cast.ToDouble(row["iNatDisCount"]);

            dispatchLists.iTaxRate = Cast.ToDouble(row["iTaxRate"]);
            //数量
            dispatchLists.iQuantity    = Cast.ToDouble(row["iQuantity"]);
            dispatchLists.iNum         = Cast.ToDouble(row["iNum"]);
            dispatchLists.fOutQuantity = Cast.ToDouble(row["fOutQuantity"]);
            dispatchLists.fOutNum      = Cast.ToDouble(row["fOutNum"]);
            //单价金额
            dispatchLists.fSaleCost  = Cast.ToDouble(row["fSaleCost"]);
            dispatchLists.fSalePrice = Cast.ToDouble(row["fSalePrice"]);

            dispatchLists.iSettleNum      = Cast.ToDouble(row["iSettleNum"]);
            dispatchLists.iSettleQuantity = Cast.ToDouble(row["iSettleQuantity"]);
            dispatchLists.bSettleAll      = Cast.ToBoolean(row["bSettleAll"]);
            dispatchLists.cFree1          = Cast.ToString(row["cFree1"]);
            dispatchLists.cFree2          = Cast.ToString(row["cFree2"]);
            dispatchLists.iTB             = Cast.ToInteger(row["iTB"]);
            dispatchLists.KL      = Cast.ToDouble(row["KL"]);
            dispatchLists.KL2     = Cast.ToDouble(row["KL2"]);
            dispatchLists.bIsSTQc = Cast.ToBoolean(row["bIsSTQc"]);
            dispatchLists.bGsp    = Cast.ToBoolean(row["bGsp"]);

            dispatchLists.bCosting     = Cast.ToBoolean(row["bCosting"]);
            dispatchLists.iInvExchRate = Cast.ToDouble(row["iInvExchRate"]);

            //订单行号
            dispatchLists.iorderrowno = Cast.ToInteger(row["iorderrowno"]);
            return(dispatchLists);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 把销售发货子表转换成销售出库子表对象
        /// </summary>
        /// <param name="dispatchLists"></param>
        /// <returns></returns>
        public static RdRecords ConvertToRdrecords(DispatchLists dispatchLists)
        {
            RdRecords rdRecords = new RdRecords();

            //rdRecords.AutoID;
            rdRecords.bCosting = dispatchLists.bCosting;
            rdRecords.bGsp     = dispatchLists.bGsp;
            rdRecords.cWhCode  = dispatchLists.cWhCode;
            rdRecords.cWhName  = dispatchLists.cWhName;
            //rdRecords.bVMIUsed;
            //rdRecords.cAssUnit = dispatchLists.cav;
            rdRecords.cbaccounter = dispatchLists.cbaccounter;
            //rdRecords.cBarCode = dispatchLists.cBarCode;
            rdRecords.cBatch           = dispatchLists.cBatch;
            rdRecords.cBatchProperty1  = dispatchLists.cBatchProperty1;
            rdRecords.cBatchProperty2  = dispatchLists.cBatchProperty2;
            rdRecords.cBatchProperty3  = dispatchLists.cBatchProperty3;
            rdRecords.cBatchProperty4  = dispatchLists.cBatchProperty4;
            rdRecords.cBatchProperty5  = dispatchLists.cBatchProperty5;
            rdRecords.cBatchProperty6  = dispatchLists.cBatchProperty6;
            rdRecords.cBatchProperty7  = dispatchLists.cBatchProperty7;
            rdRecords.cBatchProperty8  = dispatchLists.cBatchProperty8;
            rdRecords.cBatchProperty9  = dispatchLists.cBatchProperty9;
            rdRecords.cBatchProperty10 = dispatchLists.cBatchProperty10;
            rdRecords.cbdlcode         = dispatchLists.cDLCode;
            rdRecords.cCusInvCode      = dispatchLists.cCusInvCode;
            rdRecords.cCusInvName      = dispatchLists.cCusInvName;
            rdRecords.cDefine22        = dispatchLists.cDefine22;
            rdRecords.cDefine23        = dispatchLists.cDefine23;
            rdRecords.cDefine24        = dispatchLists.cDefine24;
            rdRecords.cDefine25        = dispatchLists.cDefine25;
            rdRecords.cDefine26        = dispatchLists.cDefine26;
            rdRecords.cDefine27        = dispatchLists.cDefine27;
            rdRecords.cDefine28        = dispatchLists.cDefine28;
            rdRecords.cDefine29        = dispatchLists.cDefine29;
            rdRecords.cDefine30        = dispatchLists.cDefine30;
            rdRecords.cDefine31        = dispatchLists.cDefine31;
            rdRecords.cDefine32        = dispatchLists.cDefine32;
            rdRecords.cDefine33        = dispatchLists.cDefine33;
            rdRecords.cDefine34        = dispatchLists.cDefine34;
            rdRecords.cDefine35        = dispatchLists.cDefine35;
            rdRecords.cDefine36        = dispatchLists.cDefine36;
            rdRecords.cDefine37        = dispatchLists.cDefine37;
            rdRecords.cExpirationdate  = dispatchLists.cExpirationdate;
            rdRecords.cFree1           = dispatchLists.cFree1;
            rdRecords.cFree2           = dispatchLists.cFree2;
            rdRecords.cFree3           = dispatchLists.cFree3;
            rdRecords.cFree4           = dispatchLists.cFree4;
            rdRecords.cFree5           = dispatchLists.cFree5;
            rdRecords.cFree6           = dispatchLists.cFree6;
            rdRecords.cFree7           = dispatchLists.cFree7;
            rdRecords.cFree8           = dispatchLists.cFree8;
            rdRecords.cFree9           = dispatchLists.cFree9;
            rdRecords.cFree10          = dispatchLists.cFree10;
            rdRecords.cGspState        = dispatchLists.cGspState;
            //rdRecords.cinva_unit = dispatchLists.cinvde;
            //rdRecords.cInvAddCode= dispatchLists.cinvadd;
            rdRecords.cInvCode    = dispatchLists.cInvCode;
            rdRecords.cInvName    = dispatchLists.cInvName;
            rdRecords.cInvStd     = dispatchLists.cInvStd;
            rdRecords.cInvDefine1 = dispatchLists.cInvDefine1;
            rdRecords.cInvDefine6 = dispatchLists.cInvDefine6;
            rdRecords.cinvm_unit  = dispatchLists.cinvm_unit;
            //rdRecords.cInVouchCode = dispatchLists.cinvouch;
            rdRecords.cItem_class = dispatchLists.cItem_class;
            rdRecords.cItemCName  = dispatchLists.cItem_CName;
            rdRecords.cItemCode   = dispatchLists.cItemCode;
            rdRecords.cMassUnit   = dispatchLists.cMassUnit;
            rdRecords.iMassDate   = dispatchLists.iMassDate;
            //rdRecords.corufts = dispatchLists.cou;
            //rdRecords.cPosition = dispatchLists.cPosition;
            //rdRecords.cReplaceItem = dispatchLists.crelacusc;
            rdRecords.csocode = dispatchLists.cSoCode;
            //rdRecords.cVenName= dispatchLists.Inventory.cv;
            rdRecords.cvmivencode = dispatchLists.cvmivencode;
            //rdRecords.cvmivenname= dispatchLists.cv;
            //rdRecords.cVouchCode= dispatchLists.cvouc;
            rdRecords.dExpirationdate = dispatchLists.dExpirationdate;
            rdRecords.dMadeDate       = dispatchLists.dMDate;
            rdRecords.dVDate          = dispatchLists.dVDate;
            rdRecords.iTaxRate        = dispatchLists.iTaxRate;
            //rdRecords.editprop= "A";
            //rdRecords.iAvaNum = dispatchLists.iav;
            //rdRecords.iAvaQuantity = ;
            //rdRecords.iBondedSumQty = ;
            //rdRecords.iCheckIds = ;
            //rdRecords.ID =;
            rdRecords.iDLsID = dispatchLists.iDLsID;
            //rdRecords.iEnsID = dispatchLists.iend;
            rdRecords.iExpiratDateCalcu = dispatchLists.iExpiratDateCalcu;
            //rdRecords.iGrossWeight= dispatchLists.igr;
            rdRecords.iInvExchRate = dispatchLists.iInvExchRate;
            rdRecords.iInvSNCount  = dispatchLists.iInvSNCount;
            //rdRecords.iMPoIds = dispatchLists.imoneys;
            //rdRecords.iNetWeight= dispatchLists.inat;
            //rdRecords.iNNum= dispatchLists.innum;
            rdRecords.iNQuantity = dispatchLists.iQuantity - dispatchLists.fOutQuantity;
            rdRecords.iNum       = dispatchLists.iNum - dispatchLists.fOutNum;
            rdRecords.iordercode = dispatchLists.cSoCode;
            rdRecords.iorderdid  = dispatchLists.iSOsID;
            rdRecords.iorderseq  = dispatchLists.iorderrowno;
            //rdRecords.iordertype = dispatchLists.iorer;
            //rdRecords.iPPrice = dispatchLists.ippric;
            //rdRecords.iPresent = dispatchLists.ipr;
            //rdRecords.iPresentNum =;
            //rdRecords.iPrice = dispatchLists.fSalePrice;
            //rdRecords.iPUnitCost= dispatchLists.fSaleCost;
            //rdRecords.iUnitCost = dispatchLists.fSaleCost;
            rdRecords.iQuantity = dispatchLists.iQuantity;
            //rdRecords.iSBsID = dispatchLists.isb;
            //rdRecords.iSendNum = dispatchLists.iNum;
            //rdRecords.iSendQuantity= dispatchLists.iScanQuantity;
            //rdRecords.iSoDID = dispatchLists.iSOsID;
            //rdRecords.isoseq = dispatchLists.irowno;
            //rdRecords.iSoType = dispatchLists.iSettle;
            rdRecords.iSOutNum      = dispatchLists.fOutNum;
            rdRecords.iSOutQuantity = dispatchLists.fOutQuantity;
            //rdRecords.iTrIds = dispatchLists.;
            //rdRecords.iVMISettleNum=;
            //rdRecords.iVMISettleQuantity =;
            //rdRecords.scrapufts=;
            //rdRecords.strCode = dispatchLists.str;
            //rdRecords.strContractId =;

            return(rdRecords);
        }
        /// <summary>
        /// 销售发货:单据装载
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="cDLCode"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        /// <remarks>tianzhenyun 2013-06-20</remarks>
        public DispatchList Load(string connectionString, string cDLCode, out string errMsg)
        {
            errMsg = string.Empty;
            DispatchList dispatchList = null;
            //查询主表
            string strSql = string.Format(@" SELECT DISTINCT DispatchList.caddcode, (CASE WHEN isnull(DispatchList.cSBVCode, '') <> '' THEN salebillvouch.cVouchType  ELSE Dispatchlist.cVouchType END) AS cVouchType,  VouchType.cVouchName,
DispatchList.cDLCode,DispatchList.sbvid ,DispatchList.cSBVCode,DispatchList.ddate,DispatchList.cBusType, DispatchList.DLID as DLID,  DispatchList.cSTCode, 
SaleType.cSTName, DispatchList.cCusCode, Customer.cCusAbbName,Customer.cCusName, DispatchList.cDepCode, Department.cDepName,DispatchList.cPersonCode ,
 Person.cPersonName, DispatchList.cMaker,DispatchList.cVerifier,
DispatchList.cShipAddress,convert(char,convert(money,DispatchList.ufts),2) as ufts   ,
DispatchList.cDefine1 , DispatchList.cDefine2, DispatchList.cDefine3, DispatchList.cDefine4, 
 DispatchList.cDefine5, DispatchList.cDefine6, DispatchList.cDefine7, DispatchList.cDefine8, DispatchList.cDefine9, 
 DispatchList.cDefine10, DispatchList.cDefine11, DispatchList.cDefine12, DispatchList.cDefine13, DispatchList.cDefine14,
 DispatchList.cDefine15, DispatchList.cDefine16,DispatchList.cMemo,DispatchList.bReturnFlag 
 from DispatchList inner join   DispatchLists ON DispatchList.DLID = DispatchLists.DLID  
  INNER JOIN  Inventory ON DispatchLists.cInvCode = Inventory.cInvCode left join ComputationUnit on Inventory.ccomunitcode=ComputationUnit.ccomunitcode 
 inner join Warehouse on DispatchLists.cwhcode=warehouse.cwhcode
 LEFT OUTER JOIN SaleType ON DispatchList.cSTCode = SaleType.cSTCode 
 LEFT OUTER JOIN (select cpersoncode as cpersoncode2,cpersonname from Person) person ON DispatchList.cPersonCode = Person.cPersonCode2 
 LEFT OUTER JOIN  Customer ON DispatchList.cCusCode = Customer.cCusCode 
 LEFT OUTER JOIN Department ON DispatchList.cDepCode = Department.cDepCode
 left join SaleBillVouch on SaleBillVouch.SBVID = dbo.DispatchList.SBVID  
 left join VouchType on VouchType.cVouchType = case when  salebillvouch.SBVID is null then dispatchlist.cVouchType else salebillvouch.cVouchType end  
 WHERE  (DispatchList.cVouchType='05' OR DispatchList.cVouchType='06') 
AND  ((ISNULL(DispatchList.cSaleOut,'') = '' OR isnull(bqaneedcheck,0)=1) OR DispatchList.cSaleOut ='ST')    
AND NOT (isnull(DispatchList.bFirst,0) =1 And isnull(DispatchLists.bIsStQC,0) =0) 
AND (
	(ABS(ISNULL((case when (isnull(DispatchLists.bQANeedCheck,0)=1 and DispatchLists.iquantity>0) then DispatchLists.iqaquantity else DispatchLists.iquantity end ),0))-ABS(ISNULL(DispatchLists.fOutQuantity,0))    ) >=0.01 
	or ( igrouptype=2 and  (  ABS(ISNULL((case when (isnull(DispatchLists.bQANeedCheck,0)=1 and DispatchLists.iquantity>0) then DispatchLists.iqanum else DispatchLists.inum end ),0))-ABS(ISNULL(DispatchLists.fOutnum,0)) ) >=0.01)
	)
AND (ISNULL(DispatchLists.cWhCode,'')<>'') 
AND bInvType=0 
AND bService=0  
AND	((ISNULL(DispatchLists.bSettleAll,0)=0 and DispatchList.cvouchtype='05') or DispatchList.cvouchtype='06')  
AND ISNULL(DispatchList.cVerifier,'')<>''  
AND DISPATCHLIST.CDLCODE = N'{0}'
AND (
	(case when isnull(DispatchLists.bQANeedCheck,0)=1 and isnull(DispatchLists.iquantity,0)>0 then DispatchLists.iqaquantity else DispatchLists.iquantity end) <>0 
	 OR (case when isnull(DispatchLists.bQANeedCheck,0)=1  and isnull(DispatchLists.inum,0)>0 then DispatchLists.iqanum else DispatchLists.inum end) <>0)"    , cDLCode);

            DataTable dt = null;

            try
            {
                dt = DBHelperSQL.QueryTable(connectionString, strSql);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return(dispatchList);
            }
            if (dt.Rows.Count == 0)
            {
                errMsg = "单据错误或单据不存在、未审核、已关闭";
                return(dispatchList);
            }
            //转换主表
            dispatchList = EntityConvert.ConvertToDispatchList(dt.Rows[0]);
            //查询子表
            strSql = string.Format(@"Select WareHouse.cWhName
,DispatchList.cDLCode
,DispatchLists.AutoID,DispatchLists.cWhCode, DispatchLists.DLID, DispatchLists.iCorID,DispatchLists.cInvCode,DispatchLists.iQuotedPrice,DispatchLists.ccusinvcode,DispatchLists.ccusinvname,DispatchLists.iExpiratDateCalcu,DispatchLists.cExpirationdate,DispatchLists.dExpirationdate,DispatchLists.iUnitPrice, DispatchLists.iTaxUnitPrice,DispatchLists.iMoney, DispatchLists.iTax, DispatchLists.iDisCount,DispatchLists.iSum, DispatchLists.iNatUnitPrice,DispatchLists.iNatMoney, DispatchLists.iNatTax, DispatchLists.iNatSum,DispatchLists.iNatDisCount, DispatchLists.iSettleNum,DispatchLists.iSettleQuantity, DispatchLists.iBatch,DispatchLists.iInvExchRate,DispatchLists.cBatch, DispatchLists.bSettleAll, DispatchLists.cvmivencode,DispatchLists.cFree1, DispatchLists.cFree2, DispatchLists.iTB,DispatchLists.dMDate , DispatchLists.dvDate,DispatchLists.cMassUnit,DispatchLists.iMassDate, DispatchLists.TBQuantity, DispatchLists.TBNum,DispatchLists.iSOsID, DispatchLists.iDLsID, DispatchLists.KL,DispatchLists.iTaxRate, DispatchLists.KL2,DispatchLists.cDefine22, DispatchLists.cDefine23,DispatchLists.cDefine24, DispatchLists.cDefine25,DispatchLists.cDefine26, DispatchLists.cDefine27,convert(int,1) as isotype, DispatchLists.isosid as isodid,DispatchLists.idemandtype,DispatchLists.cdemandcode,DispatchLists.cdemandid,DispatchLists.idemandseq,DispatchLists.cItemCode, DispatchLists.cItem_class,DispatchLists.fSaleCost, DispatchLists.fSalePrice,DispatchLists.cVenAbbName, DispatchLists.cItemName,DispatchLists.cContractid,DispatchLists.ccontractTagCode,DispatchLists.ccontractrowguid,DispatchLists.cItem_CName, DispatchLists.cFree3,DispatchLists.cFree4, DispatchLists.cFree5, DispatchLists.cFree6,DispatchLists.cFree7, DispatchLists.cFree8, DispatchLists.cFree9,DispatchLists.cFree10,DispatchLists.cBatchProperty1,DispatchLists.cBatchProperty2,DispatchLists.cBatchProperty3, DispatchLists.bIsSTQc,DispatchLists.cBatchProperty4,DispatchLists.cBatchProperty5,DispatchLists.cBatchProperty6,DispatchLists.cBatchProperty7,DispatchLists.cBatchProperty8,DispatchLists.cBatchProperty9,DispatchLists.cBatchProperty10,DispatchLists.cUnitID, DispatchLists.cCode,DispatchLists.iRetQuantity, DispatchLists.fEnSettleQuan,DispatchLists.fEnSettleSum, DispatchLists.iSettlePrice,DispatchLists.cDefine28, DispatchLists.cDefine29,DispatchLists.cDefine30, DispatchLists.cDefine31,DispatchLists.cDefine32, DispatchLists.cDefine33,DispatchLists.cDefine34, DispatchLists.cDefine35,DispatchLists.cDefine36, DispatchLists.cDefine37,DispatchLists.bGsp, DispatchLists.cGspState,DispatchLists.bQANeedCheck,DispatchLists.cSoCode,DispatchLists.bCosting,DispatchLists.iorderrowno
,v1.cvenabbname as cvmivenname
,ComputationUnit.cComUnitName AS cinvm_unit,ComputationUnit_1.cComUnitName AS cinva_unit 
,SaleType.cstcode,saletype.cstname, SA_SORowNo.iRowNo
,inventory.cinvaddcode,Inventory.cInvName,Inventory.cInvStd, Inventory.cInvCCode, Inventory.cVenCode, Inventory.cReplaceItem, Inventory.cPosition, Inventory.bSale,Inventory.bPurchase, Inventory.bSelf, Inventory.bComsume,Inventory.bProducing, Inventory.bService, Inventory.bAccessary,Inventory.iInvWeight, Inventory.iVolume,Inventory.iInvRCost, Inventory.iInvSPrice, Inventory.iInvSCost,Inventory.iInvLSCost, Inventory.iInvNCost, Inventory.iInvAdvance,Inventory.iInvBatch, Inventory.iSafeNum, Inventory.iTopSum,Inventory.iLowSum, Inventory.iOverStock, Inventory.cInvABC,Inventory.bInvQuality, Inventory.bInvBatch, Inventory.bInvEntrust,Inventory.bInvOverStock, Inventory.dSDate, Inventory.dEDate,Inventory.bFree1, Inventory.bFree2, Inventory.cInvDefine1,Inventory.cInvDefine2, Inventory.cInvDefine3, Inventory.I_id,Inventory.bInvType, Inventory.iInvMPCost, Inventory.cQuality,Inventory.iInvSaleCost, Inventory.iInvSCost1, Inventory.iInvSCost2,Inventory.iInvSCost3, Inventory.bFree3, Inventory.bFree4,Inventory.bFree5, Inventory.bFree6, Inventory.bFree7,Inventory.bFree8, Inventory.bFree9, Inventory.bFree10,Inventory.cCreatePerson, Inventory.cModifyPerson,Inventory.dModifyDate, Inventory.fSubscribePoint,Inventory.fVagQuantity, Inventory.cValueType, Inventory.bFixExch,Inventory.fOutExcess, Inventory.fInExcess,Inventory.iWarnDays, Inventory.fExpensesExch, Inventory.bTrack,Inventory.bSerial, Inventory.bBarCode, Inventory.iId,Inventory.cBarCode, Inventory.cInvDefine4, Inventory.cInvDefine5,Inventory.cInvDefine6, Inventory.cInvDefine7, Inventory.cInvDefine8,Inventory.cInvDefine9, Inventory.cInvDefine10, Inventory.cInvDefine11,Inventory.cInvDefine12, Inventory.cInvDefine13, Inventory.cInvDefine14,Inventory.cInvDefine15, Inventory.cInvDefine16,convert(bit,0) AS bQuanSign, Inventory.iGroupType,Inventory.cGroupCode, Inventory.cAssComUnitCode,Inventory.cSAComUnitCode, Inventory.cPUComUnitCode,Inventory.cSTComUnitCode, Inventory.cComUnitCode,Inventory.cCAComUnitCode, Inventory.cFrequency, Inventory.iFrequency,Inventory.iDays, Inventory.dLastDate, Inventory.iWastage,Inventory.bSolitude, Inventory.cEnterprise, Inventory.cAddress,Inventory.cFile, Inventory.cLabel, Inventory.cCheckOut,Inventory.cLicence, Inventory.bSpecialties, Inventory.cDefWareHouse, Inventory.iHighPrice, Inventory.cPriceGroup,Inventory.iExpSaleRate, Inventory.cOfferGrade, Inventory.iOfferRate,Inventory.cMonth, Inventory.iAdvanceDate, Inventory.cCurrencyName,Inventory.cProduceAddress, Inventory.cProduceNation,Inventory.cRegisterNo, Inventory.cEnterNo, Inventory.cPackingType,Inventory.cEnglishName, Inventory.bPropertyCheck,Inventory.cPreparationType, Inventory.cCommodity,Inventory.iRecipeBatch, Inventory.cNotPatentName,Inventory.pubufts
,(case when (isnull(DispatchLists.bQANeedCheck,0)=1 and DispatchLists.iquantity>0) then isnull(DispatchLists.iqaquantity,0) else isnull(DispatchLists.iquantity,0) end ) as iquantity
, (case when (isnull(DispatchLists.bqaneedcheck,0)=1 and DispatchLists.inum>0) then isnull(DispatchLists.iqanum,0) else isnull(DispatchLists.inum,0) end) as inum,isnull(DispatchLists.fOutQuantity,0) as fOutQuantity
,isnull(case when inventory.igrouptype=1 then DispatchLists.fOutQuantity/DispatchLists.iInvExchRate else DispatchLists.fOutNum end ,0) as fOutNum 
 From dbo.DispatchList  
 INNER JOIN DispatchLists ON DispatchList.DLID = DispatchLists.DLID 
 INNER JOIN Inventory ON DispatchLists.cInvCode = Inventory.cInvCode 
 INNER JOIN Warehouse ON DispatchLists.cWhCode = Warehouse.cWhCode 
 INNER JOIN ComputationUnit ON Inventory.cComUnitCode = ComputationUnit.cComunitCode 
 LEFT OUTER JOIN Department ON DispatchList.cDepCode = Department.cDepCode 
 LEFT OUTER JOIN ComputationUnit ComputationUnit_1 ON DispatchLists.cUnitID = ComputationUnit_1.cComunitCode 
 Left Join SA_SORowNo On Dispatchlists.isosid=SA_SORowNo.isosid 
 Left Join SaleType ON DispatchList.cStCode=SaleType.cstcode 
 left join vendor v1 on v1.cvencode =dispatchlists.cvmivencode 
 left join (select cpersoncode as cpersoncode2,cpersonname from person) person on person.cpersoncode2 =dispatchlist.cpersoncode  
 left join  SaleBillVouch on SaleBillVouch.SBVID = DispatchList.SBVID 
 left join VouchType on VouchType.cVouchType = case when  salebillvouch.SBVID is null then dispatchlist.cVouchType else salebillvouch.cVouchType end  
 WHERE  (DispatchList.cVouchType='05' OR DispatchList.cVouchType='06')  
 AND  ((ISNULL(DispatchList.cSaleOut,'') = '' OR isnull(bqaneedcheck,0)=1) OR DispatchList.cSaleOut ='ST')    
 AND not (isnull(DispatchList.bFirst,0) =1 And isnull(DispatchLists.bIsStQC,0) =0) 
 and (
	(ABS(ISNULL((case when (isnull(DispatchLists.bQANeedCheck,0)=1 and DispatchLists.iquantity>0) then DispatchLists.iqaquantity else DispatchLists.iquantity end ),0))-ABS(ISNULL(DispatchLists.fOutQuantity,0))    ) >=0.01 
	or ( igrouptype=2 and  (  ABS(ISNULL((case when (isnull(DispatchLists.bQANeedCheck,0)=1 and DispatchLists.iquantity>0) then DispatchLists.iqanum else DispatchLists.inum end ),0))-ABS(ISNULL(DispatchLists.fOutnum,0)) ) >=0.01)
	)
 AND (ISNULL(DispatchLists.cWhCode,'')<>'') 
 AND bInvType=0 
 AND bService=0  
 AND ((ISNULL(DispatchLists.bSettleAll,0)=0 and DispatchList.cvouchtype='05') or DispatchList.cvouchtype='06')  
and  ISNULL(DispatchList.cVerifier,'')<>''  
AND	DISPATCHLIST.CDLCODE = N'{0}' 
and	((case when isnull(DispatchLists.bQANeedCheck,0)=1 and isnull(DispatchLists.iquantity,0)>0 then DispatchLists.iqaquantity else DispatchLists.iquantity end) <>0  OR (case when isnull(DispatchLists.bQANeedCheck,0)=1  and isnull(DispatchLists.inum,0)>0 then DispatchLists.iqanum else DispatchLists.inum end) <>0) "    , cDLCode);

            try
            {
                dt = DBHelperSQL.QueryTable(connectionString, strSql);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
                return(dispatchList);
            }
            //转换子表
            DispatchLists dispatchLists = null;

            foreach (DataRow row in dt.Rows)
            {
                dispatchLists = EntityConvert.ConvertToDispatchLists(row);
                dispatchList.List.Add(dispatchLists);
            }

            return(dispatchList);
        }