Пример #1
0
            public CResult Update(CGRMaster oMaster, Dictionary <string, CGRDetails> oGRFinalQtyDic)
            {
                List <CInventory> oInvtList = new List <CInventory>();

                oResult = new CResult();
                conn    = oConnManager.GetConnection(out s_DBError);
                if (conn != null)
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.Parameters.Clear();

                    cmd.Transaction = oConnManager.BeginTransaction();
                    try
                    {
                        cmd.CommandText = "sp_GRMaster_Update";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Clear();

                        cmd.Parameters.AddWithValue("@GRMstr_OID", oMaster.GRMstr_OID);
                        cmd.Parameters.AddWithValue("@GRMstr_Branch", oMaster.GRMstr_Branch);
                        cmd.Parameters.AddWithValue("@GRMstr_Code", oMaster.GRMstr_Code);
                        cmd.Parameters.AddWithValue("@GRMstr_Date", oMaster.GRMstr_Date);
                        cmd.Parameters.AddWithValue("@GRMstr_Type", oMaster.GRMstr_Type);
                        cmd.Parameters.AddWithValue("@GRMstr_By", oMaster.GRMstr_By);
                        cmd.Parameters.AddWithValue("@GRMstr_RefBy", oMaster.GRMstr_RefBy);
                        cmd.Parameters.AddWithValue("@GRMstr_VendorID", oMaster.GRMstr_VendorID);
                        cmd.Parameters.AddWithValue("@GRMstr_TotalAmt", oMaster.GRMstr_TotalAmt);

                        cmd.Parameters.AddWithValue("@Creator", oMaster.Creator);
                        cmd.Parameters.AddWithValue("@CreationDate", oMaster.CreationDate);
                        cmd.Parameters.AddWithValue("@UpdateBy", oMaster.UpdateBy);
                        cmd.Parameters.AddWithValue("@UpdateDate", oMaster.UpdateDate);
                        cmd.Parameters.AddWithValue("@IsActive", (oMaster.IsActive == "Y") ? 1 : 0);
                        cmd.Parameters.AddWithValue("@Remarks", oMaster.Remarks);

                        cmd.ExecuteNonQuery();


                        cmd.CommandText = "Delete from t_GRDet where GRDet_MStrOID=@GRMstr_OID";
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@GRMstr_OID", oMaster.GRMstr_OID);
                        cmd.ExecuteNonQuery();

                        foreach (CGRDetails oDetails in oMaster.GRMstr_DetailsList)
                        {
                            cmd.CommandText = "sp_GRDetails_Insert";
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.Clear();

                            cmd.Parameters.AddWithValue("@GRDet_Branch", oDetails.GRDet_Branch);
                            cmd.Parameters.AddWithValue("@GRDet_OID", oDetails.GRDet_OID);
                            cmd.Parameters.AddWithValue("@GRDet_MStrOID", oMaster.GRMstr_OID);
                            cmd.Parameters.AddWithValue("@GRDet_ItemOID", oDetails.GRDet_ItemOID);
                            cmd.Parameters.AddWithValue("@GRDet_QTY", oDetails.GRDet_QTY);
                            cmd.Parameters.AddWithValue("@GRDet_UOM", oDetails.GRDet_UOM);
                            cmd.Parameters.AddWithValue("@GRDet_BranchOID", oDetails.GRDet_BranchOID);
                            cmd.Parameters.AddWithValue("@GRDet_LocOID", oDetails.GRDet_LocOID);
                            cmd.Parameters.AddWithValue("@GRDet_InvType", oDetails.GRDet_InvType);
                            cmd.Parameters.AddWithValue("@GRDet_Price", oDetails.GRDet_Price);
                            cmd.Parameters.AddWithValue("@GRDet_Currency", oDetails.GRDet_Currency);
                            cmd.Parameters.AddWithValue("@GRDet_Amount", oDetails.GRDet_Amount);

                            cmd.ExecuteNonQuery();
                        }

                        // update inventory

                        foreach (CGRDetails oGRDetails in oGRFinalQtyDic.Values)
                        {
                            // populate inv list
                            CInventory oInventory = new CInventory();

                            oInventory.Invt_Branch    = oGRDetails.GRDet_Branch;
                            oInventory.Invt_BranchOID = oGRDetails.GRDet_BranchOID;
                            oInventory.Invt_InvType   = oGRDetails.GRDet_InvType;
                            oInventory.Invt_ItemOID   = oGRDetails.GRDet_ItemOID;
                            oInventory.Invt_LocOID    = oGRDetails.GRDet_LocOID;
                            oInventory.Invt_QTY       = oGRDetails.GRDet_QTY;

                            oInvtList.Add(oInventory);
                        }

                        //Update inv

                        CInventoryBO oInventoryBO = new CInventoryBO();
                        oResult = oInventoryBO.InvtInc(oInvtList);

                        if (oResult.IsSuccess)
                        {
                            oConnManager.Commit();

                            oResult.IsSuccess = true;
                        }
                        else
                        {
                            oResult.ErrMsg    = oConnManager.Rollback();
                            oResult.IsSuccess = false;
                        }
                    }
                    catch (SqlException e)
                    {
                        string sRollbackError = oConnManager.Rollback();

                        oResult.IsSuccess = false;
                        oResult.ErrMsg    = sRollbackError.Equals("") ? oConnManager.GetErrorMessage(e) : sRollbackError;
                    }
                    finally
                    {
                        oConnManager.Close();
                    }
                }
                else
                {
                    oResult.IsSuccess = false;
                    oResult.ErrMsg    = s_DBError;
                }

                return(oResult);
            }
