public string LabelPrintProductAdd(string branchCode, string createdBy, string remark, string labelPrintTypeCode) { 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); using (var db = new DbManager(branchCode)) { SqlQuery <LabelPrintProduct> query = new SqlQuery <LabelPrintProduct>(); var item = new LabelPrintProduct(); item.Branchcode = branchCode; item.Createuser = createdBy; item.Createdate = DateTime.Now; item.Computername = "Intranet"; item.Docno = docno; item.Docdate = DateTime.Now.Date; item.Remark = remark; item.Printlabeltype = labelPrintTypeCode; query.Insert(db, item); } return(docno); }
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); }