public static bool DeleteData(Order_Item x) { //Order_Item.UpdateData(x); return(BaseDataBase._StoredProcedure("sp_Delete_Order_Item" , new SqlParameter("@OrderID", x.Order.Id) , new SqlParameter("@ItemID", x.Item.Id))); }
private void btnAddItem_Click(object sender, RoutedEventArgs e) { Item i; if (lbItemsFiltered.Visibility == Visibility.Visible) { if (lbItemsFiltered.SelectedIndex == -1) { return; } var iFiltered = lbItemsFiltered.SelectedItem as Item; i = (lbMainItems.ItemsSource as List <Item>).Where(x => x.Id == iFiltered.Id).FirstOrDefault(); txtSearch.Text = string.Empty; } else { if (lbMainItems.SelectedIndex == -1) { return; } i = lbMainItems.SelectedItem as Item; } Order_Item s = new Order_Item(); s.Item = i; s.Quantity = 1; (dgSelectedItems.ItemsSource as List <Order_Item>).Add(s); (lbMainItems.ItemsSource as List <Item>).Remove(i); RefreshPanel(); }
public static List <Order_Item> GetAllOrder_ItemByOrder(Order Order) { List <Order_Item> xx = new List <Order_Item>(); SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString); SqlCommand com = new SqlCommand("sp_Get_All_Order_Item_ByOrderID", con); com.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter pr1 = new SqlParameter("@OrderID", Order.Id); com.Parameters.Add(pr1); try { con.Open(); SqlDataReader rd = com.ExecuteReader(); while (rd.Read()) { Order_Item x = new Order_Item(); x.Order = Order; x.Item = Item.GetItemByID(int.Parse(rd["ItemID"].ToString())); x.Quantity = double.Parse(rd["Quantity"].ToString()); x.LastUserID = int.Parse(rd["LastUserID"].ToString()); xx.Add(x); } rd.Close(); } catch { xx = null; } finally { con.Close(); } return(xx); }
async void InsertOrderItems(Order order) { foreach (var item in order.OIs) { if (item.Order == null) { item.Order = order; Order_Item.InsertData(item); } else { Order_Item.UpdateData(item); } } foreach (var item in DeletedItems) { if (item.Order != null) { Order_Item.DeleteData(item); } } await Dispatcher.BeginInvoke(new Action(() => { PrintOrder(order); }), System.Windows.Threading.DispatcherPriority.Normal); }
public static bool UpdateData(Order_Item x) { return(BaseDataBase._StoredProcedure("sp_Update_Order_Item" , new SqlParameter("@OrderID", x.Order.Id) , new SqlParameter("@ItemID", x.Item.Id) , new SqlParameter("@Quantity", x.Quantity) , new SqlParameter("@LastUserID", BaseDataBase.CurrentUser.ID))); }
private void btnSave_Click(object sender, RoutedEventArgs e) { var order = this.DataContext as Order; if (order.IsValidateMainOrderData() && order.IsValidateOrderItemsData()) { try { if (order.Type == 5) { if (cmboInventory2.SelectedValue == null || int.Parse(cmboInventory2.SelectedValue.ToString()) == order.InventoryID) { MyMessageBox.Show("يجب اختيار المستودع المراد نقل المواد اليه ويجب ان يكون مختلفا عن المستودع الاساسي"); return; } } if (order.Id == null) { if (Order.InsertData(order)) { if (MyMessageBox.Show("هل تريد طباعة وصل", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { PrintTicket.printReportA6(order); } MyMessage.InsertMessage(); } } else { if (Order.UpdateData(order)) { MyMessage.UpdateMessage(); } } foreach (var item in order.OIs) { if (item.Order == null) { item.Order = order; Order_Item.InsertData(item); } else { Order_Item.UpdateData(item); } } foreach (var item in DeletedItems) { if (item.Order != null) { Order_Item.DeleteData(item); } } DialogResult = true; } catch (Exception ex) { MyMessageBox.Show(ex.Message); } } }
public static bool DeleteData(Order x) { //foreach (var item in x.FamilyNeeds) //{ // item.OrderID = null; // FamilyNeed_ListerGroup.UpdateData(item); //} foreach (var item in x.OIs) { Order_Item.DeleteData(item); } return(BaseDataBase._StoredProcedure("sp_Delete_Order" , new SqlParameter("@Id", x.Id))); }
private void btnDelItem_Click(object sender, RoutedEventArgs e) { if (dgSelectedItems.SelectedIndex != -1) { txtSearch.Text = string.Empty; Order_Item s = dgSelectedItems.SelectedItem as Order_Item; var i = s.Item; if (s.Order != null) { double currentQuantity = 0; double previousQuantity = 0; if (s.Order.Id.HasValue) { double.TryParse(BaseDataBase._Scalar($"select IsNUll(sum(Quantity),0) from Order_Item where ItemId={s.Item.Id} and OrderID = {s.Order.Id}"), out previousQuantity); } else { previousQuantity = 0; } double.TryParse(BaseDataBase._Scalar($"select Quantity from Batch_Item where InventoryID = {s.Order.InventoryID} and ItemID = {s.Item.Id}"), out currentQuantity); if (s.Order.Type == 1) { if (currentQuantity - previousQuantity < (s.Item.MinimumQuantity.HasValue ? s.Item.MinimumQuantity : 0)) { MyMessageBox.Show($"القيمة الحالية للمادة \"{s.Item.Name}\" هو {currentQuantity}\nبينما الحد الادنى الذي يجب ان يحويه المستودع هو {(s.Item.MinimumQuantity.HasValue ? s.Item.MinimumQuantity : 0)}\nلا يمكن حذف المادة"); return; } } else { if (s.Item.MaximumQuantity.HasValue && currentQuantity + previousQuantity > s.Item.MaximumQuantity) { MyMessageBox.Show($"القيمة الحالية للمادة \"{s.Item.Name}\" هو {currentQuantity}\nبينما الحد الاعلى الذي يجب ان يحويه المستودع هو {s.Item.MaximumQuantity}\nلا يمكن حذف المادة"); return; } } } (lbMainItems.ItemsSource as List <Item>).Add(i); (dgSelectedItems.ItemsSource as List <Order_Item>).Remove(s); RefreshPanel(); if (s != null) { DeletedItems.Add(s); } } }
public static Order_Item GetOrder_ItemByID(Order Order, Item Item) { Order_Item x = new Order_Item(); SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString); SqlCommand com = new SqlCommand("sp_Get_ID_Order_Item", con); com.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter pr1 = new SqlParameter("@OrderID", Order.Id); com.Parameters.Add(pr1); SqlParameter pr2 = new SqlParameter("@Item", Item.Id); com.Parameters.Add(pr2); try { con.Open(); SqlDataReader rd = com.ExecuteReader(); if (rd.Read()) { x.Order = Order; x.Item = Item; if (!(rd["Quantity"] is DBNull)) { x.Quantity = double.Parse(rd["Quantity"].ToString()); } if (!(rd["LastUserID"] is DBNull)) { x.LastUserID = int.Parse(rd["LastUserID"].ToString()); } } rd.Close(); } catch { x = null; } finally { con.Close(); } return(x); }
public static List <Order_Item> GetFamilyCriteria(int FamilyID) { List <Order_Item> OIs = new List <Order_Item>(); SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString); SqlCommand com = new SqlCommand("GetFamilyCriteria", con); com.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter pr = new SqlParameter("@FamilyID", FamilyID); com.Parameters.Add(pr); try { con.Open(); SqlDataReader rd = com.ExecuteReader(); while (rd.Read()) { var x = new Order_Item(); if (!(rd["ID"] is DBNull)) { x.Item = Item.GetItemByID(System.Int32.Parse(rd["ID"].ToString())); } if (!(rd["Count"] is DBNull)) { x.Quantity = System.Int32.Parse(rd["Count"].ToString()); } OIs.Add(x); } rd.Close(); } catch { OIs = null; } finally { con.Close(); } return(OIs); }
public static bool InsertData(Order x, bool InsertOrderItems = false) { x.LastUserID = BaseDataBase.CurrentUser.ID.Value; x.Id = BaseDataBase._StoredProcedureReturnable("sp_Add_Order" , new SqlParameter("@Id", System.Data.SqlDbType.Int) , new SqlParameter("@InventoryID", x.InventoryID) , new SqlParameter("@FamilyID", x.FamilyID) , new SqlParameter("@OrphanID", x.OrphanID) , new SqlParameter("@SpecialFamilyID", x.SpecialFamilyID) , new SqlParameter("@Type", x.Type) , new SqlParameter("@Date", x.Date) , new SqlParameter("@NextOrderDate", x.NextOrderDate) , new SqlParameter("@Description", x.Description) , new SqlParameter("@Source", x.Source) , new SqlParameter("@InvoiceSerial", x.InvoiceSerial) , new SqlParameter("@Notes", x.Notes) , new SqlParameter("@LastUserID", x.LastUserID)); if (InsertOrderItems) { foreach (var item in x.OIs) { item.Order = x; Order_Item.InsertData(item); } } x.OrderCode = int.Parse(BaseDataBase._Scalar($"select OrderCode from [Order] where Id = {x.Id}")); x.BarCode = BaseDataBase._Scalar($"select BarCode from [Order] where Id = {x.Id}"); //if (x.Id.HasValue) //{ // foreach (var item in x.FamilyNeeds) // { // if (item.IsEnsured) // item.OrderID = x.Id; // else item.OrderID = null; // FamilyNeed_ListerGroup.UpdateData(item); // } //} return(x.Id.HasValue); }
//To Re Create public static List <Order> GetAllOrderByOrphanID(int OrphanID) { List <Order> xx = new List <Order>(); SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString); SqlCommand com = new SqlCommand("sp_Get_All_Order_ByOrphanID", con); com.CommandType = System.Data.CommandType.StoredProcedure; com.Parameters.Add(new SqlParameter("@OrphanID", OrphanID)); try { con.Open(); SqlDataReader rd = com.ExecuteReader(); while (rd.Read()) { Order x = new Order(); if (!(rd["Id"] is DBNull)) { x.Id = int.Parse(rd["Id"].ToString()); } if (!(rd["InventoryID"] is DBNull)) { x.InventoryID = int.Parse(rd["InventoryID"].ToString()); } if (!(rd["FamilyID"] is DBNull)) { x.FamilyID = int.Parse(rd["FamilyID"].ToString()); } if (!(rd["SpecialFamilyID"] is DBNull)) { x.SpecialFamilyID = int.Parse(rd["SpecialFamilyID"].ToString()); } if (!(rd["OrphanID"] is DBNull)) { x.OrphanID = int.Parse(rd["OrphanID"].ToString()); } if (!(rd["Type"] is DBNull)) { x.Type = int.Parse(rd["Type"].ToString()); } if (!(rd["Date"] is DBNull)) { x.Date = DateTime.Parse(rd["Date"].ToString()); } if (!(rd["NextOrderDate"] is DBNull)) { x.NextOrderDate = DateTime.Parse(rd["NextOrderDate"].ToString()); } x.Description = rd["Description"].ToString(); x.Source = rd["Source"].ToString(); x.InvoiceSerial = rd["InvoiceSerial"].ToString(); x.Notes = rd["Notes"].ToString(); if (!(rd["LastUserID"] is DBNull)) { x.LastUserID = int.Parse(rd["LastUserID"].ToString()); } x.OIs = Order_Item.GetAllOrder_ItemByOrder(x); xx.Add(x); } rd.Close(); } catch { xx = null; } finally { con.Close(); } return(xx); }
//Done public static List <Order> GetAllOrderBySpecialFamilyID(int SpecialFamilyID) { List <Order> xx = new List <Order>(); SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString); SqlCommand com = new SqlCommand("sp_Get_All_Order_BySpecialFamilyID", con); com.CommandType = System.Data.CommandType.StoredProcedure; com.Parameters.Add(new SqlParameter("@SpecialFamilyID", SpecialFamilyID)); try { con.Open(); SqlDataReader rd = com.ExecuteReader(); Order o = null; while (rd.Read()) { if (o == null || (int)rd["OrderID"] != o.Id.Value) { o = new Order(); o.Id = (int)rd["OrderID"]; o.InventoryID = (int)rd["InventoryID"]; if (!(rd["FamilyID"] is DBNull)) { o.FamilyID = int.Parse(rd["FamilyID"].ToString()); } if (!(rd["SpecialFamilyID"] is DBNull)) { o.SpecialFamilyID = int.Parse(rd["SpecialFamilyID"].ToString()); } if (!(rd["OrphanID"] is DBNull)) { o.OrphanID = int.Parse(rd["OrphanID"].ToString()); } o.Type = (int)rd["Type"]; o.Date = (DateTime)rd["Date"]; if (!(rd["NextOrderDate"] is DBNull)) { o.NextOrderDate = (DateTime)rd["NextOrderDate"]; } o.Description = rd["OrderDescription"].ToString(); o.Source = rd["OrderSource"].ToString(); o.InvoiceSerial = rd["InvoiceSerial"].ToString(); o.Notes = rd["OrderNotes"].ToString(); o.LastUserID = int.Parse(rd["OrderLastUserID"].ToString()); o.BarCode = rd["OrderBarcode"].ToString(); o.OrderCode = (int)rd["OrderCode"]; xx.Add(o); } Item i = new Item(); i.Id = (int)rd["ItemID"]; i.Name = rd["Name"].ToString(); i.IsActive = (bool)rd["IsActive"]; i.Source = rd["ItemSource"].ToString(); i.Barcode = rd["ItemBarcode"].ToString(); i.ItemType = rd["ItemType"].ToString(); i.Description = rd["ItemDescription"].ToString(); i.StandardUnit = rd["StandardUnit"].ToString(); i.Unit2 = rd["Unit2"].ToString(); if (!(rd["Unit2Convert"] is DBNull)) { i.Unit2Convert = (float)rd["Unit2Convert"]; } i.Unit3 = rd["Unit3"].ToString(); if (!(rd["Unit3Convert"] is DBNull)) { i.Unit3Convert = (float)rd["Unit3Convert"]; } if (!(rd["MinimumQuantity"] is DBNull)) { i.MinimumQuantity = (float)rd["MinimumQuantity"]; } if (!(rd["MaximumQuantity"] is DBNull)) { i.MaximumQuantity = (float)rd["MaximumQuantity"]; } if (!(rd["MaxQuantityPerOrder"] is DBNull)) { i.MaxQuantityPerOrder = (float)rd["MaxQuantityPerOrder"]; } if (!(rd["MaxQuantityPerFamily"] is DBNull)) { i.MaxQuantityPerFamily = (float)rd["MaxQuantityPerFamily"]; } if (!(rd["MaxQuantityPerDay"] is DBNull)) { i.MaxQuantityPerDay = (float)rd["MaxQuantityPerDay"]; } if (!(rd["WarningQuantity"] is DBNull)) { i.WarningQuantity = (float)rd["WarningQuantity"]; } if (!(rd["Weight"] is DBNull)) { i.Weight = (float)rd["Weight"]; } i.DefaultLocation = rd["DefaultLocation"].ToString(); i.Notes = rd["ItemNotes"].ToString(); i.LastUserID = (int)rd["ItemLastUserID"]; Order_Item oi = new Order_Item(); oi.Order = o; oi.Item = i; oi.Quantity = (float)rd["Quantity"]; oi.LastUserID = (int)rd["Order_ItemLastUserID"]; o.OIs.Add(oi); } rd.Close(); } catch { xx = null; } finally { con.Close(); } return(xx); }
private async void Window_Loaded(object sender, RoutedEventArgs e) { var o = this.DataContext as Order; if (o.Type != 1) { List <Item> lst = null; lst = await Item.GetAllItemsByInventory(o.InventoryID); if (lst == null || lst.Count == 0) { MyMessageBox.Show("المستودع الذي تم اختياره لا يحوي أي مادة حاليّاً"); DialogResult = false; return; } if (o.Id.HasValue) { foreach (var item in o.OIs) { if (lst.Select(x => x.Id).Contains(item.Item.Id)) { item.Item.CurrentQuantity = item.Quantity + lst.Where(x => x.Id == item.Item.Id).First().CurrentQuantity; } else { item.Item.CurrentQuantity = item.Quantity; } } dgSelectedItems.ItemsSource = o.OIs; lbMainItems.ItemsSource = (from x in lst where !IsItemExist(x) select x).ToList <Item>(); } else { if (o.OIs.Count > 0) { foreach (var item in o.OIs) { if (lst.Select(x => x.Id).Contains(item.Item.Id)) { item.Item.CurrentQuantity = item.Quantity + lst.Where(x => x.Id == item.Item.Id).First().CurrentQuantity; } else { item.Item.CurrentQuantity = item.Quantity; } } dgSelectedItems.ItemsSource = o.OIs; lbMainItems.ItemsSource = (from x in lst where !IsItemExist(x) select x).ToList <Item>(); } else { dgSelectedItems.ItemsSource = new List <Order_Item>(); lbMainItems.ItemsSource = lst; } } if (lst != null && (o.Type == 3 || o.Type == 4)) { var FormedItems = o.Type == 3 ? FormedBasket.GetFormedBasketByFamilyID(o.FamilyID.Value).Where(x => x.IsUrgent == o.IsUrgentOrder).ToList() : FormedBasket.ActiveItems; if (FormedItems != null && FormedItems.Count > 0) { FormedBasketSelectControl w = new FormedBasketSelectControl(FormedItems); if (w.ShowDialog() == true) { var fb = w.lstFormedBakset.SelectedItem as FormedBasket; foreach (var item in fb.FormedBasketItems) { if ((lbMainItems.ItemsSource as List <Item>).Where(x => x.Id == item.RelatedItem.Id).FirstOrDefault() == null) { MyMessageBox.Show("المادة (" + item.RelatedItem.Name + ") غير موجودة في قائمة المواد الحالية\nلم يتم اضافة تشكيلة المواد"); return; } } foreach (var item in fb.FormedBasketItems) { Item i = (lbMainItems.ItemsSource as List <Item>).Where(x => x.Id == item.RelatedItem.Id).FirstOrDefault(); Order_Item s = new Order_Item(); s.Item = i; s.Quantity = item.Quantity; (dgSelectedItems.ItemsSource as List <Order_Item>).Add(s); (lbMainItems.ItemsSource as List <Item>).Remove(i); } } } } } else { if (o.Id.HasValue) { dgSelectedItems.ItemsSource = o.OIs; lbMainItems.ItemsSource = (from x in Item.AllItems where !IsItemExist(x) select x).ToList <Item>(); } else { dgSelectedItems.ItemsSource = o.OIs; lbMainItems.ItemsSource = (from x in Item.AllItems where !IsItemExist(x) select x).ToList <Item>(); } } //Criteria if (o != null && !o.Id.HasValue && o.FamilyID.HasValue) { var OIs = Order_Item.GetFamilyCriteria(o.FamilyID.Value); if (OIs != null && OIs.Count > 0) { foreach (var s in OIs) { foreach (var i in lbMainItems.ItemsSource as List <Item> ) { if (i.Id.HasValue && i.Id.Value == s.Item.Id.Value) { s.Item.Id = i.Id; (dgSelectedItems.ItemsSource as List <Order_Item>).Add(s); (lbMainItems.ItemsSource as List <Item>).Remove(i); break; } } } } } RefreshPanel(); }