public void UpdateLicense(MerchantLicense license) { //bool isValid = true; List <MerchandiseInLicense> merchandiseList = new List <MerchandiseInLicense>(); merchandiseList = statementDAO.GetMerchandiseListForLicense(license.GetLicenseNumber()); if (license.GetExpirationDate() < statement.GetIssuanceDate()) { return; } foreach (MerchandiseInStatement statementMerchandise in statement.GetMerchandiseList()) { bool licenseHasMerchandise = false; foreach (MerchandiseInLicense licenseMerchandise in merchandiseList) { if (licenseMerchandise.GetName() == statementMerchandise.GetName()) { licenseHasMerchandise = true; if (licenseMerchandise.GetUnitPrice() != -1 && licenseMerchandise.GetUnitPrice() == statementMerchandise.GetUnitPrice()) { licenseMerchandise.SetCount(licenseMerchandise.GetNumber() - statementMerchandise.GetCount()); break; } else if (licenseMerchandise.GetMaxUnitPrice() != -1 && licenseMerchandise.GetMaxUnitPrice() >= statementMerchandise.GetUnitPrice()) { licenseMerchandise.SetCount(licenseMerchandise.GetNumber() - statementMerchandise.GetCount()); break; } else if (licenseMerchandise.Getweight() >= statementMerchandise.GetWeight()) { licenseMerchandise.SetWeight(licenseMerchandise.Getweight() - statementMerchandise.GetWeight()); break; } else // kala darim, kam darim { break; } } } //if (!licenseHasMerchandise) // kollan kala to in mojavvez nist } }
public IssueLicenseHandler() { merchantLicense = new MerchantLicense(); licenseDAO = new IssueLicenseDAO(); // needed any more? it is created in function!!! companies = new List <string>(); }
public bool IsLicenseValid(string licenseNumber) { MessageBox.Show((statement.GetCountry() == null).ToString()); //MessageBox.Show((statement.GetIssuanceDate() == null).ToString()); MerchantLicense license = new MerchantLicense(); license = licenseDAO.GetLicenseWithNumber(licenseNumber); if (statement.GetIssuanceDate() <= license.GetExpirationDate() && String.IsNullOrEmpty(license.GetCountry()) ? true : (license.GetCountry() == statement.GetCountry()) && String.IsNullOrEmpty(license.GetImportType()) ? true : (license.GetImportType() == statement.GetKindOfImport())) { if (license.GetMerchandiseList().Count == 0) /* with no merchandise */ { if (license.GetValue() > 0) { if (String.IsNullOrEmpty(license.GetWeight())) /* weight treated as company List */ { MessageBox.Show("type 1: returning " + (statement.GetWholeValue() <= license.GetValue()).ToString()); return(statement.GetWholeValue() <= license.GetValue()); /* type 1 */ } else /* type 2 */ { if (statement.GetWholeValue() > license.GetValue()) { MessageBox.Show("type 2: returning " + (statement.GetWholeValue() > license.GetValue()).ToString()); return(false); } string[] temp = license.GetWeight().Split('#'); List <string> licenseCompanies = new List <string>(temp); double totalPriceWithliceCompanies = 0; foreach (MerchandiseInStatement merchandise in statement.GetMerchandiseList()) { if (licenseCompanies.Contains(merchandise.GetName())) { totalPriceWithliceCompanies += merchandise.GetUnitPrice() * merchandise.GetCount(); } } MessageBox.Show("type 2: returning " + (license.GetValue() >= totalPriceWithliceCompanies).ToString()); return(license.GetValue() >= totalPriceWithliceCompanies); } } else /* type 3 */ { foreach (MerchandiseInStatement merchandise in statement.GetMerchandiseList()) { if (merchandise.GetWeight() > license.GetMaxUnitWeight() || merchandise.GetUnitPrice() > license.GetMaxUnitPrice()) { MessageBox.Show("type 3: returning false"); return(false); } } MessageBox.Show("type 3: returning false"); return(true); } } else /* with some merchandise */ { foreach (MerchandiseInStatement statementGood in statement.GetMerchandiseList()) { foreach (MerchandiseInLicense licenseGood in license.GetMerchandiseList()) { if (licenseGood.GetName() == statementGood.GetName()) { if (licenseGood.Getweight() > 0) /* type 4 */ { if (statementGood.GetCompany() == licenseGood.GetCompany() && statementGood.GetWeight() <= licenseGood.Getweight()) { MessageBox.Show("type 4: returning true"); return(true); } } else if (licenseGood.GetNumber() > 0) { if (licenseGood.GetUnitPrice() < 0 && licenseGood.GetMaxUnitPrice() < 0) /* type 5 */ { MessageBox.Show("type 5; returning " + (statementGood.GetCount() <= licenseGood.GetNumber()).ToString()); return(statementGood.GetCount() <= licenseGood.GetNumber()); } else if (licenseGood.GetUnitPrice() > 0 && licenseGood.GetMaxUnitPrice() < 0) /* type 6 */ { MessageBox.Show("type 6: returning " + (statementGood.GetCount() <= licenseGood.GetNumber() && statementGood.GetUnitPrice() == licenseGood.GetUnitPrice()).ToString()); return(statementGood.GetCount() <= licenseGood.GetNumber() && statementGood.GetUnitPrice() == licenseGood.GetUnitPrice()); } else if (licenseGood.GetUnitPrice() < 0 && licenseGood.GetMaxUnitPrice() > 0) /* type 7 */ { MessageBox.Show("type 7: returning " + (statementGood.GetCount() <= licenseGood.GetNumber() && statementGood.GetUnitPrice() <= licenseGood.GetMaxUnitPrice()).ToString()); return(statementGood.GetCount() <= licenseGood.GetNumber() && statementGood.GetUnitPrice() <= licenseGood.GetMaxUnitPrice()); } } else /* type 8 */ { MessageBox.Show("type 8: no limitations - returning true"); return(true); } } } } MessageBox.Show("no types matched. returning false"); return(false); } } else { MessageBox.Show("primary conditions not valid. " + (statement.GetIssuanceDate() <= license.GetExpirationDate()).ToString() + " " + (String.IsNullOrEmpty(license.GetCountry()) ? true : (license.GetCountry() == statement.GetCountry())).ToString() + " " + (String.IsNullOrEmpty(license.GetImportType()) ? true : (license.GetImportType() == statement.GetKindOfImport())).ToString()); MessageBox.Show("license: " + license.GetCountry() + " " + license.GetCountry().Length); MessageBox.Show("statement: " + statement.GetCountry() + " " + statement.GetCountry().Length); return(false); } }
public MerchantLicense GetLicenseWithNumber(string licenseNumber) { string query = "select * from dbo.MerchantLicense where number = '" + licenseNumber + "'"; DBConnection dbConnection = new DBConnection(); List <List <Object> > queryResult = new List <List <Object> >(); queryResult = dbConnection.RunSelectQuery(query); if (queryResult.Count == 0) { MessageBox.Show("No MerchantLicense Found with licenseNumber: " + licenseNumber); return(null); } int licenseNum = Convert.ToInt16(licenseNumber); string licenseName = Convert.ToString(queryResult[0][1]); string SSN = Convert.ToString(queryResult[0][2]); DateTime issuanceDate = Convert.ToDateTime(queryResult[0][3]); DateTime expirationDate = Convert.ToDateTime(queryResult[0][4]); double wholeValue = Convert.ToDouble(queryResult[0][5]); string weight = Convert.ToString(queryResult[0][6]); /*treated as company List */ double maxUnitPrice = Convert.ToDouble(queryResult[0][7]); double maxUnitWeight = Convert.ToDouble(queryResult[0][8]); string importType = Convert.ToString(queryResult[0][9]); string country = Convert.ToString(queryResult[0][10]); MerchantLicense merchantLicense = new MerchantLicense(); merchantLicense.SetLicenseNumber(licenseNum); merchantLicense.SetParameters(issuanceDate, expirationDate, licenseName, wholeValue, weight, maxUnitPrice, maxUnitWeight, importType, country, SSN); //MessageBox.Show("in DAO; found merchant license for ssn: " + SSN); string queryToFindMerchandiseId = "select merchandiseid from dbo.LicenseHasMerchandise where licenseNumber = '" + licenseNumber + "'"; List <List <Object> > merchandiseIdObjects = new List <List <Object> >(); merchandiseIdObjects = dbConnection.RunSelectQuery(queryToFindMerchandiseId); List <string> merchandiseIDs = new List <string>(); for (int i = 0; i < merchandiseIdObjects.Count; i++) { merchandiseIDs.Add(Convert.ToString(merchandiseIdObjects[i][0])); } //MessageBox.Show("in DAO: found merchanndise ids: " + String.Join("\n", merchandiseIDs.ToArray())); List <List <Object> > merhcandiseObjects = new List <List <Object> >(); foreach (string merchandiseId in merchandiseIDs) { string queryToFindMerchandiseList = "select * from MerchandiseInfoInLicense where Id = '" + merchandiseId + "'"; merchandiseIdObjects = dbConnection.RunSelectQuery(queryToFindMerchandiseList); string name = Convert.ToString(merchandiseIdObjects[0][1]); string company = Convert.ToString(merchandiseIdObjects[0][2]); double unitWeight = Convert.ToDouble(merchandiseIdObjects[0][3]); double unitPrice = Convert.ToDouble(merchandiseIdObjects[0][4]); double wholeWeight = Convert.ToDouble(merchandiseIdObjects[0][5]); double _maxUnitPrice = Convert.ToDouble(merchandiseIdObjects[0][6]); int count = Convert.ToInt32(merchandiseIdObjects[0][7]); MerchandiseInLicense merchandise = new MerchandiseInLicense(name, company, wholeWeight, _maxUnitPrice, unitWeight, unitPrice, count); //MessageBox.Show("in DAO: found merchandise with id, name: " + merchandiseId + ", " + name); merchantLicense.AddNewMercahndise(merchandise); merchandiseIdObjects.Clear(); } return(merchantLicense); }