/// <summary> /// On doubleclicking on the grid, It displays the details to edit or delete a rack /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvRack_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex != -1) { if (dgvRack.Rows[e.RowIndex].Cells["dgvtxtRackName"].Value.ToString() != "NA") { RackSP spRack = new RackSP(); RackInfo infoRack = new RackInfo(); decRackId = Convert.ToDecimal(dgvRack.Rows[e.RowIndex].Cells["dgvtxtRackId"].Value.ToString()); infoRack = spRack.RackView(decRackId); txtRackName.Text = infoRack.RackName; cmbGodown.SelectedValue = infoRack.GodownId.ToString(); txtNarration.Text = infoRack.Narration; btnSave.Text = "Update"; btnDelete.Enabled = true; strRackName = infoRack.RackName; txtRackName.Focus(); } else { Messages.InformationMessage("Default Rack cannot update or delete"); Clear(); } } } catch (Exception ex) { MessageBox.Show("R19:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to save new rack /// </summary> public void SaveFunction() { try { RackSP spRack = new RackSP(); RackInfo rackInfo = new RackInfo(); rackInfo.RackName = txtRackName.Text.Trim(); rackInfo.GodownId = Convert.ToDecimal(cmbGodown.SelectedValue.ToString()); rackInfo.Narration = txtNarration.Text.Trim(); rackInfo.ExtraDate = DateTime.Now; rackInfo.Extra1 = string.Empty; rackInfo.Extra2 = string.Empty; decimal decGodounId = Convert.ToDecimal(cmbGodown.SelectedValue.ToString()); if (spRack.RackCheckExistence(txtRackName.Text.Trim(), 0, decGodounId) == false) { decIdForOtherForms = spRack.RackAdd(rackInfo); if (decIdForOtherForms > 0) { Messages.SavedMessage(); Clear(); } } else { Messages.InformationMessage(" Rack name already exist"); txtRackName.Focus(); } } catch (Exception ex) { MessageBox.Show("R7:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to edit the existing rack /// </summary> public void EditFunction() { try { RackSP spRack = new RackSP(); RackInfo rackInfo = new RackInfo(); rackInfo.RackName = txtRackName.Text.Trim(); rackInfo.GodownId = Convert.ToDecimal(cmbGodown.SelectedValue.ToString()); rackInfo.Narration = txtNarration.Text.Trim(); rackInfo.ExtraDate = DateTime.Now; rackInfo.Extra1 = string.Empty; rackInfo.Extra2 = string.Empty; rackInfo.RackId = decRackId; if (txtRackName.Text != strRackName) { if (CheckExistenceOfRackName() == false) { if (spRack.RackEdit(rackInfo)) { Messages.UpdatedMessage(); Clear(); } } else { Messages.InformationMessage("Already exists"); txtRackName.Focus(); } } else if (rackInfo.RackId == 1) { Messages.InformationMessage("Cannot update"); Clear(); txtRackName.Focus(); } else { if (spRack.RackEdit(rackInfo)) { Messages.UpdatedMessage(); Clear(); } } } catch (Exception ex) { MessageBox.Show("R8:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to Update values in Rack Table /// </summary> /// <param name="rackinfo"></param> /// <returns></returns> public bool RackEdit(RackInfo rackinfo) { try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("RackEdit", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@rackId", SqlDbType.Decimal); sprmparam.Value = rackinfo.RackId; sprmparam = sccmd.Parameters.Add("@rackName", SqlDbType.VarChar); sprmparam.Value = rackinfo.RackName; sprmparam = sccmd.Parameters.Add("@godownId", SqlDbType.Decimal); sprmparam.Value = rackinfo.GodownId; sprmparam = sccmd.Parameters.Add("@narration", SqlDbType.VarChar); sprmparam.Value = rackinfo.Narration; sprmparam = sccmd.Parameters.Add("@extraDate", SqlDbType.DateTime); sprmparam.Value = rackinfo.ExtraDate; sprmparam = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar); sprmparam.Value = rackinfo.Extra1; sprmparam = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar); sprmparam.Value = rackinfo.Extra2; int inEffectedRow = sccmd.ExecuteNonQuery(); if (inEffectedRow > 0) { return(true); } else { return(false); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(false); } finally { sqlcon.Close(); } }
/// <summary> /// Function to Save Rack /// </summary> public void RackAddCurrespondingtoGodown() { try { RackSP spRack = new RackSP(); RackInfo infoRack = new RackInfo(); infoRack.RackName = "NA"; infoRack.GodownId = decIdForOtherForms; infoRack.Narration = string.Empty; infoRack.Extra1 = string.Empty; infoRack.Extra2 = string.Empty; infoRack.ExtraDate = DateTime.Now; spRack.RackAdd(infoRack); } catch (Exception ex) { MessageBox.Show("G3:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Function to get particular values from Rack Table based on the parameter /// </summary> /// <param name="rackId"></param> /// <returns></returns> public RackInfo RackView(decimal rackId) { RackInfo rackinfo = new RackInfo(); SqlDataReader sdrreader = null; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("RackView", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@rackId", SqlDbType.Decimal); sprmparam.Value = rackId; sdrreader = sccmd.ExecuteReader(); while (sdrreader.Read()) { rackinfo.RackId = decimal.Parse(sdrreader[0].ToString()); rackinfo.RackName = sdrreader[1].ToString(); rackinfo.GodownId = decimal.Parse(sdrreader[2].ToString()); rackinfo.Narration = sdrreader[3].ToString(); rackinfo.Extra1 = sdrreader[4].ToString(); rackinfo.Extra2 = sdrreader[5].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sdrreader.Close(); sqlcon.Close(); } return(rackinfo); }