private void BtnSave_Click(object sender, EventArgs e) { SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false); SplashScreenManager.Default.SetWaitFormDescription("Loading Data "); if (ValidateData()) { InfoGridView.CloseEditor(); InfoGridView.UpdateCurrentRow(); using (var sqlcon = new SqlConnection(ProjectFunctions.GetConnection())) { sqlcon.Open(); var sqlcom = sqlcon.CreateCommand(); var transaction = sqlcon.BeginTransaction("SaveTransaction"); sqlcom.Connection = sqlcon; sqlcom.Transaction = transaction; sqlcom.CommandType = CommandType.Text; try { if (S1 == "&Add") { txtPINo.Text = GetNewInvoiceDocumentNo().PadLeft(6, '0'); sqlcom.CommandText = "Insert into PIMstNew(PINo,PIDate,PIStoreCode)values(@PINo,@PIDate,@PIStoreCode)"; sqlcom.Parameters.AddWithValue("@PINo", txtPINo.Text.Trim()); sqlcom.Parameters.AddWithValue("@PIDate", Convert.ToDateTime(txtPIDate.Text)); sqlcom.Parameters.AddWithValue("@PIStoreCode", txtStoreCode.Text.Trim()); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } if (S1 == "Edit") { sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = "Update PIMstNew Set PIStoreCode=@PIStoreCode Where PINo = @PINo And PIDate=@PIDate "; sqlcom.Parameters.AddWithValue("@PINo", txtPINo.Text.Trim()); sqlcom.Parameters.AddWithValue("@PIDate", Convert.ToDateTime(txtPIDate.Text)); sqlcom.Parameters.AddWithValue("@PIStoreCode", txtStoreCode.Text.Trim()); sqlcom.Parameters.Clear(); sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = " Delete from PIDataNew Where PINo = @PINo And PIDate=@PIDate "; sqlcom.Parameters.AddWithValue("@PINo", txtPINo.Text.Trim()); sqlcom.Parameters.AddWithValue("@PIDate", Convert.ToDateTime(txtPIDate.Text)); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } SplashScreenManager.Default.SetWaitFormDescription("Saving Data "); //foreach (DataRow dr in dt.Rows) //{ // sqlcom.CommandType = CommandType.Text; // sqlcom.CommandText = " Insert into PIDataNew" // + " (PINo,PIDate,PIQty,EANNo)" // + " values(@PINo,@PIDate,@PIQty,@EANNo)"; // sqlcom.Parameters.AddWithValue("@PINo", txtPINo.Text.Trim()); // sqlcom.Parameters.AddWithValue("@PIDate", Convert.ToDateTime(txtPIDate.Text)); // sqlcom.Parameters.AddWithValue("@PIQty", Convert.ToDecimal(dr["PIQty"])); // sqlcom.Parameters.AddWithValue("@EANNo", dr["EANNo"].ToString()); // sqlcom.ExecuteNonQuery(); // sqlcom.Parameters.Clear(); //} DataTable dtFinal = new DataTable(); dtFinal.Columns.Add("PINo", typeof(string)); dtFinal.Columns.Add("PIDate", typeof(string)); dtFinal.Columns.Add("PIQty", typeof(string)); dtFinal.Columns.Add("EANNo", typeof(string)); dtFinal.Rows.Clear(); foreach (DataRow dr in (InfoGrid.DataSource as DataTable).Rows) { DataRow drRow = dtFinal.NewRow(); drRow["PINo"] = txtPINo.Text.Trim(); drRow["PIDate"] = Convert.ToDateTime(txtPIDate.Text).ToString("yyyy-MM-dd"); drRow["PIQty"] = dr["PIQty"].ToString(); drRow["EANNo"] = dr["EANNo"].ToString(); dtFinal.Rows.Add(drRow); } dtFinal.AcceptChanges(); sqlcom.CommandType = CommandType.StoredProcedure; sqlcom.CommandText = "sp_InsertPINew"; sqlcom.CommandTimeout = 600000; SqlParameter param = new SqlParameter { ParameterName = "@PerformaInv", Value = dtFinal }; sqlcom.Parameters.Add(param); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); transaction.Commit(); //ProjectFunctions.SpeakError("PI Data Saved Successfully"); sqlcon.Close(); if (FromExcel == "Y") { // SplashScreenManager.Default.SetWaitFormDescription("Saving PI " + i.ToString()); i++; LoadSheet(); DevExpress.Spreadsheet.Workbook workbook = new DevExpress.Spreadsheet.Workbook(); workbook.LoadDocument(openFileDialog1.FileName); DevExpress.Spreadsheet.Worksheet worksheet = workbook.Worksheets[i]; if (i <= workbook.Sheets.Count) { BtnSave_Click(null, e); } else { SplashScreenManager.CloseForm(false); Close(); } } else { SplashScreenManager.CloseForm(false); } Close(); FromExcel = "N"; } catch (Exception ex) { ProjectFunctions.SpeakError("Something Wrong. \n I am going to Roll Back." + ex.Message); try { transaction.Rollback(); } catch (Exception ex2) { ProjectFunctions.SpeakError("Something Wrong. \n Roll Back Failed." + ex2.Message); } } } } }
private void InfoGridView_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { InfoGridView.CloseEditor(); InfoGridView.UpdateCurrentRow(); }
private void BtnSaveNew_Click(object sender, EventArgs e) { if (ValidateData()) { S1 = "&Add"; AddRowsToDatatable(); InfoGridView.CloseEditor(); InfoGridView.UpdateCurrentRow(); using (var sqlcon = new SqlConnection(ProjectFunctions.GetConnection())) { sqlcon.Open(); var sqlcom = sqlcon.CreateCommand(); var transaction = sqlcon.BeginTransaction("SaveTransaction"); sqlcom.Connection = sqlcon; sqlcom.Transaction = transaction; sqlcom.CommandType = CommandType.Text; try { if (S1 == "&Add") { txtPINo.Text = GetNewInvoiceDocumentNo().PadLeft(6, '0'); sqlcom.CommandText = "Insert into PIMst(PINo,PIDate,PIPartyCode,PITaxableAmount,PITaxAmount,PITotalAmount)values(@PINo,@PIDate,@PIPartyCode,@PITaxableAmount,@PITaxAmount,@PITotalAmount)"; sqlcom.Parameters.AddWithValue("@PINo", txtPINo.Text.Trim()); sqlcom.Parameters.AddWithValue("@PIDate", Convert.ToDateTime(txtPIDate.Text)); sqlcom.Parameters.AddWithValue("@PIPartyCode", txtAccCode.Text.Trim()); sqlcom.Parameters.AddWithValue("@PITaxableAmount", "0"); sqlcom.Parameters.AddWithValue("@PITaxAmount", "0"); sqlcom.Parameters.AddWithValue("@PITotalAmount", "0"); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } foreach (DataRow dr in dtAll.Rows) { sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = " Insert into PIData" + " (PINo,PIDate,PIBrand,PIEANNo,PIArticle,PIHSNCode,PIQyt,PIMrp,PTTaxPer,PICoreFashion,Season)" + " values(@PINo,@PIDate,@PIBrand,@PIEANNo,@PIArticle,@PIHSNCode,@PIQyt,@PIMrp,@PTTaxPer,@PICoreFashion,@Season)"; sqlcom.Parameters.AddWithValue("@PINo", txtPINo.Text.Trim()); sqlcom.Parameters.AddWithValue("@PIDate", Convert.ToDateTime(txtPIDate.Text)); sqlcom.Parameters.AddWithValue("@PIBrand", dr["PIBrand"].ToString()); sqlcom.Parameters.AddWithValue("@PIEANNo", dr["PIEANNo"].ToString()); sqlcom.Parameters.AddWithValue("@PIArticle", dr["PIArticle"].ToString()); sqlcom.Parameters.AddWithValue("@PIHSNCode", dr["PIHSNCode"].ToString()); sqlcom.Parameters.AddWithValue("@PIQyt", Convert.ToDecimal(dr["PIQyt"])); sqlcom.Parameters.AddWithValue("@PIMrp", Convert.ToDecimal(dr["PIMrp"])); sqlcom.Parameters.AddWithValue("@PTTaxPer", Convert.ToDecimal(dr["PTTaxPer"])); sqlcom.Parameters.AddWithValue("@PICoreFashion", dr["PICoreFashion"].ToString()); sqlcom.Parameters.AddWithValue("@Season", dr["Season"].ToString()); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } transaction.Commit(); ProjectFunctions.SpeakError("PI Data Saved Successfully"); sqlcon.Close(); Close(); } catch (Exception ex) { ProjectFunctions.SpeakError("Something Wrong. \n I am going to Roll Back." + ex.Message); try { transaction.Rollback(); } catch (Exception ex2) { ProjectFunctions.SpeakError("Something Wrong. \n Roll Back Failed." + ex2.Message); } } } } }
private void InfoGridView_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e) { InfoGridView.CloseEditor(); InfoGridView.UpdateCurrentRow(); }
private void BtnSave_Click(object sender, EventArgs e) { if (ValidateData()) { InfoGridView.CloseEditor(); InfoGridView.UpdateCurrentRow(); using (var sqlcon = new SqlConnection(ProjectFunctions.GetConnection())) { sqlcon.Open(); var sqlcom = sqlcon.CreateCommand(); var transaction = sqlcon.BeginTransaction("SaveTransaction"); sqlcom.Connection = sqlcon; sqlcom.Transaction = transaction; sqlcom.CommandType = CommandType.StoredProcedure; try { sqlcom.CommandText = "sp_InsertOrderMst"; sqlcom.Parameters.AddWithValue("@OrdNo", txtOrderNo.Text.Trim()); sqlcom.Parameters["@OrdNo"].Direction = ParameterDirection.InputOutput; sqlcom.Parameters.AddWithValue("@OrdDate", Convert.ToDateTime(dtOrderDate.Text).ToString("yyyy-MM-dd")); sqlcom.Parameters.AddWithValue("@OrdForDate", Convert.ToDateTime(dtOrderForDate.Text).ToString("yyyy-MM-dd")); sqlcom.Parameters.AddWithValue("@OrdDealerCode", txtDealerCode.Text.Trim()); if (S1 == "&Add") { sqlcom.Parameters.AddWithValue("@Tag", "&Add"); } else { sqlcom.Parameters.AddWithValue("@Tag", "Edit"); } sqlcom.ExecuteNonQuery(); txtOrderNo.Text = sqlcom.Parameters["@OrdNo"].Value.ToString(); sqlcom.Parameters.Clear(); if (S1 == "Edit") { sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = " Delete from DealerOrderData Where OrdDNo = @OrdDNo "; sqlcom.Parameters.AddWithValue("@OrdDNo", txtOrderNo.Text.Trim()); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } #pragma warning disable CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.' for (var i = 0; i < ((InfoGrid.KeyboardFocusView as GridView).RowCount); i++) #pragma warning restore CS0618 // 'GridControl.KeyboardFocusView' is obsolete: 'Use the FocusedView property instead.' { sqlcom.CommandType = CommandType.Text; var currentrow = InfoGridView.GetDataRow(i); if (Convert.ToDecimal(currentrow["OrdDPrdQuantity"]) > 0) { sqlcom.CommandText = " Insert into DealerOrderData" + " (OrdDNo,OrdDDate,OrdDDealerCode,OrdDPrdCode,OrdDPrdQuantity,OrdDForDate)" + " values(@OrdDNo,@OrdDDate,@OrdDDealerCode,@OrdDPrdCode,@OrdDPrdQuantity,@OrdDForDate)"; sqlcom.Parameters.AddWithValue("@OrdDNo", txtOrderNo.Text.Trim()); sqlcom.Parameters.AddWithValue("@OrdDDate", Convert.ToDateTime(dtOrderDate.Text).ToString("yyyy-MM-dd")); sqlcom.Parameters.AddWithValue("@OrdDDealerCode", txtDealerCode.Text.Trim()); sqlcom.Parameters.AddWithValue("@OrdDPrdCode", Convert.ToDecimal(currentrow["OrdDPrdCode"])); sqlcom.Parameters.AddWithValue("@OrdDPrdQuantity", Convert.ToDecimal(currentrow["OrdDPrdQuantity"])); sqlcom.Parameters.AddWithValue("@OrdDForDate", Convert.ToDateTime(dtOrderForDate.Text).ToString("yyyy-MM-dd")); sqlcom.ExecuteNonQuery(); sqlcom.Parameters.Clear(); } } transaction.Commit(); ProjectFunctions.SpeakError("Order Data Saved Successfully"); sqlcon.Close(); if (S1 == "&Add") { txtDealerCode.Text = string.Empty; txtDealerName.Text = string.Empty; FrmDealerOrderMaster_Load(null, e); } else { Close(); } } catch (Exception ex) { ProjectFunctions.SpeakError("Something Wrong. \n I am going to Roll Back." + ex.Message); try { transaction.Rollback(); } catch (Exception ex2) { ProjectFunctions.SpeakError("Something Wrong. \n Roll Back Failed." + ex2.Message); } } } } }