private void buttonDel_Click(object sender, EventArgs e) { try { if (listViewSupplySet.SelectedItems.Count == 1) { SupplySet supply = listViewSupplySet.SelectedItems[0].Tag as SupplySet; Program.esoft_Project.SupplySet.Remove(supply); Program.esoft_Project.SaveChanges(); ShowSupplySet(); } comboBoxAgents.Text = null; comboBoxClients.Text = null; comboBoxRealEstate.Text = null; textBoxPrice.Text = ""; } catch { MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void listViewSupplySet_SelectedIndexChanged(object sender, EventArgs e) { if (listViewSupplySet.SelectedItems.Count == 1) { SupplySet supply = listViewSupplySet.SelectedItems[0].Tag as SupplySet; comboBoxAgents.SelectedIndex = comboBoxAgents.FindString(supply.IdAgent.ToString()); comboBoxClients.SelectedIndex = comboBoxClients.FindString(supply.IdClient.ToString()); comboBoxRealEstate.SelectedIndex = comboBoxRealEstate.FindString(supply.IdRealEstate.ToString()); textBoxPrice.Text = supply.Price.ToString(); } else { comboBoxAgents.SelectedItem = null; comboBoxClients.SelectedItem = null; comboBoxRealEstate.SelectedItem = null; textBoxPrice.Text = ""; } }
private void buttonEdit_Click(object sender, EventArgs e) { try { if (listViewSupplySet.SelectedItems.Count == 1) { SupplySet supply = listViewSupplySet.SelectedItems[0].Tag as SupplySet; supply.IdAgent = Convert.ToInt32(comboBoxAgents.SelectedItem.ToString().Split('.')[0]); supply.IdClient = Convert.ToInt32(comboBoxClients.SelectedItem.ToString().Split('.')[0]); supply.IdRealEstate = Convert.ToInt32(comboBoxRealEstate.SelectedItem.ToString().Split('.')[0]); if (textBoxPrice.Text != "") { supply.Price = Convert.ToInt64(textBoxPrice.Text); } else { throw new Exception("Поле цены не заполнено"); } Program.esoft_Project.SaveChanges(); ShowSupplySet(); } } catch (Exception ex) { MessageBox.Show("" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonAdd_Click(object sender, EventArgs e) { //проверяем, что все поля были заполнены if (comboBoxAgents.SelectedItem != null && comboBoxClients.SelectedItem != null && comboBoxRealEstate.SelectedItem != null && textBoxPrice.Text != "") { //создаем новый экземпляр класса Предложение SupplySet supply = new SupplySet(); //из выьранной строки в comboBoxAgents отделяем Id Риелтора (он отделен точкой) и делаем ссылку supply.IdAgent supply.IdAgent = Convert.ToInt32(comboBoxAgents.SelectedItem.ToString().Split('.')[0]); //точно также с клиентом и объектом недвижимости supply.IdClient = Convert.ToInt32(comboBoxClients.SelectedItem.ToString().Split('.')[0]); supply.IdRealEstate = Convert.ToInt32(comboBoxRealEstate.SelectedItem.ToString().Split('.')[0]); //цена чаще всего превосходит миллион, поэтому используем Int64 supply.Price = Convert.ToInt64(textBoxPrice.Text); //добавляем и сохраняем в таблицу SupplySet Program.esoft_Project.SupplySet.Add(supply); Program.esoft_Project.SaveChanges(); ShowSupplySet(); } else { MessageBox.Show("Данные не выбраны!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
protected override DbEntityValidationResult ValidateEntity(DbEntityEntry entityEntry, IDictionary <object, object> items) { var result = base.ValidateEntity(entityEntry, items); if (entityEntry.Entity is PrinterModel) { var printerModel = (PrinterModel)entityEntry.Entity; if (entityEntry.State == EntityState.Added || entityEntry.State == EntityState.Modified) { if (PrinterModelSet.Any(x => x.Id != printerModel.Id && x.Name.ToLower() == printerModel.Name.ToLower())) { AddDBValidationError(result, "Name", "Значение должно быть уникальным."); } } if (entityEntry.State == EntityState.Deleted) { if (PrinterSet.Any(x => x.ModelId == printerModel.Id)) { AddDBValidationError(result, "", String.Format("Перед удалением {0} нужно удалить все принтеры этой модели.", printerModel.Name)); } } } if (entityEntry.Entity is Printer) { var printer = (Printer)entityEntry.Entity; if (entityEntry.State == EntityState.Added || entityEntry.State == EntityState.Modified) { if (PrinterSet.Any(x => x.Id != printer.Id && x.Name.ToLower() == printer.Name.ToLower())) { AddDBValidationError(result, "Name", "Значение должно быть уникальным."); } } } if (entityEntry.Entity is SupplyModel) { var supplyModel = (SupplyModel)entityEntry.Entity; if (entityEntry.State == EntityState.Added || entityEntry.State == EntityState.Modified) { if (SupplyModelSet.Any(x => x.Id != supplyModel.Id && x.PartNumber.ToLower() == supplyModel.PartNumber.ToLower())) { AddDBValidationError(result, "PartNumber", "Значение должно быть уникальным."); } if (supplyModel.PrinterModels.Count() < 1) { AddDBValidationError(result, "PrinterModelIds", "Нужно выбрать хотя бы одну совместимую модель принтера."); } } if (entityEntry.State == EntityState.Modified) { foreach (var supply in supplyModel.Supplies) { foreach (var supplySlot in supply.SupplySlots) { if (!supplyModel.PrinterModels.Contains(supplySlot.Printer.PrinterModel)) { AddDBValidationError(result, "PrinterModelIds", string.Format("Требуется совместимость с {0}. В принтере {1} установлены расходные материалы этой модели.", supplySlot.Printer.PrinterModel.Name, supplySlot.Printer.Name)); } } } } if (entityEntry.State == EntityState.Deleted) { if (SupplySet.Any(x => x.ModelId == supplyModel.Id)) { AddDBValidationError(result, "", String.Format("Перед удалением {0} нужно удалить все расходные материалы этой модели.", supplyModel.GetFullName())); } } } if (entityEntry.Entity is SupplySlot) { var supplySlot = (SupplySlot)entityEntry.Entity; if (entityEntry.State == EntityState.Modified) { if (supplySlot.Supply != null) { if (!supplySlot.Printer.PrinterModel.SupplyModels.Contains(supplySlot.Supply.SupplyModel)) { AddDBValidationError(result, "SupplyId", string.Format("Расходный материал {0} не совместим с принтером.", supplySlot.SupplyId)); } if (supplySlot.Supply.SupplySlots.Count() > 1) { AddDBValidationError(result, "SupplyId", string.Format("Расходный материал {0} установлен в другой принтер.", supplySlot.SupplyId)); } } } } return(result); }
internal static void SupplyChangeCommand(CommandArgs args) { Player player = args.TPlayer; var settings = AutoSupplyMain.Instance.Settings; if (settings == null) { return; } var canChooseSet = new List <SupplySet>(); foreach (var set in settings.SupplySets) { // 不要なはず set.Parse(); // Default, GMは除外 if (set.Name == "DEFAULT" || set.Name == SupplySettings.GMSET_NAME) { continue; } // チームで選択可能かを判断 if (set.TeamIDs.Contains(player.team)) { canChooseSet.Add(set); } } string supplySelectErrorMsg = string.Format("Invalid supply name! Usage: {0}{1} <supply_name>\nSupply List: {2}", new object[] { TShock.Config.CommandSpecifier, settings.SupplyCommand, string.Join(", ", canChooseSet.Select(x => x.Name.ToLower(CultureInfo.InvariantCulture))), }); // BAN範囲外か if (!AutoSupplyMain.Instance.IsInBanRange(player.Center.X, player.Center.Y)) { if (args.Parameters.Count != 1 || string.IsNullOrEmpty(args.Parameters[0])) { args.Player.SendErrorMessage(supplySelectErrorMsg); return; } Guid supplyId = default; string setName = args.Parameters[0].ToUpperInvariant(); SupplySet selectedSet = null; foreach (var set in canChooseSet) { if (set.Name == "DEFAULT" || set.Name == SupplySettings.GMSET_NAME) { continue; } if (set.Name == setName) { selectedSet = set; supplyId = set.ID; AutoSupplyMain.Instance.PlayerLastSupplyedId[player.whoAmI] = supplyId; break; } } if (setName == string.Format(CultureInfo.InvariantCulture, "GM-{0:D6}", GMCodeCommand.GMCODE)) { selectedSet = settings.GMSet; supplyId = selectedSet.ID; setName = SupplySettings.GMSET_NAME; } if (supplyId == default || selectedSet == null) { args.Player.SendErrorMessage(supplySelectErrorMsg); return; } Supply(args.Player, selectedSet); } else { args.Player.SendErrorMessage("You can\'t get supply in the ban area."); } }
public static void Supply(TSPlayer tsPlayer, SupplySet set) { if (tsPlayer == null || set == null) { return; } var player = tsPlayer.TPlayer; var oldSupplyId = AutoSupplyMain.Instance.PlayerLastSupplyedId[player.whoAmI]; string oldSupplySetName = AutoSupplyMain.Instance.Settings.SupplySets.FirstOrDefault(x => x.ID == oldSupplyId)?.Name ?? "None"; AutoSupplyMain.WriteLog(string.Format( CultureInfo.InvariantCulture, "SUPPLY:{0},{1},{2},{3},{4}", player.name, oldSupplySetName, set.Name, player.position.X, player.position.Y)); AutoSupplyMain.Instance.PlayerLastSupplyedId[player.whoAmI] = set.ID; // Clear inventory for (int invIndex = 0; invIndex < NetItem.InventorySlots; ++invIndex) { player.inventory[invIndex] = new Item(); } for (int invIndex = 0; invIndex < NetItem.ArmorSlots; ++invIndex) { player.armor[invIndex] = new Item(); } for (int invIndex = 0; invIndex < NetItem.DyeSlots; ++invIndex) { player.dye[invIndex] = new Item(); } for (int invIndex = 0; invIndex < NetItem.MiscEquipSlots; ++invIndex) { player.miscEquips[invIndex] = new Item(); } for (int invIndex = 0; invIndex < NetItem.MiscDyeSlots; ++invIndex) { player.miscDyes[invIndex] = new Item(); } // Clear buffs int buffLength = player.buffType.Length; for (int buffIndex = 0; buffIndex < buffLength; buffIndex++) { player.DelBuff(buffIndex); } // Clear own projectiles int projLength = Main.projectile.Length; for (int projIndex = 0; projIndex < projLength; projIndex++) { if (Main.projectile[projIndex].owner == player.whoAmI) { Main.projectile[projIndex].timeLeft = 2; Main.projectile[projIndex].netUpdate = true; } } const int MAX_INVENTORY = 49; const int VANITY_START = 10; const int ACCESSORY_START = 3; // Inventory for (int j = 0; j < set.Items.Count; j++) { set.Items[j].Parse(); player.inventory[j].SetDefaults(set.Items[j].ItemID); player.inventory[j].prefix = (byte)set.Items[j].Prefix; player.inventory[j].stack = set.Items[j].Stack; } // Ammos for (int j = 0; j < set.Ammos.Count; j++) { set.Ammos[j].Parse(); player.inventory[MAX_INVENTORY - j].SetDefaults(set.Ammos[j].ItemID); player.inventory[MAX_INVENTORY - j].prefix = (byte)set.Ammos[j].Prefix; player.inventory[MAX_INVENTORY - j].stack = set.Ammos[j].Stack; } // Armors for (int j = 0; j < set.Armors.Count; j++) { set.Armors[j].Parse(); int index = set.Armors[j].SlotID; player.armor[index].SetDefaults(set.Armors[j].ItemID); player.armor[index].prefix = (byte)set.Armors[j].Prefix; player.armor[index].stack = set.Armors[j].Stack; } // VanityArmors for (int j = 0; j < set.VanityArmors.Count; j++) { set.VanityArmors[j].Parse(); int index = set.VanityArmors[j].SlotID; player.armor[VANITY_START + index].SetDefaults(set.VanityArmors[j].ItemID); player.armor[VANITY_START + index].prefix = (byte)set.VanityArmors[j].Prefix; player.armor[VANITY_START + index].stack = set.VanityArmors[j].Stack; } // Armor Dyes for (int j = 0; j < set.ArmorDyes.Count; j++) { set.ArmorDyes[j].Parse(); player.dye[j].SetDefaults(set.ArmorDyes[j].ItemID); player.dye[j].prefix = (byte)set.ArmorDyes[j].Prefix; player.dye[j].stack = set.ArmorDyes[j].Stack; } // Accessories for (int j = 0; j < set.Accessorys.Count; j++) { set.Accessorys[j].Parse(); player.armor[ACCESSORY_START + j].SetDefaults(set.Accessorys[j].ItemID); player.armor[ACCESSORY_START + j].prefix = (byte)set.Accessorys[j].Prefix; player.armor[ACCESSORY_START + j].stack = set.Accessorys[j].Stack; } // Vanity Accessories for (int j = 0; j < set.VanityAccessorys.Count; j++) { set.VanityAccessorys[j].Parse(); player.armor[VANITY_START + ACCESSORY_START + j].SetDefaults(set.VanityAccessorys[j].ItemID); player.armor[VANITY_START + ACCESSORY_START + j].prefix = (byte)set.VanityAccessorys[j].Prefix; player.armor[VANITY_START + ACCESSORY_START + j].stack = set.VanityAccessorys[j].Stack; } // Accessory Dyes for (int j = 0; j < set.AccessoryDyes.Count; j++) { set.AccessoryDyes[j].Parse(); player.dye[ACCESSORY_START + j].SetDefaults(set.AccessoryDyes[j].ItemID); player.dye[ACCESSORY_START + j].prefix = (byte)set.AccessoryDyes[j].Prefix; player.dye[ACCESSORY_START + j].stack = set.AccessoryDyes[j].Stack; } // Misc Items for (int j = 0; j < set.MiscItems.Count; j++) { set.MiscItems[j].Parse(); int index = set.MiscItems[j].SlotID; player.miscEquips[index].SetDefaults(set.MiscItems[j].ItemID); player.miscEquips[index].prefix = (byte)set.MiscItems[j].Prefix; player.miscEquips[index].stack = set.MiscItems[j].Stack; } // Misc Dyes for (int j = 0; j < set.MiscDyes.Count; j++) { set.MiscDyes[j].Parse(); int index = set.MiscDyes[j].SlotID; player.miscDyes[index].SetDefaults(set.MiscDyes[j].ItemID); player.miscDyes[index].prefix = (byte)set.MiscDyes[j].Prefix; player.miscDyes[index].stack = set.MiscDyes[j].Stack; } player.statLifeMax = set.HP; player.statManaMax = set.MP; if (player.statLife > player.statLifeMax) { player.statLife = player.statLifeMax; } // Send Charactor int playerIndex = tsPlayer.Index; bool isSSC = Main.ServerSideCharacter; if (!isSSC) { Main.ServerSideCharacter = true; NetMessage.SendData(7, playerIndex, -1, null, 0, 0f, 0f, 0f, 0, 0, 0); tsPlayer.IgnoreSSCPackets = true; } NetMessage.SendData(16, playerIndex, -1, null, playerIndex, 0f, 0f, 0f, 0, 0, 0); //Send life info NetMessage.SendData(42, playerIndex, -1, null, playerIndex, 0f, 0f, 0f, 0, 0, 0); //Send mana info player.extraAccessory = set.ExtraAccessory; NetMessage.SendData(4, playerIndex, -1, null, playerIndex, 0f, 0f, 0f, 0, 0, 0); //Send charactor info (include extra accessory slot) int masterInvIndex = 0; for (int invIndex = 0; invIndex < NetItem.InventorySlots; invIndex++) { NetMessage.SendData(5, -1, -1, null, playerIndex, masterInvIndex, player.inventory[invIndex].prefix, 0, 0, 0, 0); ++masterInvIndex; } // include accessory for (int invIndex = 0; invIndex < NetItem.ArmorSlots; invIndex++) { NetMessage.SendData(5, -1, -1, null, playerIndex, masterInvIndex, player.armor[invIndex].prefix, 0, 0, 0, 0); ++masterInvIndex; } for (int invIndex = 0; invIndex < NetItem.DyeSlots; invIndex++) { NetMessage.SendData(5, -1, -1, null, playerIndex, masterInvIndex, player.dye[invIndex].prefix, 0, 0, 0, 0); ++masterInvIndex; } // Hooks, Light Pet, etc... for (int invIndex = 0; invIndex < NetItem.MiscEquipSlots; invIndex++) { NetMessage.SendData(5, -1, -1, null, playerIndex, masterInvIndex, player.miscEquips[invIndex].prefix, 0, 0, 0, 0); ++masterInvIndex; } for (int invIndex = 0; invIndex < NetItem.MiscDyeSlots; invIndex++) { NetMessage.SendData(5, -1, -1, null, playerIndex, masterInvIndex, player.miscDyes[invIndex].prefix, 0, 0, 0, 0); ++masterInvIndex; } var trashItem = Main.player[playerIndex].trashItem; NetMessage.SendData(5, playerIndex, -1, new NetworkText(trashItem.Name, NetworkText.Mode.Formattable), playerIndex, 179f, trashItem.prefix, 0.0f, 0, 0, 0); // Send buff info NetMessage.SendData(50, -1, -1, null, playerIndex, 0f, 0f, 0f, 0, 0, 0); if (!isSSC) { Main.ServerSideCharacter = false; // Send world info NetMessage.SendData(7, playerIndex, -1, null, 0, 0.0f, 0.0f, 0.0f, 0, 0, 0); tsPlayer.IgnoreSSCPackets = false; } AutoSupplyMain.Instance.SetBuffs(set, playerIndex); return; }