public int Insert(ProductSell info, List <ProductSellRecord> records) { try { //string commandText = @"insert into Users(userName,userPassword,userLevel,userPhone,userAddress) values ( //?userName,?userPassword,?userLevel,?userPhone,?userAddress)"; string commandText = string.Format("insert into ProductSell(name, sellTime, comment, status, customerID) values('{0}', '{1}', '{2}', '{3}', {4})", info.Name, info.SellTime, info.Comment, info.Status, info.CustomerID); DbHelperAccess.executeNonQuery(commandText); int ProductSellID = DbHelperAccess.executeMax("ID", "ProductSell"); ProductSellRecordDao dao = new ProductSellRecordDao(); foreach (ProductSellRecord record in records) { record.SellID = ProductSellID; dao.Insert(record); } return(ProductSellID); } catch (Exception ex) { throw ex; } }
//仅限于同级相邻两个节点,而且node比preNode大 public bool nodeUp(string tableName, Category node, Category preNode) { //先把node挪开,要不等下会重叠 int maxRight = DbHelperAccess.executeMax("rgt", tableName); maxRight++; int offset = maxRight - node.Left; string commandText = string.Format("update {0} set {0}.rgt={0}.rgt+{1}, {0}.lft={0}.lft+{1} where lft>={2} and lft<={3}", tableName, offset, node.Left, node.Right); DbHelperAccess.executeNonQuery(commandText); //把preNode移过去新位置 int span = node.Right - node.Left + 1; commandText = string.Format("update {0} set {0}.rgt={0}.rgt+{1}, {0}.lft={0}.lft+{1} where lft>={2} and lft<={3}", tableName, span, preNode.Left, preNode.Right); DbHelperAccess.executeNonQuery(commandText); node = this.FindById(tableName, node.Id); span = preNode.Right - preNode.Left + 1 + offset; commandText = string.Format("update {0} set {0}.rgt={0}.rgt-{1}, {0}.lft={0}.lft-{1} where lft>={2} and lft<={3}", tableName, span, node.Left, node.Right); DbHelperAccess.executeNonQuery(commandText); return(true); }
public int Insert(CharactorValue info) { try { string commandText = string.Format("insert into CharactorValue(name, charactorID) values('{0}', {1})", info.Name, info.CharactorId); DbHelperAccess.executeNonQuery(commandText); int id = DbHelperAccess.executeMax("ID", "CharactorValue"); return(id); } catch (Exception ex) { throw ex; } }
public bool UpdateParent(string tableName, Category node, Category preParent, Category newParent) { if (preParent == null && newParent == null || preParent != null && newParent != null && preParent.Id == newParent.Id) { return(false); } string commandText = string.Format("update {0} set parent={1} where ID={2}", tableName, newParent == null?"null":newParent.Id.ToString(), node.Id); DbHelperAccess.executeNonQuery(commandText); int newParentRight = 0; int nodeSpan = node.Right - node.Left + 1; if (newParent != null) { newParentRight = newParent.Right; //先腾出位置,包括newParent的right,也包括node commandText = string.Format("update {0} set {0}.lft={0}.lft+{1} where lft>={2}", tableName, nodeSpan, newParentRight); DbHelperAccess.executeNonQuery(commandText); commandText = string.Format("update {0} set {0}.rgt={0}.rgt+{1} where rgt>={2}", tableName, nodeSpan, newParentRight); DbHelperAccess.executeNonQuery(commandText); } else { int maxRight = DbHelperAccess.executeMax("rgt", tableName); newParentRight = maxRight + 1; } //刷新下node1 node = this.FindById(tableName, node.Id); //node的left从newParentRight开始 int offset = newParentRight - node.Left; //更新下node2 commandText = string.Format("update {0} set {0}.rgt={0}.rgt+{1}, {0}.lft={0}.lft+{1} where lft>={2} and lft<={3}", tableName, offset, node.Left, node.Right); DbHelperAccess.executeNonQuery(commandText); //用node1来判断,右边的才需要删除位置 commandText = string.Format("update {0} set {0}.lft={0}.lft-{1} where lft>{2}", tableName, nodeSpan, node.Right); DbHelperAccess.executeNonQuery(commandText); commandText = string.Format("update {0} set {0}.rgt={0}.rgt-{1} where rgt>{2}", tableName, nodeSpan, node.Right); DbHelperAccess.executeNonQuery(commandText); return(true); }
public bool Insert(PayReceipt info, out int id) { try { string commandText = string.Format("insert into PayReceipt(serial, bill_time, comment, customer_id, bill_type, handle_people, previousArrears, amount, status, cashDirection, arrearDirection, thisPayed, hide) values('{0}', '{1}', '{2}', {3}, {4}, '{5}', {6}, {7}, {8}, {9}, {10}, {11}, {12})", info.serial, info.bill_time, info.comment, info.customer_id <= 0 ? "null" : info.customer_id.ToString(), (int)info.bill_type, info.handle_people, info.previousArrears, info.amount, info.status, info.cashDirection, info.arrearDirection, info.thisPayed, info.hide); DbHelperAccess.executeNonQuery(commandText); id = DbHelperAccess.executeMax("ID", "PayReceipt"); return(true); } catch (Exception ex) { throw ex; } }
public int Insert(Product info, List <CharactorValue> colors, List <CharactorValue> sizes) { try { string commandText = string.Format("insert into Product(name, comment, parent, price) values('{0}', '{1}', {2}, {3})", info.Name, info.Comment, info.CategoryID, info.PricePurchase); DbHelperAccess.executeNonQuery(commandText); int productID = DbHelperAccess.executeMax("ID", "Product"); setAttribute(productID, info, colors, sizes); return(productID); } catch (Exception ex) { throw ex; } }
public bool Insert(Customer info, out int id) { try { string commandText = string.Format("insert into Customer(name, comment, tel, phone, address, parent, arrear) values('{0}', '{1}', '{2}', '{3}', '{4}', {5}, {6})", info.Name, info.Comment, info.Tel, info.Phone, info.Address, info.Parent, info.arrear); DbHelperAccess.executeNonQuery(commandText); id = DbHelperAccess.executeMax("ID", "Customer"); return(true); } catch (Exception ex) { throw ex; } }
public bool Insert(Consume info, out int id) { try { string commandText = string.Format("insert into Consume(code, consumeTime, cardID, status, type, num, operator, comment, leftNum) values('{0}', '{1}', {2}, {3}, {4}, {5}, '{6}', '{7}', {8})", info.Code, info.ConsumeTime, info.CardID, info.Status, info.Type, info.Number, info.Oper, info.Comment, info.LeftNumber); DbHelperAccess.executeNonQuery(commandText); id = DbHelperAccess.executeMax("ID", "Consume"); return(true); } catch (Exception ex) { throw ex; } }
public int Insert(ProductStainless info) { try { string commandText = string.Format( "insert into ProductStainless(serial, name, comment, parent, pricePurchase, priceCost, priceSell, unit, quantityPerPiece, disable) values('{0}', '{1}', '{2}', {3}, {4}, {5}, {6}, '{7}', {8}, {9})", info.Serial, info.Name, info.Comment, info.CategoryID, info.PricePurchase, info.PriceCost, info.PriceSell, info.Unit, info.QuantityPerPiece, info.Disable); DbHelperAccess.executeNonQuery(commandText); int productID = DbHelperAccess.executeMax("ID", "ProductStainless"); return(productID); } catch (Exception ex) { throw ex; } }
public bool Insert(ProductCirculation info, out int ProductCirculationID) { ProductCirculationID = 0; try { string commandText = string.Format("insert into {0}(code, circulationTime, comment, status, customerID, type, flowType, arrearDirection, total, backFreightPerPiece, realTotal, previousArrears, thisPayed, freight, operator, lastPayReceipt) values('{1}','{2}', '{3}', '{4}', {5}, {6}, {7}, {8}, {9},{10},{11},{12},{13},{14},'{15}', '{16}')", tableName, info.Code, info.CirculationTime, info.Comment, info.Status, info.CustomerID <= 0 ? "null" : info.CustomerID.ToString(), info.Type, info.FlowType, info.ArrearDirection, info.Total, info.BackFreightPerPiece, info.RealTotal, info.PreviousArrears, info.ThisPayed, info.Freight, info.Oper, info.LastPayReceipt); DbHelperAccess.executeNonQuery(commandText); ProductCirculationID = DbHelperAccess.executeMax("ID", tableName); return(true); } catch (Exception ex) { throw ex; } }
public int Insert(ProductStainlessCirculationRecord info) { try { //注意这里:quantity不用'',而totalNum用 string commandText = string.Format("insert into ProductStainlessCirculationRecord(productID, quantityPerPiece, pieces, totalNum, unit, price, totalPrice, circulationID, comment) values('{0}', {1}, {2}, '{3}','{4}', '{5}', '{6}', '{7}', '{8}')", info.ProductID, info.QuantityNull ? "NULL" : info.QuantityPerPiece.ToString(), info.PiecesNull ? "NULL" : info.Pieces.ToString(), info.TotalNum, info.Unit, info.Price, info.TotalPrice, info.CirculationID, info.Comment); DbHelperAccess.executeNonQuery(commandText); int recordID = DbHelperAccess.executeMax("ID", "ProductStainlessCirculationRecord"); return(recordID); } catch (Exception ex) { throw ex; } }
public bool Insert(ProductCirculation info, List <ProductClothesCirculationRecord> records, out int ProductCirculationID) { ProductCirculationID = 0; try { string commandText = string.Format("insert into ProductCirculation(code, circulationTime, comment, status, customerID, type, flowType, operator) values('{0}', '{1}', '{2}', '{3}', {4}, {5}, {6}, '{7}')", info.Code, info.CirculationTime, info.Comment, info.Status, info.CustomerID <= 0 ? "null" : info.CustomerID.ToString(), info.Type, info.FlowType, info.Oper); DbHelperAccess.executeNonQuery(commandText); ProductCirculationID = DbHelperAccess.executeMax("ID", "ProductCirculation"); this.insertRecords(ProductCirculationID, records); return(true); } catch (Exception ex) { throw ex; } }
public int Insert(string tableName, Category parent, Category right, Category info) { try { int point = 0; string parentId = null; if (right != null) { point = right.Right; parentId = right.Parent.ToString(); } else if (parent != null) { point = parent.Right - 1; // parent.right is changed to right+1 parentId = parent.Id.ToString(); } if (parentId == null || parentId == "" || parentId == "0") { parentId = "null"; } string commandText = string.Format("update {0} set {0}.lft={0}.lft+2 where lft>{1}", tableName, point); DbHelperAccess.executeNonQuery(commandText); commandText = string.Format("update {0} set {0}.rgt={0}.rgt+2 where rgt>{1}", tableName, point); DbHelperAccess.executeNonQuery(commandText); commandText = string.Format("insert into {0}(name, parent, lft, rgt) values('{1}', {2}, {3}, {4})", tableName, info.Name, parentId, point + 1, point + 2); DbHelperAccess.executeNonQuery(commandText); int categoryID = DbHelperAccess.executeMax("ID", tableName); return(categoryID); } catch (Exception ex) { throw ex; } }
public int Insert(ProductClothesCirculationRecord info) { try { string commandText = string.Format("insert into ProductCirculationRecord(productID, totalNum, price, circulationID) values('{0}', '{1}', '{2}', '{3}')", info.ProductID, info.TotalNum, info.Price, info.CirculationID); DbHelperAccess.executeNonQuery(commandText); int recordID = DbHelperAccess.executeMax("ID", "ProductCirculationRecord"); List <ProductClothesCirculationSKURecord> skuRecords = info.SkuRecords; ProductClothesCirculationSKURecordDao dao = new ProductClothesCirculationSKURecordDao(); foreach (ProductClothesCirculationSKURecord record in skuRecords) { record.RecordID = recordID; dao.Insert(record); } return(recordID); } catch (Exception ex) { throw ex; } }