private void insertFunc(object sender, RoutedEventArgs e) { if (markcontact.SelectedItem == null || string.IsNullOrEmpty(refprice.Text) || string.IsNullOrEmpty(name.Text)) { MessageBox.Show("Талбар дутууу !!!!"); return; } long contract = Convert.ToInt64(markcontact.SelectedValue); using (demoEntities10 conx = new demoEntities10()) { var idexist = conx.RefPrices.Count(a => a.contractId == contract); if (idexist != 0) { MessageBox.Show("contract давтагдсан байна " + markcontact.SelectedValue.ToString() + " !!!"); return; } var re = new RefPrice() { contractId = contract, refprice1 = Convert.ToDecimal(refprice.Text), name = name.Text, modified = DateTime.Now, }; conx.RefPrices.Add(re); conx.SaveChanges(); } // string refPrice = refprice.Text; // System.Data.SqlClient.SqlConnection sqlConnection1 = //new System.Data.SqlClient.SqlConnection(connectionString); // System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); // cmd.CommandType = System.Data.CommandType.Text; // cmd.CommandText = "DELETE demo.dbo.RefPrice WHERE id = '" + contrid + "'; " + // "insert into dbo.RefPrice (id,refprice, modified) values" + // " ("+ contrid + ",'" + refPrice + "', getdate())"; // cmd.Connection = sqlConnection1; // sqlConnection1.Open(); // try // { // cmd.ExecuteNonQuery(); // } // catch (SqlException ex) // { // if (ex.Number == 2) // { // MessageBox.Show("contract 2 is already price edit it !!!"); // } // else throw; // } // sqlConnection1.Close(); FillDataGrid(); }
void displayPrice(GUIOverlappedImageButton button, RefPrice[] prices, float itemWorth) { if (prices == null) return; int priceIndex = 0; foreach(RefPrice price in prices) { RefItem condRefItem = RefData.Instance.RefItems[price.refItemId]; string str = "<color=white>"; int cost = (int)(price.count*itemWorth); ItemObject inventoryItemObj = Warehouse.Instance.FindItem(price.refItemId); long hasCount = 0; if (inventoryItemObj == null) { str = "<color=red>"; } else if (inventoryItemObj != null) { if (inventoryItemObj.Item.Count < cost) { str = "<color=red>"; } hasCount = inventoryItemObj.Item.Count; } //str += hasCount; //str += "/" + cost; str += cost; str += "</color>"; button.GUIImages[priceIndex].Lable.Text.text = str; ++priceIndex; } }
public static void PayPriceItem(RefPrice[] conds, float itemWorth) { if (conds == null) return; foreach(RefPrice price in conds) { Warehouse.Instance.PullItem(Warehouse.Instance.FindItem(price.refItemId), (int)(price.count*itemWorth)); } }
public static bool CheckAvailableItem(RefPrice[] conds, float itemWorth) { if (conds == null) return false; foreach(RefPrice price in conds) { ItemObject inventoryItemObj = Warehouse.Instance.FindItem(price.refItemId); if (inventoryItemObj == null) return false; if (inventoryItemObj != null) { if (inventoryItemObj.Item.Count < price.count*itemWorth) return false; } } return true; }