private void BindMaxNo(string Matfrom, Int32 LocationId, Int32 YearId) { TyreIssueDAL obj = new TyreIssueDAL(); Int64 MaxNo = obj.MaxNo(Matfrom, YearId, LocationId, ApplicationFunction.ConnectionString()); txtGRNo.Text = Convert.ToString(MaxNo); }
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { #region fill values to Variables TyreIssueDAL objGrprepDAL = new TyreIssueDAL(); dtTemp = (DataTable)ViewState["dt"]; //AcntDS = objGrprepDAL.DtAcntDS(ApplicationFunction.ConnectionString()); //DsTrAcnt = objGrprepDAL.DsTrAcnt(ApplicationFunction.ConnectionString()); #endregion #region Validation Messages //if (ddlReciver.SelectedIndex == 0) { this.ShowMessageErr("Please select Receiver's Name."); ddlReciver.Focus(); lblmessage.Visible = true; lblmessage.Text = "* Please select Receiver's Name."; return; } if (ddlLocation.SelectedIndex == 0) { this.ShowMessageErr("Please select Delivery Place."); ddlLocation.Focus(); lblmessage.Visible = true; lblmessage.Text = "* Please select Delivery Place."; return; } if ((dtTemp != null) && (dtTemp.Rows.Count == 0)) { this.ShowMessageErr("Please enter Item Details ."); return; } #endregion //txtGrNo=txtIssueNo #region Declare Input Variables string strMsg = string.Empty; Int64 intMaterialIdno = 0; DateTime strMatDate = Convert.ToDateTime(ApplicationFunction.mmddyyyy(txtGRDate.Text.Trim().ToString())); DateTime dtMatDate = strMatDate; Int32 IAgainst = Convert.ToInt32(1); Int32 YearIdno = Convert.ToInt32(ddlDateRange.SelectedValue) == -1 ? 0 : Convert.ToInt32(ddlDateRange.SelectedValue); Int64 intMatNo = string.IsNullOrEmpty(txtGRNo.Text.Trim()) ? 0 : Convert.ToInt64(txtGRNo.Text.Trim()); Int32 TruckNoIdno = string.IsNullOrEmpty(ddlTruckNo.SelectedValue) ? 0 : Convert.ToInt32(ddlTruckNo.SelectedValue); Int32 intIssueIDno = string.IsNullOrEmpty(ddlReciver.SelectedValue) ? 0 : Convert.ToInt32(ddlReciver.SelectedValue); Int32 intLoc_Id = string.IsNullOrEmpty(ddlLocation.SelectedValue) ? 0 : Convert.ToInt32(ddlLocation.SelectedValue); Int64 intDriver_Id = string.IsNullOrEmpty(ddlDriver.SelectedValue) ? 0 : Convert.ToInt32(ddlDriver.SelectedValue); //new string strRemarkhead = txtRemarkhead.Text.Trim(); string strNetAmnt = (Convert.ToString(txtNetAmnt.Text)).Replace(",", ""); Double DNetAmnt = string.IsNullOrEmpty(strNetAmnt) ? 0 : Convert.ToDouble(strNetAmnt); DataTable dtDetail = (DataTable)ViewState["dt"]; #endregion #region Insert/Update with Transaction using (TransactionScope tScope = new TransactionScope(TransactionScopeOption.Required)) { if (grdMain.Rows.Count > 0 && dtTemp != null && dtTemp.Rows.Count > 0) { TyreIssueDAL objMat = new TyreIssueDAL(); string Matfrom = "BK"; Int64 MaxIssueNo = 0; Int64 GrIdnos = Convert.ToInt64(Convert.ToString(hidGRHeadIdno.Value) == "" ? 0 : Convert.ToInt64(hidGRHeadIdno.Value)); MaxIssueNo = objMat.MaxNo(Matfrom, Convert.ToInt32(ddlDateRange.SelectedValue), Convert.ToInt32(Convert.ToString(ddlLocation.SelectedValue) == "" ? 0 : Convert.ToInt32(ddlLocation.SelectedValue)), ApplicationFunction.ConnectionString()); if (Convert.ToString(hidGRHeadIdno.Value) == "") { if ((txtGRNo.Text.Trim() != "") && (Convert.ToInt64(txtGRNo.Text.Trim()) > 0)) { var lst = objMat.CheckDuplicateGrNo(Convert.ToInt64(txtGRNo.Text.Trim()), Convert.ToInt64(Convert.ToString(ddlLocation.SelectedValue) == "" ? 0 : Convert.ToInt64(ddlLocation.SelectedValue)), Convert.ToInt64(ddlDateRange.SelectedValue)); if (lst.Count > 0) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmsg1", "ShowConfirmAtSave()", true); return; } //if ((txtGRNo.Text != Convert.ToString(MaxGRNo)) && (GrIdnos != Convert.ToInt32(txtGRNo.Text))) //{ // ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmsg1", "ShowConfirm()", true); //} } else { this.ShowMessageErr("Issue No. can't be left blank."); txtGRNo.Text = Convert.ToString(MaxIssueNo); txtGRNo.Focus(); txtGRNo.SelectText(); return; } } TyreIssueDAL obj = new TyreIssueDAL(); if (Convert.ToString(hidGRHeadIdno.Value) != "") { intMaterialIdno = obj.MatUpdate(Convert.ToInt64(hidGRHeadIdno.Value), dtMatDate, IAgainst, intMatNo, intLoc_Id, TruckNoIdno, DNetAmnt, YearIdno, dtDetail, intIssueIDno, strRemarkhead, intDriver_Id); } else { intMaterialIdno = obj.InsertMat(dtMatDate, IAgainst, intMatNo, intLoc_Id, TruckNoIdno, DNetAmnt, YearIdno, dtDetail, intIssueIDno, strRemarkhead, intDriver_Id); } obj = null; if (intMaterialIdno > 0) { if (Convert.ToString(hidGRHeadIdno.Value) != null && Convert.ToString(hidGRHeadIdno.Value) != "") { this.ShowMessage("Record updated successfully."); } else { this.ShowMessage("Record saved successfully."); } //ddlLocation_SelectedIndexChanged(null, null); //ddlFromCity_SelectedIndexChanged(null, null); this.ClearAll(); ViewState["dt"] = dtTemp = null; this.BindGridT(); ddlDateRange.Focus(); tScope.Complete(); //kapil // Response.Redirect("MaterialIssue.aspx"); } else { if (string.IsNullOrEmpty(Convert.ToString(hidGRHeadIdno.Value)) == false) { hidpostingmsg.Value = "Record(s) not updated."; } else { hidpostingmsg.Value = "Record(s) not saved."; } tScope.Dispose(); //tScope.Dispose(); //ScriptManager.RegisterStartupScript(this, this.GetType(), "hwa", "PassMessageError('" + Convert.ToString(hidpostingmsg.Value) + "')", true); //return; } } else if (intMaterialIdno < 0) { //this.ShowMessageErr("Entry already made with this GR. No."); if (txtGRNo.Text != "") { // checkGRNoAtSave = true; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmsg1", "ShowConfirmAtSave()", true); } } else { if (Convert.ToString(hidGRHeadIdno.Value) != null && Convert.ToString(hidGRHeadIdno.Value) != "") { this.ShowMessageErr("Record not updated."); } else { this.ShowMessageErr("Record not saved."); } } } Int64 iMaxGRNo = 0; TyreIssueDAL objGRDAL = new TyreIssueDAL(); iMaxGRNo = objGRDAL.MaxNo("BK", Convert.ToInt32(ddlDateRange.SelectedValue), Convert.ToInt32(Convert.ToString(ddlLocation.SelectedValue) == "" ? 0 : Convert.ToInt32(ddlLocation.SelectedValue)), ApplicationFunction.ConnectionString()); txtGRNo.Text = Convert.ToString(iMaxGRNo); //ddlGRType.Focus(); #endregion }