예제 #1
0
 public void PrintSheet(bool IsPrintPreview)
 {
     if (IsPrintPreview)
     {
         CurrSheet.PrintPreview();
     }
     else
     {
         CurrSheet.PrintOut(1, 1, 2, true);
     }
 }
예제 #2
0
 private void btnPrintStatement_Click(object sender, EventArgs e)
 {
     try {
         excelapp               = new Excel.Application();
         excelapp.Visible       = true;
         excelapp.DisplayAlerts = false;
         excelapp.Workbooks.Open(Application.StartupPath + @"\Template.xls");
         Excel._Worksheet workSheet = excelapp.ActiveSheet;
         workSheet.Cells[2, "C"]  = tBFullNameCustomer.Text;
         workSheet.Cells[3, "G"]  = tBHouse.Text;
         workSheet.Cells[3, "D"]  = cBStreet.SelectedItem.ToString().ToLower();
         workSheet.Cells[3, "E"]  = tBStreet.Text;
         workSheet.Cells[5, "A"]  = cBTypeOrder.SelectedIndex == 0 ? "№" + lID.Text + "ю" : "№" + lID.Text;
         workSheet.Cells[5, "H"]  = dateTimePicker1.Value.Date;
         workSheet.Cells[3, "H"]  = "№ " + comboBox1.SelectedItem.ToString();
         workSheet.Cells[3, "I"]  = tBApartment.Text;
         workSheet.Cells[64, "F"] = Properties.Settings.Default.Chief;
         workSheet.Cells[66, "F"] = tBFullNameImplementer.Text;
         workSheet.Cells[68, "F"] = tBFullNameCustomer.Text;
         MySqlDataReader CostRead;
         using (MySqlConnection mySqlCon = new MySqlConnection(connectionString))
         {
             mySqlCon.Open();
             MySqlCommand Cost = new MySqlCommand("SELECT TypeOfWork, Unit, Count, Rate, ParagraphID FROM cost WHERE OrderID=@OrderID", mySqlCon);
             Cost.Parameters.AddWithValue("OrderID", Convert.ToInt32(lID.Text));
             CostRead = Cost.ExecuteReader();
             int i = 7;
             while (CostRead.Read())
             {
                 workSheet.Cells[i, "A"] = CostRead.GetString("TypeOfWork");
                 workSheet.Cells[i, "F"] = CostRead.GetString("Unit");
                 workSheet.Cells[i, "G"] = CostRead.GetString("Count");
                 workSheet.Cells[i, "H"] = CostRead.GetDouble("Rate") * Convert.ToDouble(Properties.Settings.Default.Duty) * (int)nUPUrgency.Value;
                 workSheet.Cells[i, "J"] = CostRead.GetString("ParagraphID");
                 workSheet.Cells[i, "K"] = CostRead.GetString("Rate");
                 i++;
             }
             workSheet.Range["A" + i, "J61"].Rows.Hidden = true;
             workSheet.PrintPreview();
         }
     }
     finally
     {
         excelapp.Quit();
     }
 }