public RESTStatus GetContractInfos(SQLLib sql, object dummy, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ChangeServerSettings) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } CI = new ContractInfosList(); CI.Items = new List <ContractInfos>(); if (Settings.Default.UseContract == false) { return(RESTStatus.Success); } lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("select * from contracts order by ContractID"); while (dr.Read()) { ContractInfos i = new ContractInfos(); i.IncludedComputers = new List <ComputerData>(); sql.LoadIntoClass(dr, i); CI.Items.Add(i); } dr.Close(); } foreach (ContractInfos i in CI.Items) { List <string> Machines = new List <string>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("select MachineID from ComputerAccounts where ContractID=@c", new SQLParam("@c", i.ContractID)); while (dr.Read()) { Machines.Add(Convert.ToString(dr["MachineID"])); } dr.Close(); } foreach (string M in Machines) { ComputerData c = Computers.GetComputerDetail(sql, M); i.IncludedComputers.Add(c); } } return(RESTStatus.Success); }
private void cmdOK_Click(object sender, EventArgs e) { if (lstMachines.SelectedIndex == 0 && lstContract.SelectedIndex == 0) { MessageBox.Show(this, "Please select one option.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (lstMachines.SelectedIndex != 0 && lstContract.SelectedIndex != 0) { MessageBox.Show(this, "Please select only one option.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } List <string> Machines = new List <string>(); if (lstMachines.SelectedIndex > 0) { Machines.Add((string)((KVP)lstMachines.SelectedItem).V); } if (lstContract.SelectedIndex > 0) { ContractInfos c = (ContractInfos)((KVP)lstContract.SelectedItem).V; if (c.IncludedComputers != null) { foreach (ComputerData cd in c.IncludedComputers) { Machines.Add(cd.MachineID); } } } SaveFileDialog save = new SaveFileDialog(); save.Title = "Save PDF Report"; save.CheckPathExists = true; save.OverwritePrompt = true; save.Filter = "PDF Files|*.pdf"; if (save.ShowDialog(this) != DialogResult.OK) { return; } byte[] pdf = Program.net.PaperGetMachineReport(Machines, chkFrom.Checked == false ? (DateTime?)null : DTFrom.Value, chkTo.Checked == false ? (DateTime?)null : DTTo.Value); if (pdf == null) { MessageBox.Show(this, "Error requesting report: " + Program.net.GetLastError(), Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } try { File.WriteAllBytes(save.FileName, pdf); } catch (Exception ee) { MessageBox.Show(this, "Error saving report: " + ee.Message, Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } this.Close(); }