Beispiel #1
0
        public Result Init(DbConnections db)
        {
            Result res = new Result();

            try
            {
                EServ.Shared.Static.WriteToLogFile("Init RebateFormulas ...");

                #region [ Init General List ]
                //res = HPro.DB.Main.DB202111(db,null);
                string sql = "select FormulaID, Status, BeginDate, EndDate, SQLFunction  from RebateFormula";
                res = db.ExecuteQuery("core", sql, enumCommandType.SELECT, "Txn50000x", null);

                if (res.ResultNo != 0)
                {
                    return(res);
                }
                if (res.Data == null)
                {
                    res.ResultNo   = 9110015;
                    res.ResultDesc = "RebateFormulas уншихад алдаа гарлаа";
                    return(res);
                }
                foreach (DataRow DR in res.Data.Tables[0].Rows)
                {
                    RebateFormula formula = new RebateFormula();
                    formula.FormulaID = Static.ToLong(DR["FormulaID"]);
                    formula.Status    = Static.ToInt(DR["Status"]);
                    formula.BeginDate = Static.ToDate(DR["BeginDate"]);
                    formula.EndDate   = Static.ToDate(DR["EndDate"]);
                    formula.SQL       = Static.ToStr(DR["SQLFUNCTION"]);
                    _RebateFormulas.Add(formula.FormulaID, formula);
                }
                #endregion
                return(res);
            }
            catch (Exception ex)
            {
                res.ResultNo   = 9110015;
                res.ResultDesc = "Байгууллагын дансны бүтээгдэхүүний уншихад алдаа гарлаа" + ex.Message;

                EServ.Shared.Static.WriteToLogFile("Error.log", ex.Message + ex.Source + ex.StackTrace);

                return(res);
            }
        }
