Exemple #1
0
 public IHttpActionResult Save(pim_groupm Record)
 {
     try
     {
         using (GroupService obj = new GroupService())
             return(Ok(obj.Save(Record)));
     }
     catch (Exception Ex)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Ex.Message.ToString())));
     }
 }
Exemple #2
0
        public string AllValid(pim_groupm Record)
        {
            string str = "";

            try
            {
                sql  = "select comp_pkid from (";
                sql += "select comp_pkid  from companym a where (a.comp_code = '{CODE}')  ";

                sql += ") a where comp_pkid <> '{PKID}'";

                //sql = sql.Replace("{CODE}", Record.comp_code);

                if (Con_Oracle.IsRowExists(sql))
                {
                    str = "Code/Name Exists";
                }
            }
            catch (Exception Ex)
            {
                str = Ex.Message.ToString();
            }
            return(str);
        }
Exemple #3
0
        public Dictionary <string, object> Save(pim_groupm Record)
        {
            Dictionary <string, object> RetData = new Dictionary <string, object>();
            string  ErrorMessage = "";
            Boolean retvalue     = false;

            DataTable dt_parent = null;


            try
            {
                Con_Oracle = new DBConnection();

                if (Record.grp_name.Trim().Length <= 0)
                {
                    Lib.AddError(ref ErrorMessage, "name Cannot Be Empty");
                }

                if (ErrorMessage != "")
                {
                    throw new Exception(ErrorMessage);
                }

                if ((ErrorMessage = AllValid(Record)) != "")
                {
                    throw new Exception(ErrorMessage);
                }


                if (Record.rec_type == "ROOT")
                {
                    Record.grp_level     = 1;
                    Record.grp_parent_id = "";
                }
                else
                {
                    sql       = "select * from pim_groupm where grp_pkid = '" + Record.grp_parent_id + "'";
                    dt_parent = Con_Oracle.ExecuteQuery(sql);
                    if (dt_parent.Rows.Count <= 0)
                    {
                        if (ErrorMessage != "")
                        {
                            throw new Exception("Invalid Parent");
                        }
                    }
                    Record.grp_level     = Lib.Conv2Integer(dt_parent.Rows[0]["grp_level"].ToString()) + 1;
                    Record.grp_parent_id = dt_parent.Rows[0]["grp_pkid"].ToString();
                }

                if (Record.grp_level <= 0)
                {
                    throw new Exception("Invalid group level");
                }

                sql  = "select max(grp_name) as grp_name from pim_groupm where ";
                sql += " rec_company_code = '" + Record._globalvariables.comp_code + "'";
                sql += " and grp_name = '" + Record.grp_name.ToString().ToLower() + "'";
                sql += " and grp_table_name = '" + Record.grp_table_name.ToString().ToLower() + "'";

                if (Record.grp_parent_id == "")
                {
                    sql += " and grp_parent_id is null ";
                }
                else
                {
                    sql += " and grp_parent_id = '" + Record.grp_parent_id + "'";
                }

                if (Con_Oracle.IsRowExists(sql))
                {
                    throw new Exception("Dupliate name not  allowed ");
                }



                sql = "select nvl(max(grp_level_slno), 100000) + 1  as slno from pim_groupm where ";

                if (Con_Oracle.DB == "SQL")
                {
                    sql = "select isnull(max(grp_level_slno), 100000) + 1  as slno from pim_groupm where ";
                }

                sql += " rec_company_code = '" + Record._globalvariables.comp_code + "'";
                sql += " and grp_table_name = '" + Record.grp_table_name + "'";
                if (Record.grp_parent_id == "")
                {
                    sql += " and grp_parent_id is null ";
                }
                else
                {
                    sql += " and grp_parent_id = '" + Record.grp_parent_id + "'";
                }

                int iSlno = Lib.Conv2Integer(Con_Oracle.ExecuteScalar(sql).ToString());

                if (iSlno <= 0)
                {
                    throw new Exception("Invalid SL#");
                }


                if (Record.rec_type == "ROOT")
                {
                    Record.grp_level_id   = iSlno.ToString();
                    Record.grp_level_name = Record.grp_name;
                }
                else
                {
                    Record.grp_level_id   = dt_parent.Rows[0]["grp_level_id"].ToString() + "-" + iSlno.ToString();
                    Record.grp_level_name = dt_parent.Rows[0]["grp_level_name"].ToString() + "\\" + Record.grp_name;
                }


                DBRecord Rec = new DBRecord();
                Rec.CreateRow("pim_groupm", Record.rec_mode, "grp_pkid", Record.grp_pkid);
                Rec.InsertString("grp_name", Record.grp_name, "L");

                Rec.InsertString("grp_parent_id", Record.grp_parent_id);
                Rec.InsertNumeric("grp_level", Record.grp_level.ToString());

                Rec.InsertString("grp_level_slno", iSlno.ToString());
                Rec.InsertString("grp_level_id", Record.grp_level_id);
                Rec.InsertString("grp_level_name", Record.grp_level_name, "L");

                if (Record.rec_mode == "ADD")
                {
                    Rec.InsertString("grp_table_name", Record.grp_table_name);
                    Rec.InsertString("rec_company_code", Record._globalvariables.comp_code);
                    Rec.InsertString("rec_hidden", "N");
                    Rec.InsertString("rec_created_by", Record._globalvariables.user_code);


                    if (Con_Oracle.DB == "ORACLE")
                    {
                        Rec.InsertFunction("rec_created_date", "SYSDATE");
                    }
                    else
                    {
                        Rec.InsertFunction("rec_created_date", "GETDATE()");
                    }
                }
                if (Record.rec_mode == "EDIT")
                {
                    Rec.InsertString("rec_edited_by", Record._globalvariables.user_code);
                    if (Con_Oracle.DB == "ORACLE")
                    {
                        Rec.InsertFunction("rec_edited_date", "SYSDATE");
                    }
                    else
                    {
                        Rec.InsertFunction("rec_edited_date", "GETDATE()");
                    }
                }

                sql = Rec.UpdateRow();

                Con_Oracle.BeginTransaction();
                Con_Oracle.ExecuteNonQuery(sql);
                Con_Oracle.CommitTransaction();
                Con_Oracle.CloseConnection();
                retvalue = true;
            }
            catch (Exception Ex)
            {
                if (Con_Oracle != null)
                {
                    Con_Oracle.RollbackTransaction();
                    Con_Oracle.CloseConnection();
                }
                retvalue = false;
                throw Ex;
            }
            Con_Oracle.CloseConnection();
            RetData.Add("retvalue", retvalue);
            RetData.Add("grp_level_id", Record.grp_level_id);
            RetData.Add("grp_level_name", Record.grp_level_name);

            return(RetData);
        }
