/// <summary> /// Test Find using the Query class /// </summary> private void Step_30_TestFindByQuery_Generated() { using (TransactionManager tm = CreateTransaction()) { //Insert Mock Instance TransValue mock = CreateMockInstance(tm); bool result = DataRepository.TransValueProvider.Insert(tm, mock); Assert.IsTrue(result, "Could Not Test FindByQuery, Insert Failed"); TransValueQuery query = new TransValueQuery(); query.AppendEquals(TransValueColumn.TransNum, mock.TransNum.ToString()); if (mock.Amount != null) { query.AppendEquals(TransValueColumn.Amount, mock.Amount.ToString()); } if (mock.Frcustomer != null) { query.AppendEquals(TransValueColumn.Frcustomer, mock.Frcustomer.ToString()); } if (mock.Forex != null) { query.AppendEquals(TransValueColumn.Forex, mock.Forex.ToString()); } TList <TransValue> results = DataRepository.TransValueProvider.Find(tm, query); Assert.IsTrue(results.Count == 1, "Find is not working correctly. Failed to find the mock instance"); } }
/// <summary> /// Deep load all TransValue children. /// </summary> private void Step_03_DeepLoad_Generated() { using (TransactionManager tm = CreateTransaction()) { int count = -1; mock = CreateMockInstance(tm); mockCollection = DataRepository.TransValueProvider.GetPaged(tm, 0, 10, out count); DataRepository.TransValueProvider.DeepLoading += new EntityProviderBaseCore <TransValue, TransValueKey> .DeepLoadingEventHandler( delegate(object sender, DeepSessionEventArgs e) { if (e.DeepSession.Count > 3) { e.Cancel = true; } } ); if (mockCollection.Count > 0) { DataRepository.TransValueProvider.DeepLoad(tm, mockCollection[0]); System.Console.WriteLine("TransValue instance correctly deep loaded at 1 level."); mockCollection.Add(mock); // DataRepository.TransValueProvider.DeepSave(tm, mockCollection); } //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
///<summary> /// Update the Typed TransValue Entity with modified mock values. ///</summary> static public void UpdateMockInstance(TransactionManager tm, TransValue mock) { TransValueTest.UpdateMockInstance_Generated(tm, mock); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); }
/// <summary> /// Check the foreign key dal methods. /// </summary> private void Step_10_FK_Generated() { using (TransactionManager tm = CreateTransaction()) { TransValue entity = CreateMockInstance(tm); bool result = DataRepository.TransValueProvider.Insert(tm, entity); Assert.IsTrue(result, "Could Not Test FK, Insert Failed"); } }
/// <summary> /// Test methods exposed by the EntityHelper class. /// </summary> private void Step_20_TestEntityHelper_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); TransValue entity = mock.Copy() as TransValue; entity = (TransValue)mock.Clone(); Assert.IsTrue(TransValue.ValueEquals(entity, mock), "Clone is not working"); } }
///<summary> /// Returns a Typed TransValue Entity with mock values. ///</summary> static public TransValue CreateMockInstance(TransactionManager tm) { // get the default mock instance TransValue mock = TransValueTest.CreateMockInstance_Generated(tm); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); // return the modified object return(mock); }
/// <summary> /// Serialize the mock TransValue entity into a temporary file. /// </summary> private void Step_06_SerializeEntity_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp_TransValue.xml"); EntityHelper.SerializeXml(mock, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock not found"); System.Console.WriteLine("mock correctly serialized to a temporary file."); } }
/// <summary> /// Inserts a mock TransValue entity into the database. /// </summary> private void Step_01_Insert_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Assert.IsTrue(DataRepository.TransValueProvider.Insert(tm, mock), "Insert failed"); System.Console.WriteLine("DataRepository.TransValueProvider.Insert(mock):"); System.Console.WriteLine(mock); //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
/// <summary> /// Serialize a TransValue collection into a temporary file. /// </summary> private void Step_08_SerializeCollection_Generated() { using (TransactionManager tm = CreateTransaction()) { string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp_TransValueCollection.xml"); mock = CreateMockInstance(tm); TList <TransValue> mockCollection = new TList <TransValue>(); mockCollection.Add(mock); EntityHelper.SerializeXml(mockCollection, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found"); System.Console.WriteLine("TList<TransValue> correctly serialized to a temporary file."); } }
///<summary> /// Returns a Typed TransValue Entity with mock values. ///</summary> static public TransValue CreateMockInstance_Generated(TransactionManager tm) { TransValue mock = new TransValue(); mock.TransNum = TestUtility.Instance.RandomString(5, false);; mock.Amount = (decimal)TestUtility.Instance.RandomShort(); mock.Frcustomer = (decimal)TestUtility.Instance.RandomShort(); mock.Forex = TestUtility.Instance.RandomString(3, false);; // create a temporary collection and add the item to it TList <TransValue> tempMockCollection = new TList <TransValue>(); tempMockCollection.Add(mock); tempMockCollection.Remove(mock); return((TransValue)mock); }
///<summary> /// Update the Typed TransValue Entity with modified mock values. ///</summary> static public void UpdateMockInstance_Generated(TransactionManager tm, TransValue mock) { mock.Amount = (decimal)TestUtility.Instance.RandomShort(); mock.Frcustomer = (decimal)TestUtility.Instance.RandomShort(); mock.Forex = TestUtility.Instance.RandomString(3, false);; }
/// <summary> /// Make any alterations necessary (i.e. for DB check constraints, special test cases, etc.) /// </summary> /// <param name="mock">Object to be modified</param> static private void SetSpecialTestData(TransValue mock) { //Code your changes to the data object here. }
public void BillingData() { Cursor.Current = Cursors.WaitCursor; using (SSLsEntities db = new SSLsEntities()) { DateTime dateS = dateTimePickerStart.Value; DateTime dateE = dateTimePickerEnd.Value; int checkCombo1 = 0; int checkCombo2 = 0; List <int> fkProHd = new List <int>(); string code1 = textBox1.Text.Trim(); string code2 = textBox2.Text.Trim(); if (code1 == "") { fkProHd = db.StoreFrontStock.Where(w => w.Enable == true).Select(w => w.FKProduct).Distinct().ToList(); } else { fkProHd = Library.GetAllProDtlId(code1, code2); } //if (comboBox1.Text != "ทั้งหมด") //{ // checkCombo1 = int.Parse(comboBox1.SelectedValue.ToString()); // checkCombo2 = int.Parse(comboBox2.SelectedValue.ToString()); // fkProHd = db.StoreFrontStock.Where(w => w.Enable == true).Select(w => w.FKProduct).Distinct().ToList(); //} //else //{ // fkProHd = Library.GetAllProDtlId(code1, code2); //} //var txt1 = Singleton.SingletonProduct.Instance().ProductDetails.Where(ww => ww.Code == textBox1.Text & ww.Enable == true).Select(s => s.FKProduct).FirstOrDefault(); //var txt2 = Singleton.SingletonProduct.Instance().ProductDetails.Where(ww => ww.Code == textBox2.Text & ww.Enable == true).Select(s => s.FKProduct).FirstOrDefault(); // var listData = db.StoreFrontStockDetails.Where(w => w.Enable == true && // fkProHd.Contains(w.StoreFrontStock.FKProduct) && // DbFunctions.TruncateTime(w.CreateDate) >= DbFunctions.TruncateTime(dateS) && // DbFunctions.TruncateTime(w.CreateDate) <= DbFunctions.TruncateTime(dateE) && //(checkCombo1 == 0 && checkCombo2 == 0 ? //(w.StoreFrontStock.Products.FKProductGroup > 0) : //(w.StoreFrontStock.Products.FKProductGroup >= checkCombo1 && //w.StoreFrontStock.Products.FKProductGroup <= checkCombo2))).ToList(); var listData = db.StoreFrontStockDetails.Where(w => w.Enable == true && fkProHd.Contains(w.StoreFrontStock.FKProduct) && DbFunctions.TruncateTime(w.CreateDate) >= DbFunctions.TruncateTime(dateS) && DbFunctions.TruncateTime(w.CreateDate) <= DbFunctions.TruncateTime(dateE) ).ToList(); var list1 = listData .GroupBy(g => new { g.StoreFrontStock.Products.ProductDetails.OrderBy(w => w.PackSize).FirstOrDefault().Code, g.StoreFrontStock.Products.ThaiName, g.StoreFrontStock.FKProduct, g.FKStoreFrontStock, g.FKTransactionType, UnitName = g.StoreFrontStock.Products.ProductDetails.Where(w => w.PackSize == 1).Select(ss => (ss.ProductUnit.Name == null ? "ไม่มี" : ss.ProductUnit.Name)).FirstOrDefault(), ยอดยกมา = 0, ยอดยกไป = 0, Price = 0 }) .Select(s => new { ProductId = s.Key.FKProduct, Product = s.Key.Code + " " + s.Key.ThaiName, FKS = s.Key.FKStoreFrontStock, Id = s.Key.FKTransactionType, s.Key.UnitName, s.Key.ยอดยกมา, s.Key.ยอดยกไป, ActionQty = (s.Sum(ss => ss.ActionQty) == null ? 0 : s.Sum(ss => ss.ActionQty)), s.Key.Price }).GroupBy(g => new { g.ProductId, g.Product, g.UnitName, g.ยอดยกมา, g.ยอดยกไป, g.Price, g.Id }) .Select(s => new { ProuctId = s.Key.ProductId, Product = s.Key.Product, UnitName = s.Key.UnitName, Summit = s.Key.ยอดยกมา, LiftUp = s.Key.ยอดยกไป, Price = s.Key.Price, Buy = (s.Key.Id == 19 ? s.Sum(m => m.ActionQty) : 0), SendVender = (s.Key.Id == 3 ? s.Sum(m => m.ActionQty) : 0), Sell = (s.Key.Id == 2 ? s.Sum(m => m.ActionQty) : 0), SellGive = (s.Key.Id == 11 ? s.Sum(m => m.ActionQty) : 0), Cn = (s.Key.Id == 4 || s.Key.Id == 22 ? s.Sum(m => m.ActionQty) : 0), CnGive = (s.Key.Id == 12 ? s.Sum(m => m.ActionQty) : 0), CnCancel = (s.Key.Id == 5 ? s.Sum(m => m.ActionQty) : 0), CnGiveCancel = (s.Key.Id == 17 ? s.Sum(m => m.ActionQty) : 0), Rcv = (s.Key.Id == 1 ? s.Sum(m => m.ActionQty) : 0), RcvPo = (s.Key.Id == 10 ? s.Sum(m => m.ActionQty) : 0), OutUse = (s.Key.Id == 14 ? s.Sum(m => m.ActionQty) : 0), Out = (s.Key.Id == 8 ? s.Sum(m => m.ActionQty) : 0), AdjustCost = (s.Key.Id == 20 ? s.Sum(m => m.ActionQty) : 0), Tran = (s.Key.Id == 9 ? s.Sum(m => m.ActionQty) : 0) }).GroupBy(g => new { g.ProuctId, g.Product, g.UnitName, g.Summit, g.LiftUp, g.Price }) .Select(s => new { ProuctId = s.Key.ProuctId, Product = s.Key.Product, UnitName = s.Key.UnitName, Summit = s.Key.Summit, LiftUp = s.Key.LiftUp, Price = s.Key.Price, Buy = s.Sum(ss => ss.Buy), SendVender = s.Sum(ss => ss.SendVender), Sell = s.Sum(ss => ss.Sell), SellGive = s.Sum(ss => ss.SellGive), Cn = s.Sum(ss => ss.Cn), CnGive = s.Sum(ss => ss.CnGive), CnCancel = s.Sum(ss => ss.CnCancel), CnGiveCancel = s.Sum(ss => ss.CnGiveCancel), Rcv = s.Sum(ss => ss.Rcv), RcvPo = s.Sum(ss => ss.RcvPo), OutUse = s.Sum(ss => ss.OutUse), Out = s.Sum(ss => ss.Out), AdjustCost = s.Sum(ss => ss.AdjustCost), Tran = s.Sum(ss => ss.Tran) }).ToList(); List <TransValue> ls = new List <TransValue>(); int i = 0; int countListpg = list1.Count(); progressBar1.Minimum = 0; progressBar1.Maximum = countListpg; foreach (var item in list1) { i++; TransValue c = new TransValue(); c.ProuctId = item.ProuctId.ToString(); c.Product = item.Product.ToString(); c.UnitName = item.UnitName; c.Summit = GetResult(item.ProuctId, dateS); c.LiftUp = GetBalance(item.ProuctId, dateS, dateE); c.Price = Library.GetAverage(item.ProuctId); c.Buy = item.Buy; c.SendVender = item.SendVender; c.Sell = item.Sell; c.SellGive = item.SellGive; c.Cn = item.Cn; c.CnCancel = item.CnCancel; c.CnGiveCancel = item.CnGiveCancel; c.Rcv = item.Rcv; c.RcvPo = item.RcvPo; c.OutUse = item.OutUse; c.Out = item.Out; c.AdjustCost = item.AdjustCost; c.Tran = item.Tran; ls.Add(c); progressBar1.Value = i; progressBar1.Refresh(); } if (list1.Count > 0) { string User, WhereDate, WhereProduct, WhereGroupP; //User = Singleton.SingletonAuthen.Instance().Name; User = Singleton.SingletonAuthen.Instance().Name; WhereDate = Library.ConvertDateToThaiDate(dateS) + " ถึง " + Library.ConvertDateToThaiDate(dateE); WhereProduct = (textBox1.Text == "" ? "ค้นหา รหัส Barcode สินค้าทั้งหมด" : "ค้นหา รหัส Barcode สินค้า : " + textBox1.Text + " ถึง " + textBox2.Text); WhereGroupP = (comboBox1.Text == "ทั้งหมด" ? "ค้นหา หมวดสินค้าทั้งหมด" : "ค้นหา หมวดสินค้า : " + comboBox1.Text + " ถึง " + comboBox2.Text); DataTable dt = CodeFileDLL.ConvertToDataTable(ls); frmMainReport frm = new frmMainReport(this, dt, User, WhereDate, WhereProduct, WhereGroupP); Cursor.Current = Cursors.Default; frm.Show(); } else { Cursor.Current = Cursors.Default; MessageBox.Show("ไม่พบข้อมูล"); } } }