public string SetEnergyMeterParameter(string MacId, string EPRowNo, string EPDate, string EPMonth, string EPYear, string EPHour, string EPMinute,
                                              string EPCumulativeActiveEnergy, string EPAveragePowerFactor, string EPPowerONHours, string EPMonthlyLoadONCount, string EPMonthlyLoadOFFCount)
        {
            AppLog.WriteErrorLog("Function (POST) : EnergyParameter/SetEnergyMeterParameter");
            bool   IsRecordStore = false;
            string ReturnVal     = Validation.UnsuccessEnergyParameter;

            try
            {
                IsRecordStore = QueryBuilder.InsertInDB("gdt_energymeterparameter",
                                                        "MacId,EPRowNo,EPDate,EPMonth,EPYear,EPHour,EPMinute,EPCumulativeActiveEnergy,EPAveragePowerFactor,EPPowerONHours,EPMonthlyLoadONCount,EPMonthlyLoadOFFCount,EPRecordDate",
                                                        "'" + MacId + "','" + EPRowNo + "','" + EPDate + "','" + EPMonth + "','" + EPYear + "','" + EPHour + "','" + EPMinute + "','" + EPCumulativeActiveEnergy + "','" +
                                                        EPAveragePowerFactor + "','" + EPPowerONHours + "','" + EPMonthlyLoadONCount + "','" + EPMonthlyLoadOFFCount + "','" + DateTime.Now + "'");

                if (IsRecordStore)
                {
                    ReturnVal = Validation.SuccessEnergyParameter;
                }
                return(ReturnVal);
            }
            catch (Exception ex)
            {
                return(Validation.ErrorComman);
            }
            finally
            {
            }
        }
Esempio n. 2
0
        public string AddRole(string Role, string RoleDescription, string IsActive, string CreatedDate, string CreatedBy)
        {
            try
            {
                AppLog.WriteErrorLog("Function (POST) : Role/AddRole");
                if (!Validation.DuplicateRole(Role).Equals("1"))
                {
                    return(Validation.ValidDuplicateRoleId);
                }
                bool IsAdd = false; string ReturnVal = Validation.UnsuccessRoleUser; string Columns = string.Empty; string Values = string.Empty;
                if (!string.IsNullOrEmpty(Role))
                {
                    Columns = "Role"; Values = "'" + Role + "'";
                }
                else
                {
                    return(Validation.ValidDuplicateRoleId);
                }
                if (!string.IsNullOrEmpty(RoleDescription))
                {
                    Columns = Columns + ",RoleDescription"; Values = Values + ",'" + RoleDescription + "'";
                }
                if (!string.IsNullOrEmpty(IsActive))
                {
                    Columns = Columns + ",IsActive"; Values = Values + ",'" + IsActive + "'";
                }
                if (!string.IsNullOrEmpty(CreatedDate))
                {
                    Columns = Columns + ",CreatedDate"; Values = Values + ",'" + CreatedDate + "'";
                }
                if (!string.IsNullOrEmpty(CreatedDate))
                {
                    Columns = Columns + ",ModifiedDate"; Values = Values + ",'" + CreatedDate + "'";
                }
                if (!string.IsNullOrEmpty(CreatedBy))
                {
                    Columns = Columns + ",CreatedBy"; Values = Values + ",'" + CreatedBy + "'";
                }

                if (!string.IsNullOrEmpty(Columns) && !string.IsNullOrEmpty(Values))
                {
                    IsAdd = QueryBuilder.InsertInDB("mtblroles", Columns, Values);
                }
                if (IsAdd)
                {
                    ReturnVal = Validation.SuccessRoleUser;
                }
                return(ReturnVal);
            }
            catch
            {
                return(Validation.ErrorComman);
            }
            finally
            {
            }
        }
 private void SetActivityLogg(string DeviceId, string HType, string UserId, string HDate, string Value1, string Value2, string Value3)
 {
     try
     {
         AppLog.WriteErrorLog("Function : ActivityLog/SetActivityLogg");
         bool IsSet1 = false;
         IsSet1 = QueryBuilder.InsertInDB("gdt_activitylog", "DeviceId,MHDate,HType,UserId,Value1,Value2,Value3",
                                          "'" + DeviceId + "','" + HDate + "','" + HType + "','" + UserId + "','" + Value1 + "','" + Value2 + "','" + Value3 + "'");
     }
     catch (Exception ex) { }
     finally { }
 }
