/// <summary> /// Function to Update values in Godown Table /// </summary> /// <param name="godowninfo"></param> public void GodownEdit(GodownInfo godowninfo) { try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("GodownEdit", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@godownId", SqlDbType.Decimal); sprmparam.Value = godowninfo.GodownId; sprmparam = sccmd.Parameters.Add("@godownName", SqlDbType.VarChar); sprmparam.Value = godowninfo.GodownName; sprmparam = sccmd.Parameters.Add("@narration", SqlDbType.VarChar); sprmparam.Value = godowninfo.Narration; sprmparam = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar); sprmparam.Value = godowninfo.Extra1; sprmparam = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar); sprmparam.Value = godowninfo.Extra2; sccmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sqlcon.Close(); } }
/// <summary> /// Function to save /// </summary> public void SaveFunction() { try { GodownInfo infoGodown = new GodownInfo(); GodownSP spGodown = new GodownSP(); infoGodown.GodownName = txtGodownName.Text.Trim(); infoGodown.Narration = txtNarration.Text.Trim(); infoGodown.Extra1 = string.Empty; infoGodown.Extra2 = string.Empty; if (spGodown.GodownCheckIfExist(txtGodownName.Text.Trim(), 0) == false) { decIdForOtherForms = spGodown.GodownAddWithoutSameName(infoGodown); RackAddCurrespondingtoGodown(); if (decIdForOtherForms > 0) { Messages.SavedMessage(); Clear(); } } else { Messages.InformationMessage("Godown name already exist"); txtGodownName.Focus(); } } catch (Exception ex) { formMDI.infoError.ErrorString = "G4:" + ex.Message; } }
/// <summary> /// Function to get the godownId by godownname /// </summary> /// <param name="strGodown"></param> /// <returns></returns> public GodownInfo GodownIdByGodownName(string strGodown) { GodownInfo godowninfo = new GodownInfo(); SqlDataReader sdrreader = null; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("GodownView", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@godownName", SqlDbType.VarChar); sprmparam.Value = strGodown; sdrreader = sccmd.ExecuteReader(); while (sdrreader.Read()) { godowninfo.GodownId = Convert.ToDecimal(sdrreader[0].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sdrreader.Close(); sqlcon.Close(); } return(godowninfo); }
/// <summary> /// Function to fill controls for update /// </summary> public void FillControls() { try { GodownInfo infoGodown = new GodownInfo(); GodownSP spGodown = new GodownSP(); infoGodown = spGodown.GodownWithNarrationView(Convert.ToDecimal(dgvGodown.CurrentRow.Cells[1].Value.ToString())); txtGodownName.Text = infoGodown.GodownName; txtNarration.Text = infoGodown.Narration; btnSave.Text = "Update"; btnDelete.Enabled = true; decGodownId = infoGodown.GodownId; strGodownName = infoGodown.GodownName; } catch (Exception ex) { formMDI.infoError.ErrorString = "G11:" + ex.Message; } }
/// <summary> /// Function to insert values to Godown Table with same name /// </summary> /// <param name="godowninfo"></param> /// <returns></returns> public decimal GodownAddWithoutSameName(GodownInfo godowninfo) { // bool isSave = false; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("GodownAddWithoutSameName", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@godownName", SqlDbType.VarChar); sprmparam.Value = godowninfo.GodownName; sprmparam = sccmd.Parameters.Add("@narration", SqlDbType.VarChar); sprmparam.Value = godowninfo.Narration; sprmparam = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar); sprmparam.Value = godowninfo.Extra1; sprmparam = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar); sprmparam.Value = godowninfo.Extra2; decimal decWork = Convert.ToDecimal(sccmd.ExecuteScalar()); if (decWork > 0) { return(decWork); } else { return(0); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(0); } finally { sqlcon.Close(); } }
/// <summary> /// Function to Update values in Godown Table /// </summary> /// <param name="godowninfo"></param> /// <returns></returns> public bool GodownEditParticularField(GodownInfo godowninfo) { bool isEdit = false; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("godownEditParticularField", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@godownId", SqlDbType.Decimal); sprmparam.Value = godowninfo.GodownId; sprmparam = sccmd.Parameters.Add("@godownName", SqlDbType.VarChar); sprmparam.Value = godowninfo.GodownName; sprmparam = sccmd.Parameters.Add("@narration", SqlDbType.VarChar); sprmparam.Value = godowninfo.Narration; int inAffectedRows = sccmd.ExecuteNonQuery(); if (inAffectedRows > 0) { isEdit = true; } else { isEdit = false; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sqlcon.Close(); } return(isEdit); }
/// <summary> /// Function to Edit /// </summary> public void EditFunction() { try { GodownInfo infoGodown = new GodownInfo(); GodownSP spGodown = new GodownSP(); infoGodown.GodownName = txtGodownName.Text.Trim(); infoGodown.Narration = txtNarration.Text.Trim(); infoGodown.Extra1 = string.Empty; infoGodown.Extra2 = string.Empty; infoGodown.GodownId = Convert.ToDecimal(dgvGodown.CurrentRow.Cells["dgvtxtGodownId"].Value.ToString()); if (txtGodownName.Text != strGodownName) { if (spGodown.GodownCheckIfExist(txtGodownName.Text.Trim(), decGodownId) == false) { if (spGodown.GodownEditParticularField(infoGodown)) { Messages.UpdatedMessage(); Clear(); } } else { Messages.InformationMessage("Godown name already exist"); txtGodownName.Focus(); } } else { spGodown.GodownEditParticularField(infoGodown); Messages.UpdatedMessage(); Clear(); } } catch (Exception ex) { formMDI.infoError.ErrorString = "G5:" + ex.Message; } }
/// <summary> /// Function to get particular values from Godown table based on the parameter /// </summary> /// <param name="godownId"></param> /// <returns></returns> public GodownInfo GodownView(decimal godownId) { GodownInfo godowninfo = new GodownInfo(); SqlDataReader sdrreader = null; try { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } SqlCommand sccmd = new SqlCommand("GodownView", sqlcon); sccmd.CommandType = CommandType.StoredProcedure; SqlParameter sprmparam = new SqlParameter(); sprmparam = sccmd.Parameters.Add("@godownId", SqlDbType.Decimal); sprmparam.Value = godownId; sdrreader = sccmd.ExecuteReader(); while (sdrreader.Read()) { godowninfo.GodownId = Convert.ToDecimal(sdrreader[0].ToString()); godowninfo.GodownName = sdrreader[1].ToString(); godowninfo.Narration = sdrreader[2].ToString(); godowninfo.ExtraDate = Convert.ToDateTime(sdrreader[3].ToString()); godowninfo.Extra1 = sdrreader[4].ToString(); godowninfo.Extra2 = sdrreader[5].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { sdrreader.Close(); sqlcon.Close(); } return(godowninfo); }