private void allOrderListDataGrid_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { try { DialogResult dr = MessageBox.Show("Seçili satır için rapor yazdırmak istiyor musunuz?", "Uyarı", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr == DialogResult.Cancel) { return; } cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "ab_listOrder"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@orderId", allOrderListDataGrid.CurrentRow.Cells[0].Value); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); List <OrderDetail> orderDetailList = new List <OrderDetail>(); Orders orders = new Orders(); for (int i = 0; i < dt.Rows.Count; i++) { OrderDetail ordDetail = new OrderDetail(); ordDetail.productId = Convert.ToInt32(dt.Rows[i]["productId"]); ordDetail.productName = dt.Rows[i]["productName"].ToString(); ordDetail.mainProductName = dt.Rows[i]["mainProductName"].ToString(); ordDetail.quantity = Convert.ToInt32(dt.Rows[i]["quantity"]); orderDetailList.Add(ordDetail); } orders.orderId = Int32.Parse(allOrderListDataGrid.CurrentRow.Cells[0].Value.ToString()); orders.orderBy = allOrderListDataGrid.CurrentRow.Cells[1].Value.ToString(); orders.orderAdress = allOrderListDataGrid.CurrentRow.Cells[4].Value.ToString(); orders.orderDate = allOrderListDataGrid.CurrentRow.Cells[2].Value.ToString(); orders.orderPrice = Int32.Parse(allOrderListDataGrid.CurrentRow.Cells[3].Value.ToString()); orders.orderExplaination = allOrderListDataGrid.CurrentRow.Cells[6].Value.ToString(); orders.orderSite = allOrderListDataGrid.CurrentRow.Cells[5].Value.ToString(); rptOrder rpo = new rptOrder(); rpo.Database.Tables["productDataTable"].SetDataSource(dt); ReportForm pdf = new ReportForm(orderDetailList, orders); pdf.ShowDialog(); } catch (Exception Error) { MessageBox.Show(Error.ToString()); } }
private void saveOrder_Click(object sender, EventArgs e) { try { if (con.State == ConnectionState.Closed) { con.Open(); } bool report = false; DialogResult dr = MessageBox.Show("İşlem sonucunda rapor istiyor musunuz?", "Uyarı", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (dr == DialogResult.Cancel) { return; } else if (dr == DialogResult.Yes) { report = true; } cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "ab_addOrder"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@orderBy", orderBy.Text.ToString()); cmd.Parameters.AddWithValue("@orderDate", orderDate.Value); cmd.Parameters.AddWithValue("@orderPrice", Int32.Parse(orderPrice.Text.ToString())); cmd.Parameters.AddWithValue("@orderAdress", orderAdress.Text.ToString()); cmd.Parameters.AddWithValue("@orderExplanation", orderExplanation.Text.ToString()); cmd.Parameters.AddWithValue("@orderSite", siteList.selectedValue.ToString()); cmd.Parameters.Add("@orderId", SqlDbType.Int).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); int orderId = Convert.ToInt32(cmd.Parameters["@orderId"].Value); foreach (ListViewItem itemList in orderList.Items) { cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "ab_addOrderProduct"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@orderId", orderId); cmd.Parameters.AddWithValue("@productId", Int32.Parse(itemList.SubItems[0].Text.ToString())); cmd.Parameters.AddWithValue("@quantity", Int32.Parse(itemList.SubItems[2].Text.ToString())); cmd.ExecuteNonQuery(); cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "ab_decProductStock"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@productId", Int32.Parse(itemList.SubItems[0].Text.ToString())); cmd.Parameters.AddWithValue("@productQuantity", Int32.Parse(itemList.SubItems[2].Text.ToString())); cmd.ExecuteNonQuery(); } MessageBox.Show("İşlem başarıyla tamamlandı. Sipariş Numarası : " + orderId.ToString()); productGrid.Rows.Clear(); if (report) { cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "ab_listOrder"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@orderId", orderId); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); List <OrderDetail> orderDetailList = new List <OrderDetail>(); Orders orders = new Orders(); for (int i = 0; i < dt.Rows.Count; i++) { OrderDetail ordDetail = new OrderDetail(); ordDetail.productId = Convert.ToInt32(dt.Rows[i]["productId"]); ordDetail.productName = dt.Rows[i]["productName"].ToString(); ordDetail.mainProductName = dt.Rows[i]["mainProductName"].ToString(); ordDetail.quantity = Convert.ToInt32(dt.Rows[i]["quantity"]); orderDetailList.Add(ordDetail); } orders.orderId = orderId; orders.orderBy = orderBy.Text.ToString(); orders.orderAdress = orderAdress.Text.ToString(); orders.orderDate = orderDate.Value.ToString(); orders.orderPrice = Int32.Parse(orderPrice.Text.ToString()); orders.orderExplaination = orderExplanation.Text.ToString(); orders.orderSite = siteList.selectedValue.ToString(); rptOrder rpo = new rptOrder(); rpo.Database.Tables["productDataTable"].SetDataSource(dt); ReportForm pdf = new ReportForm(orderDetailList, orders); pdf.ShowDialog(); } } catch (Exception error) { MessageBox.Show(error.ToString()); } }