Esempio n. 4
0
        public static bool WriteErrorLog(string Action)
        {
            bool   Status = false; string User = string.Empty;
            string LogDirectory = ConfigurationManager.AppSettings["LogDirectory"].ToString();

            try
            {
            }
            catch
            {
                User = "******";
            }
            finally { }

            DateTime CurrentDateTime       = DateTime.Now;
            string   CurrentDateTimeString = CurrentDateTime.ToString();

            CheckCreateLogDirectory(LogDirectory);

            LogDirectory = (LogDirectory + "Log_" + LogFileName(DateTime.Now) + ".txt");

            //  lock (typeof(ApplicationLog))
            {
                StreamWriter oStreamWriter = null;
                try
                {
                    oStreamWriter = new StreamWriter(LogDirectory, true);

                    string hostName = Dns.GetHostName();
                    string myIP     = Dns.GetHostByName(hostName).AddressList[0].ToString();
                    var    macAddr  = (from nic in NetworkInterface.GetAllNetworkInterfaces()
                                       where nic.OperationalStatus == OperationalStatus.Up
                                       select nic.GetPhysicalAddress().ToString()).FirstOrDefault();

                    #region Storing Values in Notepad
                    oStreamWriter.WriteLine("-------------------------------------------------------------------------------------------------------------------");
                    oStreamWriter.WriteLine("| HostName - " + hostName + " | IP -" + myIP + " | Mac Address - " + macAddr + " | User - " + User + " | Action - " + Action + " |");
                    oStreamWriter.WriteLine("-------------------------------------------------------------------------------------------------------------------");
                    #endregion

                    #region Storing in DB
                    try
                    {
                        QueryBuilder.InsertInDB("errorlog", "HostName,MacAdd,IP,User,DateTime,ErrorDetails", "'" + hostName + "','" + macAddr + "','" + myIP + "','" + User + "','" + DateTime.Now + "','" + Action + "'");
                    }
                    catch
                    {
                    }
                    finally { }
                    #endregion

                    #region Storing Values in XML
                    XmlDocument oXmlDocument = new XmlDocument();
                    oXmlDocument.Load(@"D:\LogFiles\Log.xml");
                    //XmlNode oXmlRootNodeC = oXmlDocument.CreateNode("Records");
                    XmlNode oXmlRootNode   = oXmlDocument.SelectSingleNode("Records");
                    XmlNode oXmlRecordNode = oXmlRootNode.AppendChild(
                        oXmlDocument.CreateNode(XmlNodeType.Element, "Log", ""));
                    oXmlRecordNode.AppendChild(oXmlDocument.CreateNode(XmlNodeType.Element, "HostName", "")).InnerText = hostName;
                    oXmlRecordNode.AppendChild(oXmlDocument.CreateNode(XmlNodeType.Element, "IP", "")).InnerText       = myIP;
                    oXmlRecordNode.AppendChild(oXmlDocument.CreateNode(XmlNodeType.Element, "Datetime", "")).InnerText = DateTime.Now.ToString();
                    oXmlRecordNode.AppendChild(oXmlDocument.CreateNode(XmlNodeType.Element, "MacId", "")).InnerText    = macAddr;
                    oXmlRecordNode.AppendChild(oXmlDocument.CreateNode(XmlNodeType.Element, "User", "")).InnerText     = "User";
                    oXmlRecordNode.AppendChild(oXmlDocument.CreateNode(XmlNodeType.Element, "Action", "")).InnerText   = "Test";
                    oXmlDocument.Save((@"D:\LogFiles\Log.xml"));
                    #endregion
                }
                catch (Exception ex)
                {
                    string Error = ex.Message;
                }
                finally
                {
                    if (oStreamWriter != null)
                    {
                        oStreamWriter.Close();
                    }
                }
            }
            return(Status);
        }