Пример #2
0
            public CResult Create(CGRMaster oMaster)
            {
                List <CInventory> oInvtList = new List <CInventory>();

                oResult = new CResult();
                conn    = oConnManager.GetConnection(out s_DBError);
                if (conn != null)
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.Parameters.Clear();

                    cmd.Transaction = oConnManager.BeginTransaction();
                    try
                    {
                        //
                        cmd.CommandText = "sp_GRMaster_Insert";
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.Add("@GRMstr_OID", SqlDbType.Char, 24);
                        cmd.Parameters["@GRMstr_OID"].Direction = ParameterDirection.Output;

                        cmd.Parameters.AddWithValue("@GRMstr_Branch", oMaster.GRMstr_Branch);
                        cmd.Parameters.AddWithValue("@GRMstr_Code", oMaster.GRMstr_Code);
                        cmd.Parameters.AddWithValue("@GRMstr_Date", oMaster.GRMstr_Date);
                        cmd.Parameters.AddWithValue("@GRMstr_Type", oMaster.GRMstr_Type);
                        cmd.Parameters.AddWithValue("@GRMstr_By", oMaster.GRMstr_By);
                        cmd.Parameters.AddWithValue("@GRMstr_RefBy", oMaster.GRMstr_RefBy);
                        cmd.Parameters.AddWithValue("@GRMstr_VendorID", oMaster.GRMstr_VendorID);
                        cmd.Parameters.AddWithValue("@GRMstr_TotalAmt", oMaster.GRMstr_TotalAmt);

                        cmd.Parameters.AddWithValue("@Creator", oMaster.Creator);
                        cmd.Parameters.AddWithValue("@CreationDate", oMaster.CreationDate);
                        cmd.Parameters.AddWithValue("@UpdateBy", oMaster.UpdateBy);
                        cmd.Parameters.AddWithValue("@UpdateDate", oMaster.UpdateDate);
                        cmd.Parameters.AddWithValue("@IsActive", (oMaster.IsActive == "Y") ? 1 : 0);
                        cmd.Parameters.AddWithValue("@Remarks", oMaster.Remarks);
                        cmd.Parameters.AddWithValue("@IsImported", oMaster.GRMstr_IsImported);

                        cmd.ExecuteNonQuery();
                        string stGRMStr_OID = cmd.Parameters["@GRMstr_OID"].Value.ToString();

                        if (stGRMStr_OID.Trim() == "")
                        {
                            oResult.ErrMsg    = "This delivered data is already exists.";
                            oResult.IsSuccess = false;
                            return(oResult);
                        }

                        foreach (CGRDetails oDetails in oMaster.GRMstr_DetailsList)
                        {
                            cmd.CommandText = "sp_GRDetails_Insert";
                            cmd.Parameters.Clear();

                            cmd.Parameters.AddWithValue("@GRDet_Branch", oDetails.GRDet_Branch);
                            cmd.Parameters.AddWithValue("@GRDet_OID", oDetails.GRDet_OID);
                            cmd.Parameters.AddWithValue("@GRDet_MStrOID", stGRMStr_OID);
                            cmd.Parameters.AddWithValue("@GRDet_ItemOID", oDetails.GRDet_ItemOID);
                            cmd.Parameters.AddWithValue("@GRDet_QTY", oDetails.GRDet_QTY);
                            cmd.Parameters.AddWithValue("@GRDet_UOM", oDetails.GRDet_UOM);
                            cmd.Parameters.AddWithValue("@GRDet_BranchOID", oDetails.GRDet_BranchOID);
                            cmd.Parameters.AddWithValue("@GRDet_LocOID", oDetails.GRDet_LocOID);
                            cmd.Parameters.AddWithValue("@GRDet_InvType", oDetails.GRDet_InvType);
                            cmd.Parameters.AddWithValue("@GRDet_Price", oDetails.GRDet_Price);
                            cmd.Parameters.AddWithValue("@GRDet_Currency", oDetails.GRDet_Currency);
                            cmd.Parameters.AddWithValue("@GRDet_Amount", oDetails.GRDet_Amount);

                            cmd.ExecuteNonQuery();

                            // populate inv list
                            CInventory oInventory = new CInventory();

                            oInventory.Invt_Branch    = oDetails.GRDet_Branch;
                            oInventory.Invt_BranchOID = oDetails.GRDet_BranchOID;
                            oInventory.Invt_InvType   = oDetails.GRDet_InvType;
                            oInventory.Invt_ItemOID   = oDetails.GRDet_ItemOID;
                            oInventory.Invt_LocOID    = oDetails.GRDet_LocOID;
                            oInventory.Invt_QTY       = oDetails.GRDet_QTY;

                            oInvtList.Add(oInventory);
                        }

                        //Update inv

                        CInventoryBO oInventoryBO = new CInventoryBO();
                        oResult = oInventoryBO.InvtInc(oInvtList);

                        if (oResult.IsSuccess)
                        {
                            oConnManager.Commit();

                            oResult.IsSuccess = true;
                        }
                        else
                        {
                            oResult.ErrMsg    = oConnManager.Rollback();
                            oResult.IsSuccess = false;
                        }
                    }
                    catch (SqlException e)
                    {
                        string sRollbackError = oConnManager.Rollback();

                        oResult.IsSuccess = false;
                        oResult.ErrMsg    = sRollbackError.Equals("") ? oConnManager.GetErrorMessage(e) : sRollbackError;
                    }
                    finally
                    {
                        oConnManager.Close();
                    }
                }
                else
                {
                    oResult.IsSuccess = false;
                    oResult.ErrMsg    = s_DBError;
                }

                return(oResult);
            }