Exemple #4
0
        public Dictionary <string, object> GetRecord(Dictionary <string, object> SearchData)
        {
            Dictionary <string, object> RetData = new Dictionary <string, object>();

            List <pim_groupm> mList = new List <pim_groupm>();
            pim_groupm        mRow  = new pim_groupm();

            string  parentid     = SearchData["parentid"].ToString();
            string  company_code = SearchData["company_code"].ToString();
            string  table_name   = SearchData["grp_table_name"].ToString();
            Boolean showInactive = (Boolean)SearchData["showinactive"];

            try
            {
                DataTable Dt_Rec = new DataTable();

                sql  = "select  grp_pkid, grp_name, grp_parent_id, grp_level_slno,grp_level_id, grp_level_name, rec_hidden, grp_table_name ";
                sql += " from pim_groupm a  ";
                sql += " where a.rec_company_code ='" + company_code + "' and a.grp_table_name = '" + table_name + "'";
                if (parentid == "")
                {
                    sql += " and  a.grp_parent_id is null ";
                }
                else
                {
                    sql += " and  a.grp_parent_id ='" + parentid + "'";
                }

                if (showInactive == false)
                {
                    sql += " and  a.rec_hidden ='N'";
                }


                sql += " order by grp_level_slno ";

                Con_Oracle = new DBConnection();
                Dt_Rec     = Con_Oracle.ExecuteQuery(sql);
                Con_Oracle.CloseConnection();
                foreach (DataRow Dr in Dt_Rec.Rows)
                {
                    mRow               = new pim_groupm();
                    mRow.grp_pkid      = Dr["grp_pkid"].ToString();
                    mRow.grp_name      = Dr["grp_name"].ToString();
                    mRow.grp_parent_id = Dr["grp_parent_id"].ToString();

                    mRow.grp_level_id   = Dr["grp_level_id"].ToString();
                    mRow.grp_level_name = Dr["grp_level_name"].ToString();
                    mRow.grp_table_name = Dr["grp_table_name"].ToString();


                    mRow.rec_hidden = Dr["rec_hidden"].ToString() == "Y" ? true : false;
                    mList.Add(mRow);
                }
            }
            catch (Exception Ex)
            {
                if (Con_Oracle != null)
                {
                    Con_Oracle.CloseConnection();
                }
                throw Ex;
            }
            RetData.Add("list", mList);
            return(RetData);
        }