Beispiel #2
0
        public Result Txn500099(ClientInfo ci, RequestInfo ri, DbConnections db, ref Log lg)
        {
            Result res = new Result();
            string sql;

            DataTable saleDB;
            DataTable valueDB;
            Hashtable ids = new Hashtable();
            RebateID  id;
            int       index = 0;

            try
            {
                gRebateMaster.Init(db);
                gRebateFormula.Init(db);

                #region [ Гэрээний дугаар орж ирсэн бол rebate ID-г авах ]

                long contractno = Static.ToLong(ri.ReceivedParam[0]);
                if (contractno != 0)
                {
                    sql = "select rebateid, loyalid, pointid from ContractMain where contractNo=:1";
                    res = db.ExecuteQuery("core", sql, enumCommandType.SELECT, "Txn50000x", contractno);

                    if (res.ResultNo != 0)
                    {
                        return(res);
                    }
                    if (res.Data == null)
                    {
                        res.ResultNo   = 9110015;
                        res.ResultDesc = "Гэрээний мэдээлэл уншихад алдаа гарлаа";
                        return(res);
                    }
                    if (res.Data.Tables[0] == null)
                    {
                        res.ResultNo   = 9110015;
                        res.ResultDesc = "Гэрээний мэдээлэл уншихад алдаа гарлаа";
                        return(res);
                    }
                    if (res.Data.Tables[0].Rows.Count > 0)
                    {
                        id          = new RebateID();
                        id.rebateid = Static.ToLong(res.Data.Tables[0].Rows[0][0]);
                        id.loyalid  = Static.ToLong(res.Data.Tables[0].Rows[0][1]);
                        id.pointid  = Static.ToLong(res.Data.Tables[0].Rows[0][2]);
                        ids.Add(index, id);
                    }
                }
                #endregion
                #region [ Захиалгын дугаар орж ирсэн бол rebate ID-г авах ]
                long orderno = Static.ToLong(ri.ReceivedParam[1]);
                if (orderno != 0)
                {
                    sql = "select rebateid, loyalid, pointid from Orders where OrderNo=:1";
                    res = db.ExecuteQuery("core", sql, enumCommandType.SELECT, "Txn50000x", orderno);

                    if (res.ResultNo != 0)
                    {
                        return(res);
                    }
                    if (res.Data == null)
                    {
                        res.ResultNo   = 9110015;
                        res.ResultDesc = "Захиалгын уншихад алдаа гарлаа";
                        return(res);
                    }
                    if (res.Data.Tables[0] == null)
                    {
                        res.ResultNo   = 9110015;
                        res.ResultDesc = "Захиалгын уншихад алдаа гарлаа";
                        return(res);
                    }
                    if (res.Data.Tables[0].Rows.Count > 0)
                    {
                        id          = new RebateID();
                        id.rebateid = Static.ToLong(res.Data.Tables[0].Rows[0][0]);
                        id.loyalid  = Static.ToLong(res.Data.Tables[0].Rows[0][1]);
                        id.pointid  = Static.ToLong(res.Data.Tables[0].Rows[0][2]);
                        ids.Add(index, id);
                    }
                }
                #endregion
                #region [ Хүсэлт дээрээс Rebate ID-г авах ]
                if (contractno == 0 && orderno == 0)
                {
                    long rebateid = 0;
                    long loyalid  = 0;
                    long pointid  = 0;
                    if (Static.ToLong(ri.ReceivedParam[2]) != 0)
                    {
                        rebateid = Static.ToLong(ri.ReceivedParam[2]);
                    }
                    else
                    {
                        rebateid = 0;
                    }

                    if (Static.ToLong(ri.ReceivedParam[3]) != 0)
                    {
                        loyalid = Static.ToLong(ri.ReceivedParam[3]);
                    }
                    else
                    {
                        loyalid = 0;
                    }
                    if (Static.ToLong(ri.ReceivedParam[4]) != 0)
                    {
                        pointid = Static.ToLong(ri.ReceivedParam[4]);
                    }
                    else
                    {
                        pointid = 0;
                    }
                    if (!(loyalid == 0 && loyalid == 0 && pointid == 0))
                    {
                        id          = new RebateID();
                        id.rebateid = rebateid;
                        id.loyalid  = loyalid;
                        id.pointid  = pointid;
                        ids.Add(index, id);
                    }
                }
                #endregion
                #region [ Sale, Value DataTable-уудыг унших ]

                if (ri.ReceivedParam[5] != null)
                {
                    DataTable productlist = (DataTable)ri.ReceivedParam[5];
                    saleDB = new DataTable();
                    saleDB.Columns.Add("CUSTOMERNO", typeof(long));
                    saleDB.Columns.Add("PRODTYPE", typeof(int));
                    saleDB.Columns.Add("PRODNO", typeof(string));
                    saleDB.Columns.Add("PRICE", typeof(decimal));
                    saleDB.Columns.Add("QUANTITY", typeof(long));
                    saleDB.Columns.Add("SALESPRICE", typeof(decimal));

                    foreach (DataRow dr in productlist.Rows)
                    {
                        if (Static.ToInt(dr["FLAG"]) != 3)
                        {
                            DataRow drow = saleDB.NewRow();
                            drow["CUSTOMERNO"] = dr["CUSTOMERNO"];
                            drow["PRODTYPE"]   = dr["PRODTYPE"];
                            drow["PRODNO"]     = dr["PRODCODE"];
                            drow["PRICE"]      = dr["PRICE"];
                            drow["QUANTITY"]   = dr["QUANTITY"];
                            drow["SALESPRICE"] = dr["PRICE"];
                            saleDB.Rows.Add(drow);
                        }
                    }
                }
                else
                {
                    res.ResultNo   = 9110015;
                    res.ResultDesc = "Борлуулалтын мэдээлэл орж ирээгүй байна.";
                    return(res);
                }
                if (ri.ReceivedParam[6] != null)
                {
                    valueDB = (DataTable)(ri.ReceivedParam[6]);
                }
                else
                {
                    res.ResultNo   = 9110015;
                    res.ResultDesc = "Нэмэлт мэдээлэл орж ирээгүй байна.";
                    return(res);
                }
                #endregion
                #region [ Rebate ID байхгүй бол Macro ажиллуулж RebateID-нуудыг авах ]
                if (ids.Count == 0)
                {
                    tmptrankey = InsertTmpDatas(db, saleDB, valueDB);
                    if (tmptrankey == 0)
                    {
                        res.ResultNo   = 1;
                        res.ResultDesc = "Temporary бааз руу оруулахад алдаа гарлаа";
                        return(res);
                    }

                    foreach (object obj in gRebateFormula.RebateFormulas.Keys)
                    {
                        RebateFormula formula = (RebateFormula)gRebateFormula.RebateFormulas[obj];
                        if (formula.Status == 0 && (formula.BeginDate <= DateTime.Now && formula.EndDate >= DateTime.Now))
                        {
                            sql = formula.SQL;
                            if (sql.Trim() != "")
                            {
                                object[] resdb = ProcessPLSQL(db, tmptrankey, formula.SQL);
                                if (resdb == null)
                                {
                                    res.ResultNo   = 1;
                                    res.ResultDesc = "PL SQL-ийг ажиллуулахад алдаа гарлаа";
                                    return(res);
                                }
                                if (resdb.Count() > 0)
                                {
                                    if (Static.ToLong(resdb[0]) != 0 || Static.ToLong(resdb[1]) != 0 || Static.ToLong(resdb[2]) != 0)
                                    {
                                        id          = new RebateID();
                                        id.rebateid = Static.ToLong(resdb[0]);
                                        id.loyalid  = Static.ToLong(resdb[1]);
                                        id.pointid  = Static.ToLong(resdb[2]);
                                        ids.Add(index, id);
                                        index += 1;
                                    }
                                }
                                else
                                {
                                    //id = new RebateID();
                                    //id.rebateid = 0;
                                    //id.loyalid = 0;
                                    //id.pointid = 0;
                                    //ids.Add(index, id);
                                    //index += 1;
                                }
                            }
                        }
                    }
                }
                #endregion

                #region [ Calculation ]
                object[] resData = new object[ids.Count];
                object[] oneresData;
                index = 0;
                foreach (object obj in ids.Keys)
                {
                    id             = (RebateID)ids[obj];
                    oneresData     = GetCalcResult(id, saleDB);
                    resData[index] = oneresData;
                    index++;
                }
                res.Param    = resData;
                res.ResultNo = 0;
                #endregion

                return(res);
            }
            catch (Exception ex)
            {
                res.ResultNo   = 9110002;
                res.ResultDesc = "Програм руу нэвтрэхэд алдаа гарлаа" + ex.Message;
                EServ.Shared.Static.WriteToLogFile("Error.log", ex.Message + ex.Source + ex.StackTrace);
                return(res);
            }
            return(res);
        }