public OrderProperties(Order _order) { InitializeComponent(); this.order = _order; product = new CustomManager.Product(); region_sending = new Region(); region_origin = new Region(); feacn = new FEACN(); CalculatePriceAsync(this.order); LoadKursValyutaAsync(); }
public static string CalculatePrice(Order order) { string answerString = string.Empty; Product product = new CustomManager.Product(); Region region_sending = new Region(); Region region_origin = new Region(); FEACN feacn = new FEACN(); if (!MyGlobalClass.DBManager.LoadProductbyID(order.product_id, ref product).Equals(KEY_VALUES.OK)) { answerString = "This is not calculate"; return(answerString); } if (!MyGlobalClass.DBManager.LoadRegionbyID(order.region_sending_id, ref region_sending).Equals(KEY_VALUES.OK)) { answerString = "This is not calculate"; return(answerString); } if (!MyGlobalClass.DBManager.LoadRegionbyID(order.region_origin_id, ref region_origin).Equals(KEY_VALUES.OK)) { answerString = "This is not calculate"; return(answerString); } if (!MyGlobalClass.DBManager.LoadFEACNbyID(product.feacn_id, ref feacn).Equals(KEY_VALUES.OK)) { answerString = "This is not calculate"; return(answerString); } double aksizMoney = product.Minimum_Cost * feacn.Aksiz_persent / 100; double poshlinaMoney = product.Minimum_Cost * feacn.Poshlina_persent / 100; double qqsMoney = (product.Minimum_Cost + aksizMoney + poshlinaMoney) * feacn.QQS_persent / 100; if (region_sending.Bonus_persent == 0) { poshlinaMoney *= 2; } double summa = (product.Minimum_Cost + poshlinaMoney + aksizMoney) * feacn.Poshlina_persent / 100 + product.Minimum_Cost; return((summa * order.Order_Count).ToString()); }
private bool LoadFEACMfromFile(string filename) { bool answer = true; Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(filename); Microsoft.Office.Interop.Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Microsoft.Office.Interop.Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; if (colCount != 5) { MessageBox.Show(filename + " Excel file not supported", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } int allproductCount = rowCount - 1; int insertProductCount = 0; var window = MessageBox.Show(string.Format("Find {0} FEACN, Are sure to you want add database all ?", allproductCount), "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (window == DialogResult.Yes) { answer = true; FEACN feacn = null; for (int i = 2; i <= rowCount; i++) { feacn = new FEACN(); if (xlRange.Cells[i, 1] != null && xlRange.Cells[i, 1].Value2 != null) { //MessageBox.Show(xlRange.Cells[i, 1].Value2.ToString()); feacn.FEACN_Code = xlRange.Cells[i, 1].Value2.ToString(); } if (xlRange.Cells[i, 2] != null && xlRange.Cells[i, 2].Value2 != null) { //MessageBox.Show(xlRange.Cells[i, 1].Value2.ToString()); feacn.FEACN_Name = xlRange.Cells[i, 2].Value2.ToString(); } if (xlRange.Cells[i, 3] != null && xlRange.Cells[i, 3].Value2 != null) { //MessageBox.Show(xlRange.Cells[i, 1].Value2.ToString()); feacn.Aksiz_persent = double.Parse(xlRange.Cells[i, 3].Value2.ToString()); } if (xlRange.Cells[i, 4] != null && xlRange.Cells[i, 4].Value2 != null) { //MessageBox.Show(xlRange.Cells[i, 1].Value2.ToString()); feacn.Poshlina_persent = double.Parse(xlRange.Cells[i, 4].Value2.ToString()); } if (xlRange.Cells[i, 5] != null && xlRange.Cells[i, 5].Value2 != null) { //MessageBox.Show(xlRange.Cells[i, 1].Value2.ToString()); feacn.QQS_persent = double.Parse(xlRange.Cells[i, 5].Value2.ToString()); } bool result = false; string resultString = MyGlobalClass.DBManager.InsertFEACN(feacn, ref result); if (resultString.Equals(KEY_VALUES.OK)) { if (result) { insertProductCount++; } } else { MessageBox.Show(string.Format("Error: {0}", resultString), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } } else { answer = false; } MessageBox.Show(string.Format("All product count is {0}, Insert Product count is {1}", allproductCount, insertProductCount), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //cleanup GC.Collect(); GC.WaitForPendingFinalizers(); //rule of thumb for releasing com objects: // never use two dots, all COM objects must be referenced and released individually // ex: [somthing].[something].[something] is bad //release com objects to fully kill excel process from running in the background System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorksheet); //close and release xlWorkbook.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkbook); //quit and release xlApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp); return(answer); }