private void UpdateSelectedItem() { ContractItem item = this.managersListView.SelectedItem as ContractItem; bool enabled = item != null && item.Selected && item.Contract.Type == ContractType.Manager; bool created = item != null && item.Contract.IsCreated; this.createContractButton.Enabled = enabled; this.sendCreateManagerMenuItem.Enabled = enabled; this.changeCodeManagerMenuItem.Enabled = enabled && created; this.copyAddresManagerMenuItem.Enabled = enabled && item != null && item.Contract.IsLoaded; this.renameManagerMenuItem.Enabled = enabled; this.sendGramsToMenuItem.Enabled = enabled && created && false; if (enabled) { this.managerGroupBox.Text = item.Contract.Name; this.addressTextBox.Text = item.Contract.Address; } else { this.managerGroupBox.Text = ""; this.addressTextBox.Text = ""; } this.contractListView.Items.Clear(); if (enabled) { foreach (Contract contract in SelectedManager.Contracts) { this.contractListView.Items.Add(new ContractItem(contract)); } } }
public static void SendGrams(Form parent, ContractItem senderItem, OwnerItem destItem) { if (senderItem != null && destItem != null) { if (destItem != null) { using (SendGramForm form = new SendGramForm(senderItem.Contract, destItem.Owner)) { if (form.ShowDialog(parent) == DialogResult.OK) { if (Constants.LinuxMode && form.Grams > 0) { senderItem.StartWait(); destItem.StartWait(); ThreadStack.Run(delegate(object[] param) { Contract src = param[0] as Contract; Owner dst = param[1] as Owner; src.SendGram(dst.Address, (double)(decimal)param[2]); if (dst is Contract) { (dst as Contract).WaitGramsChanged(); } }, senderItem.Contract, destItem.Owner, form.Grams); } } } } } }
private void Rename(ContractItem contractItem) { if (contractItem != null) { Contract contract = contractItem.Contract; using (RenameForm form = new RenameForm(contract.Name)) { if (form.ShowDialog(this) == DialogResult.OK) { if (contract.Name != form.NewName) { contract.Name = form.NewName; if (Constants.LinuxMode) { contractItem.StartWait(); contract.ChangeOwner(true); if (contract is ManagerContract) { contract.Save(); } } } } } } }
private void removeContractMenuItem_Click(object sender, EventArgs e) { ContractItem manageritem = this.managersListView.SelectedItem; if (manageritem != null) { ManagerContract manager = manageritem.Contract as ManagerContract; ContractItem item = this.contractListView.SelectedItem; if (item != null) { if (Constants.LinuxMode) { item.StartWait(); manageritem.StartWait(); ThreadStack.Run(delegate(object[] param) { ManagerContract mc = param[0] as ManagerContract; ContractItem ctitem = param[1] as ContractItem; if (mc.RemoveContact(ctitem.Contract)) { mc.Contracts.Remove(ctitem.Contract); Utils.Invoke(this, delegate { this.contractListView.Items.Remove(ctitem); }); mc.WaitGramsChangedLoop(); } }, manager, item); } } } }
private void ChangeCode(ContractItem item) { if (Constants.LinuxMode) { if (item != null) { item.StartWait(); item.Contract.ChangeCode(); } } }
private void contractListView_MouseUp(object sender, MouseEventArgs e) { ContractItem item = this.contractListView.FocusedItem as ContractItem; bool enabled = item != null && item.Selected; bool created = item != null && item.Contract.IsCreated; this.sendGrammsContractMenuItem.Enabled = enabled && created; this.changeCodeContractMenuItem.Enabled = enabled && created; this.copyAddressContractMenuItem.Enabled = enabled && item != null && item.Contract.IsLoaded; this.removeContractMenuItem.Enabled = enabled && created; this.renameContractMenuItem.Enabled = enabled && created; }
private void sendCreateManagerMenuItem_Click(object sender, EventArgs e) { if (Constants.LinuxMode) { ContractItem manageritem = this.managersListView.SelectedItem; if (manageritem != null) { manageritem.StartWait(); manageritem.Contract.SendCreate(); manageritem.Contract.WaitGramsChanged(); } } }
private void sendGramsToMenuItem_Click(object sender, EventArgs e) { ContractItem manageritem = this.managersListView.SelectedItem; if (manageritem != null) { using (SendGramsToForm form = new SendGramsToForm(manageritem.Contract)) { if (form.ShowDialog(this) == DialogResult.OK) { string address = form.Address; if (!string.IsNullOrEmpty(address) && form.Grams > 0) { manageritem.StartWait(); manageritem.Contract.SendGram(address, form.Grams); manageritem.Contract.WaitGramsChanged(); } } } } }
private void createContractButton_Click(object sender, EventArgs e) { ContractItem manageritem = this.managersListView.SelectedItem; if (manageritem != null) { ManagerContract manager = manageritem.Contract as ManagerContract; using (CreateContractForm form = new CreateContractForm(Utils.GetNext("Messenger", this.contractListView.Items))) { if (form.ShowDialog(this) == DialogResult.OK) { Contract contract = Contract.Create(form.ContractName, form.ContractType, form.OwnerType); ContractItem item = new ContractItem(contract); this.contractListView.Items.Add(item); this.contractListView.SelectedItem = item; item.StartWait(); manageritem.StartWait(); if (Constants.LinuxMode) { ThreadStack.Run(delegate(object[] param) { ManagerContract mgr = param[0] as ManagerContract; Contract ct = param[1] as Contract; ClientExecutor.Instance.CreateContract(ct, param[2] as string); if (!item.IsWaitState) { item.StartWait(); } mgr.Contracts.Add(contract); ClientExecutor.Instance.InitContract(mgr, ct, (double)param[3]); manageritem.StartWait(); mgr.AddContract(ct); Utils.Invoke(this, this.OnManagersLoaded); }, manager, contract, form.WorkchainID, (double)form.Grams); } } } } }
private void Add(ManagerContract manager) { ContractItem item = new ContractItem(manager); this.managersListView.Items.Add(item); }