Esempio n. 5
0
        public string AddUser(string FirstName, string MiddleName, string LastName, string UserId, string Password, string RoleId, string EmailId, string Phone, string IsActive, string CreatedDate, string CreatedBy)
        {
            try
            {
                AppLog.WriteErrorLog("Function (POST) : User/AddUser");

                if (!Validation.DuplicateUserId(UserId).Equals("1"))
                {
                    return(Validation.ValidDuplicateUserId);
                }
                if (!Validation.DuplicateEmailId(EmailId).Equals("1"))
                {
                    return(Validation.ValidDuplicateEmailId);
                }
                if (!Validation.DuplicatePhone(Phone).Equals("1"))
                {
                    return(Validation.ValidDuplicatePhone);
                }

                bool IsAdd = false; string ReturnVal = Validation.UnsuccessAddUser; string Columns = string.Empty; string Values = string.Empty;
                if (!string.IsNullOrEmpty(FirstName))
                {
                    Columns = "FirstName"; Values = "'" + FirstName + "'";
                }
                else
                {
                    return(Validation.ValidFirstName);
                }
                if (!string.IsNullOrEmpty(MiddleName))
                {
                    Columns = Columns + ",MiddleName"; Values = Values + ",'" + MiddleName + "'";
                }
                if (!string.IsNullOrEmpty(LastName))
                {
                    Columns = Columns + ",LastName"; Values = Values + ",'" + LastName + "'";
                }
                if (!string.IsNullOrEmpty(UserId))
                {
                    Columns = Columns + ",UserId"; Values = Values + ",'" + UserId + "'";
                }
                else
                {
                    return(Validation.ValidUserId);
                }
                if (string.IsNullOrEmpty(RoleId))
                {
                    return(Validation.ValidRoleId);
                }
                if (!string.IsNullOrEmpty(Password))
                {
                    Columns = Columns + ",Password"; Values = Values + ",'" + Password + "'";
                }
                else
                {
                    return(Validation.ValidPassword);
                }
                if (!string.IsNullOrEmpty(EmailId))
                {
                    Columns = Columns + ",EmailId"; Values = Values + ",'" + EmailId + "'";
                }
                else
                {
                    return(Validation.ValidEmail);
                }
                if (!string.IsNullOrEmpty(Phone))
                {
                    Columns = Columns + ",Phone"; Values = Values + ",'" + Phone + "'";
                }
                if (!string.IsNullOrEmpty(IsActive))
                {
                    Columns = Columns + ",IsActive"; Values = Values + ",'" + IsActive + "'";
                }
                if (!string.IsNullOrEmpty(CreatedDate))
                {
                    Columns = Columns + ",CreatedDate"; Values = Values + ",'" + CreatedDate + "'";
                }
                if (!string.IsNullOrEmpty(CreatedBy))
                {
                    Columns = Columns + ",CreatedBy"; Values = Values + ",'" + CreatedBy + "'";
                }

                if (!string.IsNullOrEmpty(Columns) && !string.IsNullOrEmpty(Values))
                {
                    IsAdd = QueryBuilder.InsertInDB("tblusers", Columns, Values);
                    if (IsAdd)
                    {
                        string Columns1 = string.Empty; string Values1 = string.Empty; string AuthToken = Guid.NewGuid().ToString().Substring(0, 8);
                        if (!string.IsNullOrEmpty(UserId))
                        {
                            Columns1 = "UserId"; Values1 = "'" + UserId + "'";
                        }
                        else
                        {
                            return(Validation.ValidUserId);
                        }
                        if (!string.IsNullOrEmpty(AuthToken))
                        {
                            Columns1 = Columns1 + ",AuthToken"; Values1 = Values1 + ",'" + AuthToken + "'";
                        }
                        if (!string.IsNullOrEmpty(IsActive))
                        {
                            Columns1 = Columns1 + ",IsActive"; Values1 = Values1 + ",'" + IsActive + "'";
                        }
                        if (!string.IsNullOrEmpty(CreatedDate))
                        {
                            Columns1 = Columns1 + ",CreatedDate"; Values1 = Values1 + ",'" + CreatedDate + "'";
                        }
                        if (!string.IsNullOrEmpty(CreatedBy))
                        {
                            Columns1 = Columns1 + ",CreatedBy"; Values1 = Values1 + ",'" + CreatedBy + "'";
                        }
                        if (!string.IsNullOrEmpty(Columns1) && !string.IsNullOrEmpty(Values1))
                        {
                            QueryBuilder.InsertInDB("tbluserauthtokens", Columns1, Values1);
                        }
                    }
                    if (IsAdd)
                    {
                        string Columns2 = string.Empty; string Values2 = string.Empty;
                        if (!string.IsNullOrEmpty(UserId))
                        {
                            Columns2 = "UserId"; Values2 = "'" + UserId + "'";
                        }
                        else
                        {
                            return(Validation.ValidUserId);
                        }
                        if (!string.IsNullOrEmpty(RoleId))
                        {
                            Columns2 = Columns2 + ",RoleId"; Values2 = Values2 + ",'" + RoleId + "'";
                        }
                        if (!string.IsNullOrEmpty(IsActive))
                        {
                            Columns2 = Columns2 + ",IsActive"; Values2 = Values2 + ",'" + IsActive + "'";
                        }
                        if (!string.IsNullOrEmpty(CreatedDate))
                        {
                            Columns2 = Columns2 + ",CreatedDate"; Values2 = Values2 + ",'" + CreatedDate + "'";
                        }
                        if (!string.IsNullOrEmpty(CreatedBy))
                        {
                            Columns2 = Columns2 + ",CreatedBy"; Values2 = Values2 + ",'" + CreatedBy + "'";
                        }
                        if (!string.IsNullOrEmpty(Columns2) && !string.IsNullOrEmpty(Values2))
                        {
                            QueryBuilder.InsertInDB("tbluserroles", Columns2, Values2);
                        }
                    }
                }
                if (IsAdd)
                {
                    ReturnVal = Validation.SuccessAddUser;
                }
                return(ReturnVal);
            }
            catch
            {
                return(Validation.ErrorComman);
            }
            finally
            {
            }
        }
