public void LabelPrintProductDetailAdd(string branchCode, string docno, List <LabelPrintProductDetail> details)
        {
            var provider = ProviderFactory.GetProvider(branchCode, "System.Data.SqlClient");
            var repo     = new SimpleRepository(provider);

            var labelPrintProduct = repo.Single <LabelPrintProduct>(docno);

            var            displayOrder         = 0;
            string         productCodeOrBarcode = "";
            ProductBarcode product      = null;
            ProductPrice   productPrice = null;

            foreach (var item in details)
            {
                item.Docno              = docno;
                item.Docdate            = DateTime.Now.Date;
                item.Roworder           = displayOrder.ToString();
                item.PrintLabelTypeCode = labelPrintProduct.Printlabeltype;
                if (!string.IsNullOrEmpty(item.Barcode))
                {
                    productCodeOrBarcode = item.Barcode;
                }
                else
                {
                    productCodeOrBarcode = item.Productcode;
                }

                product = ProductBarcodeGetByProductCodeOrBarcode3(branchCode, productCodeOrBarcode);
                if (product != null)
                {
                    item.Productcode = product.ProductCode;
                    item.Productname = product.ProductName;
                    item.Barcode     = product.Barcode;
                    item.Unitcode    = product.UnitCode;
                    item.Unitname    = product.UnitName;
                    item.OthUnitcode = item.Unitcode;
                    item.OthUnitname = item.Unitname;
                    productPrice     = ProductPriceGetCurrentPrice(branchCode, item.Productcode, item.Unitcode);
                    if (productPrice != null)
                    {
                        item.Sellprice    = productPrice.Saleprice;
                        item.Pricedate    = productPrice.Begindate;
                        item.OthUnitprice = item.Sellprice;
                    }
                }

                displayOrder++;
            }

            using (System.Transactions.TransactionScope ts = new TransactionScope())
            {
                using (SharedDbConnectionScope scs = new SharedDbConnectionScope(provider))
                {
                    repo.DeleteMany <LabelPrintProductDetail>(p => p.Docno == docno);
                    repo.AddMany <LabelPrintProductDetail>(details);
                    ts.Complete();
                }
            }
        }
        public string LabelPrintProductAddWithDetail(string branchCode, string createdBy, string remark, string labelType, List <LabelPrintProductDetail> details)
        {
            string docno = string.Empty;

            using (DbManager db = new DbManager(branchCode))
            {
                docno = db.SetCommand(GetSql(79)).ExecuteScalar <string>();
            }

            var culture = new System.Globalization.CultureInfo("th-TH");
            int index   = 1;

            if (!string.IsNullOrEmpty(docno))
            {
                index = Convert.ToInt32(docno) + 1;
            }

            docno = string.Format("PR{0}-{1:0000}", DateTime.Now.Date.ToString("yyMMdd", culture), index);

            var master = new LabelPrintProduct();

            master.Branchcode     = branchCode;
            master.Createuser     = createdBy;
            master.Createdate     = DateTime.Now;
            master.Computername   = "PDA";
            master.Docno          = docno;
            master.Docdate        = DateTime.Now.Date;
            master.Remark         = remark;
            master.Printlabeltype = labelType;

            //var labelPrintProduct = repo.Single<LabelPrintProduct>(docno);

            var          displayOrder = 0;
            ProductPrice productPrice = null;

            foreach (var item in details)
            {
                item.Docno    = docno;
                item.Docdate  = DateTime.Now.Date;
                item.Roworder = displayOrder.ToString();
                //item.PrintLabelTypeCode = labelPrintProduct.Printlabeltype;

                productPrice = ProductPriceGetCurrentPrice(branchCode, item.Productcode, item.Unitcode);
                if (productPrice != null)
                {
                    item.Sellprice = productPrice.Saleprice;
                    item.Pricedate = productPrice.Begindate;
                    //item.OthUnitprice = item.Sellprice;
                    item.OthUnitprice = 0;
                    item.OthUnitcode  = "";
                    item.OthUnitname  = "";
                    var UnitOther = ProductPriceGetUnitOther(branchCode, item.Productcode, item.Unitcode);
                    if (UnitOther != null)
                    {
                        item.OthUnitcode = UnitOther.UnitCode;
                        item.OthUnitname = UnitOther.UnitName;
                        var OthPrice = ProductPriceGetCurrentPrice(branchCode, item.Productcode, item.OthUnitcode);
                        if (OthPrice != null)
                        {
                            item.OthUnitprice = OthPrice.Saleprice;
                        }
                        else
                        {
                            item.OthUnitprice = 0;
                            item.OthUnitcode  = "";
                            item.OthUnitname  = "";
                        }
                    }
                }

                displayOrder++;
            }
            var provider = ProviderFactory.GetProvider(branchCode);
            var repo     = new SimpleRepository(provider);

            using (System.Transactions.TransactionScope ts = new TransactionScope())
            {
                using (SharedDbConnectionScope scs = new SharedDbConnectionScope(provider))
                {
                    repo.Add <LabelPrintProduct>(master);
                    repo.AddMany <LabelPrintProductDetail>(details);
                    ts.Complete();
                }
            }
            return(docno);
        }