Пример #1
0
 public JObject DeleteTopic(string connectionString, int accountId, int sectionId, int topicId)
 {
     try
     {
         if (topicId == 0)
         {
             _helper.CreateProperty(UDC.Label.SUCCESS, false);
             _helper.CreateProperty(UDC.Label.MESSAGE, "TopicId is mandatory");
         }
         else
         {
             Press3.DataAccessLayer.Scripts scriptObj = new Press3.DataAccessLayer.Scripts(connectionString);
             System.Data.DataSet            ds        = scriptObj.DeleteTopic(accountId, sectionId, topicId);
             if (ds.IsNull())
             {
                 _helper.CreateProperty(UDC.Label.SUCCESS, false);
                 _helper.CreateProperty(UDC.Label.MESSAGE, scriptObj.ErrorMessage);
             }
             else
             {
                 _helper.ParseDataSet(ds);
             }
         }
     }
     catch (Exception e)
     {
         Utilities.Logger.Error(e.ToString());
         _helper.InitializeResponseVariables();
         _helper.CreateProperty(UDC.Label.SUCCESS, false);
         _helper.CreateProperty(UDC.Label.MESSAGE, e.Message);
     }
     return(_helper.GetResponse());
 }
Пример #2
0
        public JObject UploadExcelSections(string connectionString, string excelUploadPath, string fileName, string xlSheetData, string header, string scriptTitle, int skillGroupId, int check, int accountId, int agentId)
        {
            JObject jObj = new JObject();

            try
            {
                if (header == "1")
                {
                    header = "Yes";
                }
                else
                {
                    header = "No";
                }

                jObj = JObject.Parse(xlSheetData);
                string extension  = System.IO.Path.GetExtension(fileName);
                JArray sheetArray = new JArray();
                sheetArray = jObj.SelectToken("data") as JArray;
                DataTable table = new DataTable();
                table.Columns.Add("sheetname", typeof(string));
                table.Columns.Add("columns", typeof(int));
                table.Columns.Add("section", typeof(string));
                table.Columns.Add("topic", typeof(string));
                table.Columns.Add("description", typeof(string));
                foreach (JObject _sheet in sheetArray)
                {
                    object[] val = new object[5];
                    val[0] = _sheet.SelectToken("sheetname").ToString();
                    val[1] = _sheet.SelectToken("columnscount").ToString();
                    val[2] = _sheet.SelectToken("section").ToString();
                    val[3] = _sheet.SelectToken("topic").ToString();
                    val[4] = _sheet.SelectToken("description").ToString();
                    table.Rows.Add(val);
                }
                string          excelOleDbConstring = "";
                OleDbConnection oleDbCon            = default(OleDbConnection);
                oleDbCon = null;
                if (extension == ".xlsx")
                {
                    excelOleDbConstring = excelOleDbConstring + "provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelUploadPath + fileName + ";Persist Security Info=True; Extended Properties=\"Excel 12.0;HDR=" + header + ";IMEX=1;\"";
                }
                else if (extension == ".xls")
                {
                    excelOleDbConstring = excelOleDbConstring + "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelUploadPath + fileName + ";Persist Security Info=True; Extended Properties=\"Excel 8.0;HDR=" + header + ";IMEX=1;\"";
                }

                oleDbCon = new OleDbConnection(excelOleDbConstring);
                //oleDbCon = New OleDbConnection(excelOleDbConstring)
                OleDbCommand     OleCmdSelect = null;
                OleDbDataAdapter OleAdapter   = null;
                DataSet          dSet         = null;
                int secP = 0;
                int topP = 0;
                int desP = 0;

                JObject objectj = new JObject();

                int       ColumnsCount = 0;
                string    section = "", topic = "";
                string    description = "";
                DataTable Tab         = new DataTable();

                Tab.Columns.Add("section", typeof(string));
                Tab.Columns.Add("topic", typeof(string));
                Tab.Columns.Add("description", typeof(string));
                for (int k = 0; k <= table.Rows.Count - 1; k++)
                {
                    OleAdapter   = null;
                    dSet         = null;
                    OleCmdSelect = new OleDbCommand("SELECT   *  FROM [" + table.Rows[k]["sheetname"] + "$]", oleDbCon);
                    OleAdapter   = new OleDbDataAdapter(OleCmdSelect);
                    dSet         = new DataSet();
                    OleAdapter.Fill(dSet);
                    secP = 0;
                    topP = 0;
                    desP = 0;
                    //CountryCodeP = 0;
                    section     = "";
                    topic       = "";
                    description = "";
                    //countryC = "";
                    if (dSet.Tables[0].Columns.Count >= 2)
                    {
                        var _with1 = dSet.Tables[0];
                        ColumnsCount = dSet.Tables[0].Columns.Count;
                        secP         = Convert.ToInt32(table.Rows[k]["section"]);
                        topP         = Convert.ToInt32(table.Rows[k]["topic"]);
                        desP         = Convert.ToInt32(table.Rows[k]["description"]);
                    }
                    string sectionName = "";
                    foreach (DataRow _Row in dSet.Tables[0].Rows)
                    {
                        if (secP != 0)
                        {
                            section = _Row[secP - 1].ToString();
                            if (section != "")
                            {
                                sectionName = section;
                            }
                        }


                        if (topP != 0)
                        {
                            topic = _Row[topP - 1].ToString();
                        }
                        if (desP != 0)
                        {
                            description = _Row[desP - 1].ToString();
                        }

                        if ((section != "" || section == "") && topic != "" && description != "")
                        {
                            if (section != "")
                            {
                                Tab.Rows.Add(section.Trim(), topic.Trim(), description.Trim());
                            }
                            else
                            {
                                Tab.Rows.Add(sectionName, topic.Trim(), description.Trim());
                            }
                        }
                    }
                }
                Press3.DataAccessLayer.Scripts scriptObj = new Press3.DataAccessLayer.Scripts(connectionString);
                System.Data.DataSet            ds        = scriptObj.UploadExcelSections(scriptTitle, skillGroupId, check, Tab, accountId, agentId);
                if (ds.IsNull())
                {
                    _helper.CreateProperty(UDC.Label.SUCCESS, false);
                    _helper.CreateProperty(UDC.Label.MESSAGE, scriptObj.ErrorMessage);
                }
                else
                {
                    _helper.ParseDataSet(ds);
                }
            }
            catch (Exception e)
            {
                Utilities.Logger.Error(e.ToString());
                _helper.InitializeResponseVariables();
                _helper.CreateProperty(UDC.Label.SUCCESS, false);
                _helper.CreateProperty(UDC.Label.MESSAGE, e.Message);
            }
            return(_helper.GetResponse());
        }