Esempio n. 6
0
        public string SetDevice(string DeviceName, string DeviceNo, string UserId)
        {
            string IsSet = Validation.UnsuccessDeviceProfile;

            try
            {
                AppLog.WriteErrorLog("Function (POST) : DeviceProfile/SetDevice");
                DataTable dt = QueryBuilder.GetDataTable("DeviceMastreId", "gdt_device", "Where DeviceNo = '" + DeviceNo + "'");


                if (dt.Rows.Count > 0)
                {
                    bool   IsSet1 = false;
                    string Date   = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute;
                    IsSet1 = QueryBuilder.UpdateDB("DeviceName = '" + DeviceName + "', HDate = '" + Date + "'", "gdt_device", " Where DeviceNo = '" + DeviceNo + "'");

                    if (IsSet1 == true)
                    {
                        IsSet = Validation.SuccessDeviceProfile;

                        DataTable dt1 = QueryBuilder.GetDataTable("Id", "gdt_deviceprofile",
                                                                  " Where (select DeviceNo from gdt_device where DeviceId = DeviceMastreId LIMIT 1) = '" + DeviceNo + "' AND UserId = '" + UserId + "'");

                        if (dt1.Rows.Count > 0)
                        {
                        }
                        else
                        {
                            bool   IsSet2         = false;
                            string Date1          = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute;
                            Int32  DeviceMasterId = QueryBuilder.GetInt("DeviceMastreId", "gdt_device", " Where DeviceNo = '" + DeviceNo + "' LIMIT 1");
                            IsSet2 = QueryBuilder.InsertInDB("gdt_deviceprofile", "DeviceId,UserId,DeviceDateTime,HDate",
                                                             "'" + DeviceMasterId.ToString() + "','" + UserId + "','" + Date1 + "','" + Date1 + "'");
                            if (IsSet2 == true)
                            {
                                IsSet = Validation.SuccessDeviceProfile;
                                SetActivityLog(DeviceMasterId.ToString(), "Profile Created", UserId, Date);
                            }
                        }
                    }
                }
                else
                {
                    bool   IsSet1 = false;
                    string Date   = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute;

                    IsSet1 = QueryBuilder.InsertInDB("gdt_device", "DeviceName,DeviceNo,Date,HDate",
                                                     "'" + DeviceName + "','" + DeviceNo + "','" + Date + "','" + Date + "'");
                    if (IsSet1 == true)
                    {
                        IsSet = Validation.SuccessDeviceProfile;
                        Int32 DeviceMasterId = QueryBuilder.GetInt("DeviceMastreId", "gdt_device", " Where DeviceNo = '" + DeviceNo + "' LIMIT 1");
                        SetActivityLog(DeviceMasterId.ToString(), "Device Created", UserId, Date);

                        DataTable dt1 = QueryBuilder.GetDataTable("Id", "gdt_deviceprofile",
                                                                  " Where (select DeviceNo from gdt_device where DeviceId = DeviceMastreId LIMIT 1) = '" + DeviceNo + "' AND UserId = '" + UserId + "'");

                        if (dt1.Rows.Count > 0)
                        {
                        }
                        else
                        {
                            bool   IsSet2          = false;
                            string Date1           = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute;
                            Int32  DeviceMasterId1 = QueryBuilder.GetInt("DeviceMastreId", "gdt_device", " Where DeviceNo = '" + DeviceNo + "' LIMIT 1");
                            IsSet2 = QueryBuilder.InsertInDB("gdt_deviceprofile", "DeviceId,UserId,DeviceDateTime,HDate",
                                                             "'" + DeviceMasterId1.ToString() + "','" + UserId + "','" + Date1 + "','" + Date1 + "'");
                            if (IsSet2 == true)
                            {
                                IsSet = Validation.SuccessDeviceProfile;

                                SetActivityLog(DeviceMasterId1.ToString(), "Profile Created", UserId, Date);
                            }
                        }
                    }
                }
                return(IsSet);
            }
            catch (Exception ex)
            {
                return(Validation.ErrorComman);
            }
            finally
            {// return IsSet; }
            }
        }
