Christian Dale
Christian Dale
CC#
Created by Christian Dale on 4/22/2024 in #help
✅ Regex Result into CSV and Data Grid
how would i be able to make it a Variable csv input. I was thinking a Switch method but it doesnt seam to work.
c#
public void CSVWrite(Match m)
{
var records = new List<FireInfo>();
switch (int.Parse(m.Groups["AlarmNum"].Value))
{
case 1:
new FireInfo { Time = m.Groups["Time"].Value, ActivationType = "Fire", AlarmNum = m.Groups["AlarmNum"].Value, X0 = m.Groups["X0"].Value, Y0 = m.Groups["Y0"].Value, Size0 = m.Groups["Size0"].Value };
break;
case 2:
new FireInfo { Time = m.Groups["Time"].Value, ActivationType = "Fire", AlarmNum = m.Groups["AlarmNum"].Value, X0 = m.Groups["X0"].Value, Y0 = m.Groups["Y0"].Value, Size0 = m.Groups["Size0"].Value, X1 = m.Groups["X1"].Value, Y1 = m.Groups["Y1"].Value, Size1 = m.Groups["Size1"].Value };
break;
case 3:
new FireInfo { Time = m.Groups["Time"].Value, ActivationType = "Fire", AlarmNum = m.Groups["AlarmNum"].Value, X0 = m.Groups["X0"].Value, Y0 = m.Groups["Y0"].Value, Size0 = m.Groups["Size0"].Value, X1 = m.Groups["X1"].Value, Y1 = m.Groups["Y1"].Value, Size1 = m.Groups["Size1"].Value, X2 = m.Groups["X2"].Value, Y2 = m.Groups["Y2"].Value, Size2 = m.Groups["Size2"].Value };
break;
case 4:
new FireInfo { Time = m.Groups["Time"].Value, ActivationType = "Fire", AlarmNum = m.Groups["AlarmNum"].Value, X0 = m.Groups["X0"].Value, Y0 = m.Groups["Y0"].Value, Size0 = m.Groups["Size0"].Value, X1 = m.Groups["X1"].Value, Y1 = m.Groups["Y1"].Value, Size1 = m.Groups["Size1"].Value, X2 = m.Groups["X2"].Value, Y2 = m.Groups["Y2"].Value, Size2 = m.Groups["Size2"].Value, X3 = m.Groups["X3"].Value, Y3 = m.Groups["Y3"].Value, Size3 = m.Groups["Size3"].Value };
break;
default:
break;
};
}
c#
public void CSVWrite(Match m)
{
var records = new List<FireInfo>();
switch (int.Parse(m.Groups["AlarmNum"].Value))
{
case 1:
new FireInfo { Time = m.Groups["Time"].Value, ActivationType = "Fire", AlarmNum = m.Groups["AlarmNum"].Value, X0 = m.Groups["X0"].Value, Y0 = m.Groups["Y0"].Value, Size0 = m.Groups["Size0"].Value };
break;
case 2:
new FireInfo { Time = m.Groups["Time"].Value, ActivationType = "Fire", AlarmNum = m.Groups["AlarmNum"].Value, X0 = m.Groups["X0"].Value, Y0 = m.Groups["Y0"].Value, Size0 = m.Groups["Size0"].Value, X1 = m.Groups["X1"].Value, Y1 = m.Groups["Y1"].Value, Size1 = m.Groups["Size1"].Value };
break;
case 3:
new FireInfo { Time = m.Groups["Time"].Value, ActivationType = "Fire", AlarmNum = m.Groups["AlarmNum"].Value, X0 = m.Groups["X0"].Value, Y0 = m.Groups["Y0"].Value, Size0 = m.Groups["Size0"].Value, X1 = m.Groups["X1"].Value, Y1 = m.Groups["Y1"].Value, Size1 = m.Groups["Size1"].Value, X2 = m.Groups["X2"].Value, Y2 = m.Groups["Y2"].Value, Size2 = m.Groups["Size2"].Value };
break;
case 4:
new FireInfo { Time = m.Groups["Time"].Value, ActivationType = "Fire", AlarmNum = m.Groups["AlarmNum"].Value, X0 = m.Groups["X0"].Value, Y0 = m.Groups["Y0"].Value, Size0 = m.Groups["Size0"].Value, X1 = m.Groups["X1"].Value, Y1 = m.Groups["Y1"].Value, Size1 = m.Groups["Size1"].Value, X2 = m.Groups["X2"].Value, Y2 = m.Groups["Y2"].Value, Size2 = m.Groups["Size2"].Value, X3 = m.Groups["X3"].Value, Y3 = m.Groups["Y3"].Value, Size3 = m.Groups["Size3"].Value };
break;
default:
break;
};
}
3 replies
CC#
Created by Dread on 4/17/2024 in #help
Valid Inputs
Where is 'inputvalues' defined?
73 replies
CC#
Created by Christian Dale on 3/23/2024 in #help
✅ Looking for a way to Extract information from a txt File
How can I use the Variable of IP into the Regex pattern? The IP is stored as IP = "10.247.247.11"
11 replies
CC#
Created by Christian Dale on 3/23/2024 in #help
✅ Looking for a way to Extract information from a txt File
How would I use the Variables after?
11 replies
CC#
Created by Christian Dale on 1/30/2024 in #help
Extracting JSON Element into a ComboBox Data source
I have found the Issue. 2 Fold i forgor to pass the Fileread into the Variable and also the ComboBox Add needed to be in the Form Design Section.
9 replies
CC#
Created by Christian Dale on 1/30/2024 in #help
Extracting JSON Element into a ComboBox Data source
From the JSON the only thing i need to pull for this are the ModelNumbers.
9 replies
CC#
Created by Christian Dale on 1/30/2024 in #help
Extracting JSON Element into a ComboBox Data source
namespace Hik_Config
{
public partial class Form1 : Form
{
private NvrSettings _nvrSettings;
public Form1(NvrSettings nvrSettings)
{
var data = JsonConvert.DeserializeObject<Model>(@".\nvrModels.json");
foreach (var model in data.Models) {
NVRModel.Items.Add(model.ModelNumber);
}
InitializeComponent();
_nvrSettings = nvrSettings;
JSONLOAD();

}

private void Loud_Btn_Click(object sender, EventArgs e)
{
JSONLOAD();
}

public void JSONLOAD()
{
IpAddressTextBox.Text = _nvrSettings.IpAddress;
UserNameTextBox.Text = _nvrSettings.UserName;
PasswordTextBox.Text = _nvrSettings.Password;
NVRModel.Text= _nvrSettings.Model;
}

private void Save_Btn_Click(object sender, EventArgs e)
{
//string json_txt = File.ReadAllText(@".\Config.json");
//NvrSettings NVR = JsonConvert.DeserializeObject<NvrSettings>(json_txt);
if (IsAddressValid(IpAddressTextBox.Text) == true)
{
_nvrSettings.IpAddress = IpAddressTextBox.Text;
_nvrSettings.UserName = UserNameTextBox.Text;
_nvrSettings.Password = PasswordTextBox.Text;
_nvrSettings.Model = NVRModel.Text;

// Wrap NvrSettings in a RootObject
RootObject rootObject = new RootObject
{
NvrSettings = _nvrSettings
};

File.WriteAllText(@".\Config.json", JsonConvert.SerializeObject(rootObject, Formatting.Indented));
MessageBox.Show("NVR Loader Config Saved Successfully", "SAVED");
Close();
Application.Exit();

}
else
{
MessageBox.Show("INVALID IP ADDRESS", "INVALID IP ADDRESS");
}
}
public bool IsAddressValid(string addrString)
// Check IP is Valid
{
string pattern = @"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
Regex regex = new Regex(pattern);
return regex.IsMatch(addrString);

//IPAddress address;
//return IPAddress.TryParse(addrString, out address) && address.ToString() == addrString;
}
}

}
namespace Hik_Config
{
public partial class Form1 : Form
{
private NvrSettings _nvrSettings;
public Form1(NvrSettings nvrSettings)
{
var data = JsonConvert.DeserializeObject<Model>(@".\nvrModels.json");
foreach (var model in data.Models) {
NVRModel.Items.Add(model.ModelNumber);
}
InitializeComponent();
_nvrSettings = nvrSettings;
JSONLOAD();

}

private void Loud_Btn_Click(object sender, EventArgs e)
{
JSONLOAD();
}

public void JSONLOAD()
{
IpAddressTextBox.Text = _nvrSettings.IpAddress;
UserNameTextBox.Text = _nvrSettings.UserName;
PasswordTextBox.Text = _nvrSettings.Password;
NVRModel.Text= _nvrSettings.Model;
}

private void Save_Btn_Click(object sender, EventArgs e)
{
//string json_txt = File.ReadAllText(@".\Config.json");
//NvrSettings NVR = JsonConvert.DeserializeObject<NvrSettings>(json_txt);
if (IsAddressValid(IpAddressTextBox.Text) == true)
{
_nvrSettings.IpAddress = IpAddressTextBox.Text;
_nvrSettings.UserName = UserNameTextBox.Text;
_nvrSettings.Password = PasswordTextBox.Text;
_nvrSettings.Model = NVRModel.Text;

// Wrap NvrSettings in a RootObject
RootObject rootObject = new RootObject
{
NvrSettings = _nvrSettings
};

File.WriteAllText(@".\Config.json", JsonConvert.SerializeObject(rootObject, Formatting.Indented));
MessageBox.Show("NVR Loader Config Saved Successfully", "SAVED");
Close();
Application.Exit();

}
else
{
MessageBox.Show("INVALID IP ADDRESS", "INVALID IP ADDRESS");
}
}
public bool IsAddressValid(string addrString)
// Check IP is Valid
{
string pattern = @"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
Regex regex = new Regex(pattern);
return regex.IsMatch(addrString);

//IPAddress address;
//return IPAddress.TryParse(addrString, out address) && address.ToString() == addrString;
}
}

}
9 replies
CC#
Created by Christian Dale on 1/30/2024 in #help
Extracting JSON Element into a ComboBox Data source
when i try that way it is givng me this error. 'Unexpected character encountered while parsing number: . Path '', line 1, position 1.'
9 replies
CC#
Created by Christian Dale on 1/22/2024 in #help
Using Instances in Multiple Locations
It is the Output that i would need to use multiple times not the Command. If i run the command multiple times it loads the driver multiple times.
15 replies
CC#
Created by Christian Dale on 1/22/2024 in #help
Using Instances in Multiple Locations
what would the Return type be?
15 replies
CC#
Created by Christian Dale on 1/22/2024 in #help
Using Instances in Multiple Locations
where in the Code would i need to pozition it for it to be classed as a member of the Form Class.
15 replies
CC#
Created by Christian Dale on 1/22/2024 in #help
Using Instances in Multiple Locations
So make it a Global Variable.
15 replies
CC#
Created by Christian Dale on 1/19/2024 in #help
Using same Implimentations within 2 Locations
The Code i want to use is the Driver implimentation.
4 replies