public void AddAll(List<ProductMaster> productMasters) { //string deptId = string.Format("{0:000}", CurrentDepartment.Get().DepartmentId); // always insert goods at main stock string deptId = "000"; var criteria = new ObjectCriteria(); criteria.AddBetweenCriteria("ProductMasterId", deptId + "0000000000", deptId + "9999999999"); object maxId = ProductMasterDAO.SelectSpecificType(criteria, Projections.Max("ProductMasterId")); long id = 0; if (maxId != null) { id = Int64.Parse(maxId.ToString()) + 1; //data.ProductMasterId = string.Format("{0:0000000000000}", Int64.Parse(maxId.ToString()) + 1); } else { id = Int64.Parse("0000000000001"); //data.ProductMasterId = deptId + "0000000001"; } foreach (ProductMaster productMaster in productMasters) { criteria = new ObjectCriteria(); criteria.AddEqCriteria("ProductName", productMaster.ProductName); criteria.AddEqCriteria("Packager", productMaster.Packager); criteria.AddEqCriteria("Distributor", productMaster.Distributor); criteria.AddEqCriteria("Manufacturer", productMaster.Manufacturer); criteria.AddEqCriteria("ProductType", productMaster.ProductType); criteria.AddEqCriteria("ProductSize", productMaster.ProductSize); criteria.AddEqCriteria("ProductColor", productMaster.ProductColor); criteria.AddEqCriteria("Country", productMaster.Country); IList list = ProductMasterDAO.FindAll(criteria); if (list.Count == 0) { productMaster.ProductMasterId = string.Format("{0:0000000000000}", id++); productMaster.Barcode = productMaster.ProductMasterId; ProductMasterDAO.Add(productMaster); } } /* if (data.ProductType != null) { data.Barcode = string.Format("{0:000}", data.ProductType.TypeId) + data.ProductMasterId; } else { data.Barcode = "000" + data.ProductMasterId; }*/ }
public void AddSubStock(Department department) { // lower range long subStockMin = Int64.Parse(department.DepartmentId.ToString().PadRight(4,'0').PadRight(5,'0')); // higher range long subStockMax = Int64.Parse(department.DepartmentId.ToString().PadRight(4, '0').PadRight(5,'9')); ObjectCriteria objectCriteria = new ObjectCriteria(); objectCriteria.AddBetweenCriteria("DepartmentId",subStockMin,subStockMax ); var maxId = DepartmentDAO.SelectSpecificType(objectCriteria, Projections.Max("DepartmentId")); var departmentId = maxId == null ? Int64.Parse(department.DepartmentId.ToString().PadRight(4,'0').PadRight(5,'0')) + 1 : (Int64.Parse(maxId.ToString()) + 1); department.DepartmentId = departmentId; DepartmentDAO.Add(department); }