public bool AddPO(PO po) { bool result = false; try { Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name); connection = db.CreateConnection(); connection.Open(); transaction = connection.BeginTransaction(); DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_PO_Insert); db.AddInParameter(dbCommand, "@sPOCode", DbType.String, po.POCode); db.AddInParameter(dbCommand, "@mPOAmount", DbType.Currency, po.POAmount); db.AddInParameter(dbCommand, "@mBalanceAmount", DbType.Currency, po.BalanceAmount); db.AddInParameter(dbCommand, "@iPOCreatedUser", DbType.Int32, po.POCreatedUser); db.AddInParameter(dbCommand, "@iSupId", DbType.Int32, po.SupId); db.AddInParameter(dbCommand, "@dtPODate", DbType.DateTime, po.PODate); db.AddInParameter(dbCommand, "@iRequestedBy", DbType.Int32, po.RequestedBy.Value); db.AddInParameter(dbCommand, "@sPOComment", DbType.String, po.POComment); db.AddOutParameter(dbCommand, "@iPOId", DbType.Int32, 4); if (db.ExecuteNonQuery(dbCommand, transaction) > 0) { Int32 newPOID = (Int32)db.GetParameterValue(dbCommand, "@iPOId"); if (newPOID > 0) { po.POId = newPOID; if (this.UpdatePOItems(po, db, transaction)) { transaction.Commit(); result = true; } } } } catch (System.Exception ex) { ex.Data.Add("BusinessLayerException", GetType().ToString() + Constant.Error_Seperator + "public bool AddPO(PO po)"); transaction.Rollback(); throw ex; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } return result; }
protected void dxgvPODetails_BeforePerformDataSelect(object sender, EventArgs e) { try { if ((sender as ASPxGridView).GetMasterRowKeyValue() == null) { return; } Int32 POId = Int32.Parse((sender as ASPxGridView).GetMasterRowKeyValue().ToString()); PO tempPO = new PO(); tempPO.POId = POId; DataSet ds = new PODAO().GetPOItemsByPOID(tempPO); (sender as ASPxGridView).DataSource = ds; } catch (Exception ex) { ex.Data.Add("UILayerException", this.GetType().ToString() + Constant.Error_Seperator + "protected void dxgvPODetails_BeforePerformDataSelect(object sender, EventArgs e)"); if (Master.LoggedUser != null && Master.LoggedUser.UserName != null && Master.LoggedUser.UserName != string.Empty) Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, Master.LoggedUser.UserName), false); else Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, "Annonimous"), false); } }
//protected void btnAddGRN_Click(object sender, EventArgs e) //{ // try // { // ObjGRN.Rec_By = Master.LoggedUser.UserId; // ObjGRN.Rec_Date = dtpGRNDate.Date; // if (rblGRNType.SelectedValue == "1")//PO // { // ObjGRN.POId = Int32.Parse(ddlPOCode.SelectedValue.Trim() != "-1" ? ddlPOCode.SelectedValue.Trim() : "0"); // ObjGRN.InvId = null; // ObjGRN.CreditNote = String.Empty; // ObjGRN.SuplierInvNo = txtSupplierInvNo.Text.Trim(); // if (hdnOldInvNumber.Value.Trim() != txtSupplierInvNo.Text.Trim()) // { // if (true == new GRNDAO().IsSupplierInvNoExist(ObjGRN)) // { // lblError.Text = "Supplier Invoice Number Already exists!!"; // lblError.Visible = true; // return; // } // } // } // else if (rblGRNType.SelectedValue == "2")//Sales return // { // ObjGRN.POId = null; // ObjGRN.InvId = Int32.Parse(hdnInvoiceId.Value.Trim()); // ObjGRN.CreditNote = txtCreditNote.Text.Trim(); // ObjGRN.SuplierInvNo = String.Empty; // } // if (ObjGRN.Save()) // { // lblError.Visible = true; // lblError.Text = Constant.MSG_Save_SavedSeccessfully; // hdnPRId.Value = ObjGRN.GRNId.ToString(); // btnPrint.Visible = true; // btnSave.Enabled = false; // btnSave.CssClass = "show_success"; // } // else // { // btnPrint.Visible = false; // lblError.Visible = true; // lblError.Text = Constant.MSG_Save_NotSavedSeccessfully; // } // } // catch (Exception ex) // { // ex.Data.Add("UILayerException", this.GetType().ToString() + Constant.Error_Seperator + "protected void btnAddGRN_Click(object sender, EventArgs e)"); // if (Master.LoggedUser != null && Master.LoggedUser.UserName != null && Master.LoggedUser.UserName != string.Empty) // Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, Master.LoggedUser.UserName), false); // else // Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, "Annonimous"), false); // } //} protected void btnConfirm_Click(object sender, EventArgs e) { try { Session["ObjGRN"] = null; Int64 GRNId = 0; if (Int64.TryParse(txtGrnId.Text.Trim(), out GRNId)) { ObjGRN.GRNId = GRNId; ObjGRN.GetGRNByID(); if (ObjGRN.POId.HasValue) { lblGRNError.Visible = false; lblGRNError.Text = String.Empty; PO purchaseorder = new PO(); purchaseorder.POId = ObjGRN.POId.Value; purchaseorder.GetPOByID(); lblSupInvNo.Text = ObjGRN.SuplierInvNo; lblPOCode.Text = purchaseorder.POCode; lblSupplierName.Text = purchaseorder.SupplierName; ddlItemCode.DataSource = new PurchaseReturnsDAO().GetItemsToReturnByGRNId(GRNId); ddlItemCode.DataTextField = "ItemCode"; ddlItemCode.DataValueField = "GRNDetailsId"; ddlItemCode.DataBind(); ddlItemCode.Items.Add(new ListItem("--Please Select--", "-1")); ddlItemCode.SelectedValue = "-1"; } else { lblGRNError.Visible = true; lblGRNError.Text = "Incorrect PO GRN Id"; } } else { return; } } catch (Exception ex) { ex.Data.Add("UILayerException", this.GetType().ToString() + Constant.Error_Seperator + "protected void btnConfirm_Click(object sender, EventArgs e)"); if (Master.LoggedUser != null && Master.LoggedUser.UserName != null && Master.LoggedUser.UserName != string.Empty) Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, Master.LoggedUser.UserName), false); else Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, "Annonimous"), false); } }
public DataSet GetAllPartialyReceivedPOItemsByPOID(PO po) { try { Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name); DbCommand cmd = db.GetStoredProcCommand(Constant.SP_PO_SelPartialyReceivedPOItemsByPOID); db.AddInParameter(cmd, "@iPOId", DbType.Int32, po.POId); return db.ExecuteDataSet(cmd); } catch (System.Exception ex) { throw ex; return null; } }
private bool UpdatePOItems(PO po, Database db, DbTransaction transaction) { bool result = false; try { DbCommand insCommand = db.GetStoredProcCommand(Constant.SP_PO_InsPOItems); db.AddInParameter(insCommand, "@iPOId", DbType.Int32, po.POId); db.AddInParameter(insCommand, "@iItemId", DbType.Int32, "ItemId", DataRowVersion.Current); db.AddInParameter(insCommand, "@mPOItemCost", DbType.Currency, "POItemCost", DataRowVersion.Current); db.AddInParameter(insCommand, "@iQty", DbType.Int32, "Qty", DataRowVersion.Current); db.AddInParameter(insCommand, "@mLineCost", DbType.Currency, "LineCost", DataRowVersion.Current); db.AddInParameter(insCommand, "@dDiscountPerUnit", DbType.Decimal, "DiscountPerUnit", DataRowVersion.Current); DbCommand updCommand = db.GetStoredProcCommand(Constant.SP_PO_UpdPOItems); db.AddInParameter(updCommand, "@iPOId", DbType.Int32, po.POId); db.AddInParameter(updCommand, "@iItemId", DbType.Int32, "ItemId", DataRowVersion.Current); db.AddInParameter(updCommand, "@mPOItemCost", DbType.Currency, "POItemCost", DataRowVersion.Current); db.AddInParameter(updCommand, "@iQty", DbType.Int32, "Qty", DataRowVersion.Current); db.AddInParameter(updCommand, "@mLineCost", DbType.Currency, "LineCost", DataRowVersion.Current); db.AddInParameter(updCommand, "@dDiscountPerUnit", DbType.Decimal, "DiscountPerUnit", DataRowVersion.Current); db.AddInParameter(updCommand, "@biPOItemId", DbType.Int64, "POItemId", DataRowVersion.Current); DbCommand delCommand = db.GetStoredProcCommand(Constant.SP_PO_DelPOItems); db.AddInParameter(delCommand, "@biPOItemId", DbType.Int64, "POItemId", DataRowVersion.Current); db.UpdateDataSet(po.DsPOItems, po.DsPOItems.Tables[0].TableName, insCommand, updCommand, delCommand, transaction); result = true; } catch (System.Exception ex) { ex.Data.Add("BusinessLayerException", GetType().ToString() + Constant.Error_Seperator + "public bool AddUser()"); throw ex; } return result; }
public bool UpdatePOStatus(PO po) { bool result = false; try { Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name); DbCommand dbCommand = db.GetStoredProcCommand(Constant.SP_PO_UpdateStatus); db.AddInParameter(dbCommand, "@iPOId", DbType.Int32, po.POId); db.AddInParameter(dbCommand, "@iPOStatus", DbType.Int16, (Int16)po.POStatus); db.AddInParameter(dbCommand, "@sPOComment", DbType.String, po.POComment); if (db.ExecuteNonQuery(dbCommand) > 0) { result = true; } } catch (System.Exception ex) { ex.Data.Add("BusinessLayerException", GetType().ToString() + Constant.Error_Seperator + "public bool UpdatePOStatus(PO po)"); throw ex; } return result; }
public bool GetPOByID(PO po) { bool result = false; try { Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name); DbCommand cmd = db.GetStoredProcCommand(Constant.SP_PO_GetByID); db.AddInParameter(cmd, "@iPOId", DbType.Int32, po.POId); IDataReader reader = db.ExecuteReader(cmd); if (reader != null) { while (reader.Read()) { po.POId = reader["POId"] != DBNull.Value ? Convert.ToInt32(reader["POId"].ToString()) : 0; po.POCode = reader["POCode"].ToString(); po.POAmount = reader["POAmount"] != DBNull.Value ? Convert.ToDecimal(reader["POAmount"].ToString()) : Convert.ToDecimal("0"); po.BalanceAmount = reader["BalanceAmount"] != DBNull.Value ? Convert.ToDecimal(reader["BalanceAmount"].ToString()) : Convert.ToDecimal("0"); po.POCreatedUser = reader["POCreatedUser"] != DBNull.Value ? Convert.ToInt32(reader["POCreatedUser"].ToString()) : Convert.ToInt32("0"); po.POCreatedDate = reader["POCreatedDate"] != DBNull.Value ? Convert.ToDateTime(reader["POCreatedDate"].ToString()) : DateTime.MinValue; po.SupId = reader["SupId"] != DBNull.Value ? Convert.ToInt32(reader["SupId"].ToString()) : Convert.ToInt32("0"); po.POLastModifiedBy = reader["POLastModifiedBy"] != DBNull.Value ? Convert.ToInt32(reader["POLastModifiedBy"].ToString()) : Convert.ToInt32("0"); po.POLastModifiedDate = reader["POLastModifiedDate"] != DBNull.Value ? Convert.ToDateTime(reader["POLastModifiedDate"].ToString()) : DateTime.MinValue; po.IsReceived = reader["IsReceived"] != DBNull.Value ? Convert.ToBoolean(reader["IsReceived"].ToString()) : false; po.SupplierName = reader["SupplierName"] != DBNull.Value ? reader["SupplierName"].ToString() : String.Empty; if (reader["RequestedBy"] != DBNull.Value) { po.RequestedBy = Convert.ToInt32(reader["RequestedBy"].ToString()); } else { po.RequestedBy = null; } if (reader["PODate"]!=DBNull.Value) { po.PODate = Convert.ToDateTime(reader["PODate"].ToString()); } else { po.PODate = null; } po.POStatus = (Structures.POStatus)(reader["POStatus"] != DBNull.Value ? Convert.ToInt16(reader["POStatus"].ToString()) : Convert.ToInt16("1")); po.POComment = reader["POComment"] != DBNull.Value ? reader["POComment"].ToString() : String.Empty; result = true; } po.DsPOItems = this.GetPOItemsByPOID(po); } } catch (System.Exception ex) { throw ex; } return result; }
public bool GetPOByID(PO po) { bool result = false; try { Database db = DatabaseFactory.CreateDatabase(Constant.Database_Connection_Name); DbCommand cmd = db.GetStoredProcCommand(Constant.SP_PO_GetByID); db.AddInParameter(cmd, "@iPOId", DbType.Int32, po.POId); IDataReader reader = db.ExecuteReader(cmd); if (reader != null) { while (reader.Read()) { po.POId = reader["POId"] != DBNull.Value ? Convert.ToInt32(reader["POId"].ToString()) : 0; po.POCode = reader["POCode"].ToString(); po.POAmount = reader["POAmount"] != DBNull.Value ? Convert.ToDecimal(reader["POAmount"].ToString()) : Convert.ToDecimal("0"); po.BalanceAmount = reader["BalanceAmount"] != DBNull.Value ? Convert.ToDecimal(reader["BalanceAmount"].ToString()) : Convert.ToDecimal("0"); po.POCreatedUser = reader["POCreatedUser"] != DBNull.Value ? Convert.ToInt32(reader["POCreatedUser"].ToString()) : Convert.ToInt32("0"); po.POCreatedDate = reader["POCreatedDate"] != DBNull.Value ? Convert.ToDateTime(reader["POCreatedDate"].ToString()) : DateTime.MinValue; po.SupId = reader["SupId"] != DBNull.Value ? Convert.ToInt32(reader["SupId"].ToString()) : Convert.ToInt32("0"); po.POLastModifiedBy = reader["POLastModifiedBy"] != DBNull.Value ? Convert.ToInt32(reader["POLastModifiedBy"].ToString()) : Convert.ToInt32("0"); po.POLastModifiedDate = reader["POLastModifiedDate"] != DBNull.Value ? Convert.ToDateTime(reader["POLastModifiedDate"].ToString()) : DateTime.MinValue; po.IsReceived = reader["IsReceived"] != DBNull.Value ? Convert.ToBoolean(reader["IsReceived"].ToString()) : false; po.SupplierName = reader["SupplierName"] != DBNull.Value ? reader["SupplierName"].ToString() : String.Empty; if (reader["RequestedBy"] != DBNull.Value) { po.RequestedBy = Convert.ToInt32(reader["RequestedBy"].ToString()); } else { po.RequestedBy = null; } if (reader["PODate"] != DBNull.Value) { po.PODate = Convert.ToDateTime(reader["PODate"].ToString()); } else { po.PODate = null; } po.POStatus = (Structures.POStatus)(reader["POStatus"] != DBNull.Value ? Convert.ToInt16(reader["POStatus"].ToString()) : Convert.ToInt16("1")); po.POComment = reader["POComment"] != DBNull.Value ? reader["POComment"].ToString() : String.Empty; result = true; } po.DsPOItems = this.GetPOItemsByPOID(po); } } catch (System.Exception ex) { throw ex; } return(result); }
/// <summary> /// Load the data for GRN Edit / View /// </summary> private void SetData() { try { if (ObjGRN.POId.HasValue) { hdnGRNType.Value = "1";//PO used in client side lblGRNType.Text = "Purchase Order"; int poId = ObjGRN.POId.Value; PO po = new PO(); po.POId = poId; po.GetPOByID(); lblSupplierName.Text = po.SupplierName; } else if (ObjGRN.InvId.HasValue)//Sales return used in client side { hdnGRNType.Value = "2"; lblGRNType.Text = "Sales Return"; lblTitle.Text = "GRN - Credit Note"; } lblGRNNo.Text = ObjGRN.GRNId.ToString(); hdnPOId.Value = ObjGRN.POId.ToString().Trim(); lblPOCode.Text = ObjGRNPO.POCode; lblPOAmount.Text = Decimal.Round(ObjGRNPO.POAmount, 2).ToString(); lblDate.Text = ObjGRN.Rec_Date.ToString("dd-MMM-yyyy"); if (ObjGRN.GRNInvoice.InvoiceNo != null) { lblInvoiceNo.Text = ObjGRN.GRNInvoice.InvoiceNo.Trim(); Customer cust = new Customer(); cust.CustomerID = ObjGRN.GRNInvoice.CustomerID.Value; cust.GetCustomerByID(); lblCustomerName.Text = cust.Cus_Name; lblCustomerCode.Text = cust.CustomerCode; } else { lblInvoiceNo.Text = String.Empty; } lblInvoiceTotal.Text = Decimal.Round(ObjGRN.GRNInvoice.GrandTotal, 2).ToString(); txtCreditNote.InnerHtml = ObjGRN.CreditNote.Trim(); lblSupplierInvNo.Text = ObjGRN.SuplierInvNo.Trim(); lblReceivedTotal.Text = Decimal.Round(ObjGRN.TotalAmount, 2).ToString(); gvItemList.DataSource = ObjGRN.GRNItems; gvItemList.DataBind(); } catch (Exception ex) { throw ex; } }