Esempio n. 7
0
        public string AddToken(string UserId, string DeviceId, string IsActive, string CreatedDate, string CreatedBy)
        {
            try
            {
                AppLog.WriteErrorLog("Function (POST) : Token/AddToken");
                string AuthToken = Guid.NewGuid().ToString().Substring(0, 8);
                if (!Validation.DuplicateAuthToken(UserId, AuthToken, DeviceId).Equals("1"))
                {
                    return(Validation.ValidDuplicateAuthToken);
                }
                bool IsAdd = false; string ReturnVal = Validation.UnsuccessAddToken; string Columns = string.Empty; string Values = string.Empty;
                if (!string.IsNullOrEmpty(UserId))
                {
                    Columns = "UserId"; Values = "'" + UserId + "'";
                }
                else
                {
                    return(Validation.ValidDuplicateUserId);
                }
                if (!string.IsNullOrEmpty(AuthToken))
                {
                    Columns = Columns + ",AuthToken"; Values = Values + ",'" + AuthToken + "'";
                }
                else
                {
                    return(Validation.ValidDuplicateAuthToken);
                }
                if (!string.IsNullOrEmpty(DeviceId))
                {
                    Columns = Columns + ",DeviceId"; Values = Values + ",'" + DeviceId + "'";
                }
                else
                {
                    return(Validation.ValidDuplicateDeviceId);
                }
                if (!string.IsNullOrEmpty(UserId))
                {
                    Columns = Columns + ",UserId"; Values = Values + ",'" + UserId + "'";
                }
                if (!string.IsNullOrEmpty(IsActive))
                {
                    Columns = Columns + ",IsActive"; Values = Values + ",'" + IsActive + "'";
                }
                if (!string.IsNullOrEmpty(CreatedDate))
                {
                    Columns = Columns + ",CreatedDate"; Values = Values + ",'" + CreatedDate + "'";
                }
                if (!string.IsNullOrEmpty(CreatedBy))
                {
                    Columns = Columns + ",CreatedBy"; Values = Values + ",'" + CreatedBy + "'";
                }

                if (!string.IsNullOrEmpty(Columns) && !string.IsNullOrEmpty(Values))
                {
                    IsAdd = QueryBuilder.InsertInDB("tbluserauthtokens", Columns, Values);
                }
                if (IsAdd)
                {
                    ReturnVal = Validation.SuccessAddToken;
                }
                return(ReturnVal);
            }
            catch
            {
                return(Validation.ErrorComman);
            }
            finally
            {
            }
        }