private void AddLocation(UltraListViewItem lvi) { LocationsDAO lwDataAccess = new LocationsDAO(); // Create the AssetGroup for this location noting that we need to add the root item name to all // locations created as this will be missing from the import text string oldLocation = lvi.Text; AssetGroup newGroup = new AssetGroup(); newGroup.GroupType = AssetGroup.GROUPTYPE.userlocation; if (oldLocation == "") { newGroup.FullName = _rootName; } else { newGroup.FullName = _rootName + AssetGroup.LOCATIONDELIMITER + lvi.Text; } newGroup.StartIP = lvi.SubItems[0].Text; newGroup.EndIP = lvi.SubItems[1].Text; // Add this group and get its database index newGroup.Add(); // Now we need to add the asset (if there is one defined) string assetName = lvi.SubItems[2].Text; if (assetName != "") { Asset newAsset = new Asset(); newAsset.LocationID = newGroup.GroupID; newAsset.Name = assetName; newAsset.Add(); } }
protected void btnSubmit_Click(Object Sender, EventArgs e) { int intRoom = GetID(txtDepotRoom.Text, "cv_depot_rooms"); if (intRoom == 0) { oDepotRoom.Add(txtDepotRoom.Text, 1); intRoom = GetID(txtDepotRoom.Text, "cv_depot_rooms"); } int intShelf = GetID(txtShelf.Text, "cv_shelfs"); if (intShelf == 0) { oShelf.Add(txtShelf.Text, 1); intShelf = GetID(txtShelf.Text, "cv_shelfs"); } int intModel = Int32.Parse(ddlModel.SelectedItem.Value); DataSet ds = oAsset.Get(txtSerial.Text, intModel); if (ds.Tables[0].Rows.Count > 0) { Response.Redirect(oPage.GetFullLink(intPage) + "?pid=" + Request.QueryString["pid"] + "&tid=" + Request.QueryString["tid"] + "&mid=" + ddlModel.SelectedItem.Value + "&duplicate=true"); } else { int intAsset = oAsset.Add("", intModel, txtSerial.Text, txtAsset.Text, (int)AssetStatus.Arrived, intProfile, DateTime.Now, 0, 1); oAsset.AddNetwork(intAsset, "", (int)AssetStatus.Available, intProfile, DateTime.Now, Int32.Parse(ddlDepot.SelectedItem.Value), intRoom, intShelf, Int32.Parse(txtPorts.Text), 0, 0, 0, 0, 0, ""); Response.Redirect(oPage.GetFullLink(intPage) + "?pid=" + Request.QueryString["pid"] + "&tid=" + Request.QueryString["tid"] + "&mid=" + ddlModel.SelectedItem.Value + "&save=true"); } }
protected void btnAdd_Click(Object Sender, EventArgs e) { int intRack = Int32.Parse(Request.Form[hdnParent.UniqueID]); int intModel = Int32.Parse(Request.Form[hdnModel.UniqueID]); int intClass = 0; Int32.TryParse(Request.Form[ddlClass.SelectedItem.Value], out intClass); int intEnv = 0; Int32.TryParse(Request.Form[hdnEnvironment.UniqueID], out intEnv); DataSet dsAsset = oAsset.Get(txtSerial.Text, intModel); if (dsAsset.Tables[0].Rows.Count > 0) { intID = Int32.Parse(dsAsset.Tables[0].Rows[0]["id"].ToString()); } if (intID == 0) { intID = oAsset.Add("", intModel, txtSerial.Text, txtAsset.Text, (int)AssetStatus.InStock, intProfile, DateTime.Now, (int)AssetAttribute.Ok, 1); oAsset.UpdateStatus(intID, txtName.Text, (int)AssetStatus.InUse, intProfile, DateTime.Now); oAsset.AddSwitch(intID, intClass, intEnv, intRack, txtRackPosition.Text, Int32.Parse(txtBlades.Text), Int32.Parse(txtPorts.Text), 0, (chkIsIOS.Checked ? 1 : 0), (chkIsNexus.Checked ? 1 : 0), (chkEnabled.Checked ? 1 : 0)); } else { oAsset.Update(intID, intModel, txtSerial.Text, txtAsset.Text, (int)AssetAttribute.Ok); oAsset.UpdateStatus(intID, txtName.Text, (int)AssetStatus.InUse, intProfile, DateTime.Now); oAsset.UpdateSwitch(intID, intClass, intEnv, intRack, txtRackPosition.Text, Int32.Parse(txtBlades.Text), Int32.Parse(txtPorts.Text), 0, (chkIsIOS.Checked ? 1 : 0), (chkIsNexus.Checked ? 1 : 0), (chkEnabled.Checked ? 1 : 0)); } Response.Redirect(Request.Path); }
protected void btnGo_Click(Object Sender, EventArgs e) { int intAnswer = 0; if (radEnvironment.SelectedItem.Value == "TEST") { intAnswer = intHostTest; } if (radEnvironment.SelectedItem.Value == "PROD") { intAnswer = intHostProd; } if (intAnswer > 0) { string strName = txtName.Text.ToUpper(); string strName1 = strName.Substring(0, 5); strName = strName.Substring(5); string strName2 = strName.Substring(0, 3); strName = strName.Substring(3); string strName3 = strName.Substring(0, 2); strName = strName.Substring(2); string strName4 = strName.Substring(0, 1); strName = strName.Substring(1); int intName = 0; DataSet dsNames = SqlHelper.ExecuteDataset(dsn, CommandType.Text, "SELECT * FROM cv_servernames WHERE prefix1 = '" + strName1 + "' AND prefix2 = '" + strName2 + "' AND sitecode = '" + strName3 + "' AND name1 = '" + strName4 + "' AND name2 = '" + strName + "' AND deleted = 0"); if (dsNames.Tables[0].Rows.Count > 0) { intName = Int32.Parse(dsNames.Tables[0].Rows[0]["id"].ToString()); } else { ServerName oServerName = new ServerName(0, dsn); intName = oServerName.Add(0, strName1, strName2, strName3, strName4, strName, 0, txtSerial.Text, 0); } Forecast oForecast = new Forecast(0, dsn); int intClass = Int32.Parse(oForecast.GetAnswer(intAnswer, "classid")); int intEnv = Int32.Parse(oForecast.GetAnswer(intAnswer, "environmentid")); int intAddress = Int32.Parse(oForecast.GetAnswer(intAnswer, "addressid")); int intNumber = (int)SqlHelper.ExecuteScalar(dsn, CommandType.Text, "SELECT MAX(number) FROM cv_servers WHERE answerid = " + intAnswer.ToString()); intNumber = intNumber + 1; DataSet dsServers = SqlHelper.ExecuteDataset(dsn, CommandType.Text, "SELECT * FROM cv_servers WHERE answerid = " + intAnswer.ToString()); DataRow drServer = dsServers.Tables[0].Rows[0]; int intOldServer = Int32.Parse(drServer["id"].ToString()); SqlHelper.ExecuteNonQuery(dsn, CommandType.Text, "INSERT INTO cv_servers VALUES(" + drServer["requestid"] + "," + drServer["answerid"] + "," + drServer["modelid"] + "," + drServer["csmconfigid"] + "," + drServer["clusterid"] + "," + intNumber.ToString() + "," + drServer["osid"] + "," + drServer["spid"] + "," + drServer["templateid"] + "," + drServer["domainid"] + "," + drServer["test_domainid"] + "," + drServer["infrastructure"] + "," + drServer["dr"] + "," + drServer["dr_exist"] + ",'" + drServer["dr_name"] + "'," + drServer["dr_consistency"] + "," + drServer["dr_consistencyid"] + "," + drServer["configured"] + "," + drServer["local_storage"] + "," + drServer["accounts"] + "," + drServer["fdrive"] + ",0,0," + intName.ToString() + ",'" + drServer["dhcp"] + "',0,999,0,0,null,null,null,0,getdate(),getdate(),0)"); int intServer = (int)SqlHelper.ExecuteScalar(dsn, CommandType.Text, "SELECT TOP 1 id FROM cv_servers WHERE answerid = " + intAnswer.ToString() + " ORDER BY created DESC"); Asset oAsset = new Asset(0, dsnAsset); int intAsset = oAsset.Add("", Int32.Parse(Request.Form[hdnParent.UniqueID]), txtSerial.Text.ToUpper(), txtAsset.Text.ToUpper(), (int)AssetStatus.Arrived, intProfile, DateTime.Now, 0, 1); oAsset.AddServer(intAsset, (int)AssetStatus.Available, intProfile, DateTime.Now, intClass, intEnv, intAddress, GetRoom(txtRoom.Text), GetRack(txtRack.Text), txtRackPos.Text, txtILO.Text, txtSerial.Text.ToUpper(), txtMAC.Text, Int32.Parse(txtVlan.Text), 0); oAsset.AddStatus(intAsset, txtName.Text.ToUpper(), (int)AssetStatus.InUse, intProfile, DateTime.Now); Servers oServer = new Servers(0, dsn); oServer.AddAsset(intServer, intAsset, intClass, intEnv, 0, 0); lblDone.Text = "<img src='/images/bigcheck.gif' border='0' align='absmiddle'/> <b>Finished!</b> ClearView added the host"; } else { lblDone.Text = "<img src='/images/bigerror.gif' border='0' align='absmiddle'/> <b>Error!</b> Select a Type!"; } }
private void AddAcfUnit(Asset asset, DateTime paymentDay, string name, string value) { AcfDataset acfDataset = Dataset.FirstOrDefault(x => x.PaymentDay == paymentDay); if (acfDataset == null) { acfDataset = new AcfDataset(paymentDay); Dataset.Add(acfDataset); } AcfAsset acfAsset = Asset.FirstOrDefault(x => x.Asset.Id == asset.Id); if (acfAsset == null) { acfAsset = new AcfAsset(asset); Asset.Add(acfAsset); } AcfUnit acfUnit = null; if (acfDataset.Exists(asset.Id)) { acfUnit = acfDataset.Get(asset.Id); if (!acfAsset.Exists(paymentDay)) { acfAsset.Add(acfUnit); } } else if (acfAsset.Exists(paymentDay)) { acfUnit = acfAsset.Get(paymentDay); if (!acfDataset.Exists(asset.Id)) { acfDataset.Add(acfUnit); } } else { acfUnit = new AcfUnit(asset, paymentDay); acfDataset.Add(acfUnit); acfAsset.Add(acfUnit); } acfUnit.SetValue(name, value); }
public bool Add(Gage gage) { using (SqlConnection conn = new SqlConnection(Common.SQLHelper.Asset_strConn)) { conn.Open(); SqlTransaction sqlTransaction = conn.BeginTransaction(); try { if (Asset.GetBy(gage.AssetID) != null) { throw new Exception("资产编号已存在"); } Asset asset = new Asset(); asset.AssetID = gage.AssetID.Trim(); asset.AssetName = gage.AssetName; asset.AssetCategory = "Gage"; asset.CurrentWhereOrganization = gage.CurrentWhereOrganization; asset.Status = "在库"; asset.Remark = gage.Remark; asset.StorageDate = DateTime.Now; asset.CurrentWhereSpot = gage.CurrentWhereSpot; asset.Department = gage.Department; gage.FK_AssetID = asset.AssetID; //if (gageDetail.StandardAdjustType == "外校" || gageDetail.StandardAdjustType == "内校") // gageDetail.NextAdjustDate = ((DateTime)gageDetail.AdjustBaseDate).AddDays(Convert.ToDouble(gageDetail.AdjustPeriod)); asset.sqlTransaction = gage.sqlTransaction = sqlTransaction; asset.Add(); gage.Add(); sqlTransaction.Commit(); return(true); } catch { sqlTransaction.Rollback(); throw; } } }
protected void AddUpdateAssets() { int intOrderId = 0; intOrderId = Int32.Parse(hdnOrderId.Value); oAssetOrder.UpdateAssetOrderDepotDateReceived(intOrderId, Int32.Parse(ddlDepot.SelectedValue), DateTime.Parse(txtDateReceived.Text.Trim()), intProfile); foreach (DataListItem dlItem in dlAssetList.Items) { HiddenField hdnAssetId = (HiddenField)dlItem.FindControl("hdnAssetId"); CheckBox chkSelectAsset = (CheckBox)dlItem.FindControl("chkSelectAsset"); CheckBox chkAssetReturn = (CheckBox)dlItem.FindControl("chkAssetReturn"); Label lblAssetListSerialNo = (Label)dlItem.FindControl("lblAssetListSerialNo"); Label lblAssetListAssetTag = (Label)dlItem.FindControl("lblAssetListAssetTag"); Label lblAssetListAssetScanDateTime = (Label)dlItem.FindControl("lblAssetListAssetScanDateTime"); TextBox txtAssetListComments = (TextBox)dlItem.FindControl("txtAssetListComments"); if (chkSelectAsset.Checked == true) { if (hdnAssetId.Value != "")//Update Asset { oAsset.UpdateReturned(Int32.Parse(hdnAssetId.Value), (chkAssetReturn.Checked == true ? 1 : 0), txtAssetListComments.Text); } else //Insert Asset { int intAsset = oAsset.Add(Int32.Parse(hdnOrderId.Value), Int32.Parse(ddlDepot.SelectedValue), Int32.Parse(hdnModel.Value), lblAssetListSerialNo.Text.Trim().ToUpper(), lblAssetListAssetTag.Text.Trim().ToUpper(), (int)AssetStatus.Arrived, intProfile, DateTime.Parse(lblAssetListAssetScanDateTime.Text), 0, 1, (chkAssetReturn.Checked == true?1:0), txtAssetListComments.Text); hdnAssetId.Value = intAsset.ToString(); } } } }
private void btnCommit_Click(object sender, EventArgs e) { CheckData(); if (!GetData()) { return; } M_Asset mas = new M_Asset(); mas.Personal = personalAsset; mas.Credit = creditAsset; mas.UpdateTime = date; Asset.Add(mas); if (SetAsset != null) { SetAsset(); } this.Close(); }
private void AddAsset() { AssetDAO lwDataAccess = new AssetDAO(); _asset.Name = this.tbAssetName.Text; // Set the asset type AssetType assetType = cbAssetType.Value as AssetType; _asset.AssetTypeID = assetType.AssetTypeID; // Do we have a name for the asset and is it unique? if ((_asset.Name == "") || (lwDataAccess.AssetFind(_asset) != 0)) { MessageBox.Show("You must specify a unique name for this asset", "Invalid Asset Name"); this.DialogResult = DialogResult.None; return; } // OK - unique asset so create it _asset.AssetID = _asset.Add(); }
protected void btnAdd_Click(Object Sender, EventArgs e) { if (hdnLocationId.Value == "0") { hdnLocationId.Value = "0"; } if (hdnRoomId.Value == "0") { hdnRoomId.Value = "0"; } if (Request.Form[hdnId.UniqueID] == "0") { int intAsset = 0; intAsset = oAsset.Add(0, 0, Int32.Parse(ddlModel.SelectedValue), txtAssetSerial.Text.Trim(), txtAssetTag.Text.Trim(), (int)AssetStatus.Available, intProfile, DateTime.Now, 0, 1, 0, ""); //oRacks.Add(txtName.Text, (chkEnabled.Checked ? 1 : 0)); oRacks.Add(intAsset, txtName.Text, Int32.Parse(hdnRoomId.Value), (chkEnabled.Checked ? 1 : 0), intProfile); } else { oAsset.Update(Int32.Parse(hdnAssetId.Value), Int32.Parse(ddlModel.SelectedValue), txtAssetSerial.Text.Trim(), txtAssetTag.Text.Trim(), 0); oRacks.Update(Int32.Parse(Request.Form[hdnId.UniqueID]), Int32.Parse(hdnAssetId.Value), txtName.Text.Trim(), Int32.Parse(hdnRoomId.Value), (chkEnabled.Checked ? 1 : 0), intProfile); } if (Request.Form[hdnOrder.UniqueID] != "") { string strOrder = Request.Form[hdnOrder.UniqueID]; int intCount = 0; while (strOrder != "") { intCount++; int intId = Int32.Parse(strOrder.Substring(0, strOrder.IndexOf("&"))); strOrder = strOrder.Substring(strOrder.IndexOf("&") + 1); oRacks.UpdateOrder(intId, intCount); } } Response.Redirect(Request.Path); }
protected void btnUpload_Click(Object Sender, EventArgs e) { int intSuccess = 0; int intDuplicate = 0; int intError = 0; ModelsProperties oModelsProperties = new ModelsProperties(0, dsn); if (oFile.PostedFile != null && oFile.FileName != "") { string strPhysical = oVariable.DocumentsFolder() + "xml\\"; if (Directory.Exists(strPhysical) == false) { lblResults.Text = "<b>Created XML directory "" + strPhysical + ""...SUCCESS!</b><br/><br/>"; Directory.CreateDirectory(strPhysical); } else { lblResults.Text = "<b>XML directory "" + strPhysical + "" already exists...</b><br/><br/>"; } lblResults.Text += "<b>Results of File "" + oFile.FileName + ""</b><br/>"; string strFile = strPhysical + oFile.FileName; oFile.PostedFile.SaveAs(strFile); DataSet ds = new DataSet(); ds.ReadXml(strFile); switch (oFile.FileName[0]) { case 'E': // Existing foreach (DataRow dr in ds.Tables[0].Rows) { int intModel = 0; try { intModel = Int32.Parse(dr["svrModel"].ToString()); } catch { intModel = oModelsProperties.Get(dr["svrModel"].ToString()); } if (intModel > 0) { if (oAsset.Get(dr["svrSerial"].ToString().Trim().ToUpper(), intModel).Tables[0].Rows.Count > 0) { lblResults.Text += "DUPLICATE: " + dr["svrSerial"].ToString().Trim().ToUpper() + " [" + dr["svrAsset"].ToString().Trim().ToUpper() + "]<br/>"; intDuplicate++; } else { int intAsset = oAsset.Add("", intModel, dr["svrSerial"].ToString().Trim().ToUpper(), dr["svrAsset"].ToString().Trim().ToUpper(), (int)AssetStatus.Arrived, -1, DateTime.Now, 0, 1); lblResults.Text += "success: " + dr["svrSerial"].ToString().Trim().ToUpper() + " [" + dr["svrAsset"].ToString().Trim().ToUpper() + "]<br/>"; intSuccess++; } } else { ErrorMessage(dr["svrModel"].ToString()); lblResults.Text += "### ERROR ###: " + dr["svrModel"].ToString().Trim().ToUpper() + " does not exist<br/>"; intError++; } } lblResults.Text += "<p><hr size=1 noshade/></p>"; lblResults.Text += "Successful: " + intSuccess.ToString() + "<br/>"; lblResults.Text += "Duplicates: " + intDuplicate.ToString() + "<br/>"; lblResults.Text += "Errors: " + intError.ToString() + "<br/>"; break; case 'S': // New foreach (DataRow dr in ds.Tables[0].Rows) { int intModel = 0; try { intModel = Int32.Parse(dr["svrModel"].ToString()); } catch { intModel = oModelsProperties.Get(dr["svrModel"].ToString()); } if (intModel > 0) { if (oAsset.Get(dr["svrSerial"].ToString().Trim().ToUpper(), intModel).Tables[0].Rows.Count > 0) { lblResults.Text += "DUPLICATE: " + dr["svrSerial"].ToString().Trim().ToUpper() + " [" + dr["svrAsset"].ToString().Trim().ToUpper() + "]<br/>"; intDuplicate++; } else { int intAsset = oAsset.Add(dr["svrTracking"].ToString().Trim().ToUpper(), intModel, dr["svrSerial"].ToString().Trim().ToUpper(), dr["svrAsset"].ToString().Trim().ToUpper(), (int)AssetStatus.Arrived, -1, DateTime.Now, 0, 1); oOrder.UpdateReceived(dr["svrTracking"].ToString().Trim().ToUpper(), 1); lblResults.Text += "success: " + dr["svrSerial"].ToString().Trim().ToUpper() + " [" + dr["svrAsset"].ToString().Trim().ToUpper() + "]<br/>"; intSuccess++; } } else { ErrorMessage(dr["svrModel"].ToString()); lblResults.Text += "### ERROR ###: " + dr["svrModel"].ToString().Trim().ToUpper() + " does not exist<br/>"; intError++; } } lblResults.Text += "<p><hr size=1 noshade/></p>"; lblResults.Text += "Successful: " + intSuccess.ToString() + "<br/>"; lblResults.Text += "Duplicates: " + intDuplicate.ToString() + "<br/>"; lblResults.Text += "Errors: " + intError.ToString() + "<br/>"; break; default: lblResults.Text = "Invalid XML File"; break; } } }
public void NetworkDiscoveryCompleteHandler(object sender, DataEventArgs <List <string[]> > e) { try { LocationsDAO lwDataAccess = new LocationsDAO(); string macAddress = String.Empty; string vendor = String.Empty; string ipAddress = String.Empty; // We need to get the root item as all of the domains need to be parented to this DataTable table = lwDataAccess.GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.domain)); AssetGroup rootGroup = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.domain); // Get the child domains - as domains are single level we do not need to recurse rootGroup.Populate(false, false, true); // We'll loop through the domains first and add then to the database recovering their ids so that // we only have to do this once. for (int i = 0; i < e.Data.Count; i++) { string assetName = e.Data[i][0]; string groupName = e.Data[i][1]; // Does this domain already exist? AssetGroup childGroup = rootGroup.IsChildGroup(groupName); // No - add it as a new group both to the database and to the parent if (childGroup == null) { childGroup = new AssetGroup(AssetGroup.GROUPTYPE.domain); childGroup.Name = groupName; childGroup.ParentID = rootGroup.GroupID; childGroup.GroupID = lwDataAccess.GroupAdd(childGroup); rootGroup.Groups.Add(childGroup); } try { // Recover the IP address for the asset ipAddress = Utility.GetIpAddress(assetName); // try to get the MAC address and vendor from IP IPAddress hostIPAddress = IPAddress.Parse(ipAddress); byte[] ab = new byte[6]; int len = ab.Length; int r = SendARP((int)hostIPAddress.Address, 0, ab, ref len); macAddress = BitConverter.ToString(ab, 0, 6); } catch (Exception ex) { // if we hit an invalid IP error here we can just log and carry on log.Error(String.Format("Error {0} with IP address [{1}]", ex.Message, ipAddress)); } if (macAddress != String.Empty) { using (System.IO.StreamReader sr = new System.IO.StreamReader(System.IO.Path.Combine(Application.StartupPath, "oui.txt"))) { string line; while ((line = sr.ReadLine()) != null) { if (line.StartsWith(macAddress.Substring(0, 8))) { if (line.Substring(18).ToUpper().StartsWith("APPLE")) { vendor = line.Substring(18); } break; } } } } // Now that we have the ID of the group (even if we just added the group) we can now // add the asset to the database also. Asset newAsset = new Asset(); newAsset.Name = assetName; newAsset.MACAddress = macAddress.Replace('-', ':'); newAsset.Make = vendor; AssetList assetList = new AssetList(new AssetDAO().GetAssets(0, AssetGroup.GROUPTYPE.userlocation, false), true); bool bUpdateAsset = true; foreach (Asset existingAsset in assetList) { if (assetName == existingAsset.Name) { // this asset already exists - only need to check if domain or IP have changed // if they have, send it away to be updated if (existingAsset.IPAddress != ipAddress || existingAsset.DomainID != childGroup.GroupID) { newAsset = existingAsset; newAsset.IPAddress = newAsset.IPAddress != ipAddress ? ipAddress : newAsset.IPAddress; newAsset.DomainID = newAsset.DomainID != childGroup.GroupID ? childGroup.GroupID : newAsset.DomainID; } else { // asset exists, nothing has changed so don't process bUpdateAsset = false; } break; } } if (bUpdateAsset) { newAsset.DomainID = childGroup.GroupID; newAsset.IPAddress = ipAddress; // Add the asset newAsset.Add(); } // Does this asset already exist? //if (rootGroup.FindAsset(assetName) == null) //{ // newAsset.DomainID = childGroup.GroupID; // newAsset.IPAddress = ipAddress; // // Add the asset // newAsset.Add(); //} } } catch (Exception ex) { logger.Error(ex.Message); } //WorkItem.ExplorerView.RefreshView(); //WorkItem.TabView.RefreshView(); }
protected void btnImport_Click(Object Sender, EventArgs e) { int intSuccess = 0; int intInvalid = 0; int intOverwrite = 0; if (oFile.PostedFile != null && oFile.FileName != "") { oVariable = new Variables(intEnvironment); string strPhysical = oVariable.DocumentsFolder() + "\\imports\\"; if (Directory.Exists(strPhysical) == false) { Directory.CreateDirectory(strPhysical); } DateTime _now = DateTime.Now; string strNow = _now.Day.ToString() + _now.Month.ToString() + _now.Year.ToString() + _now.Hour.ToString() + _now.Minute.ToString() + _now.Second.ToString() + _now.Millisecond.ToString(); string strFile = strPhysical + strNow + ".xls"; oFile.PostedFile.SaveAs(strFile); string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFile + ";Extended Properties=Excel 8.0;"; OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [DoNotRename$]", strConn); DataSet ds = new DataSet(); myCommand.Fill(ds, "ExcelInfo"); foreach (DataRow dr in ds.Tables[0].Rows) { if (dr[0].ToString().Trim() == "") { break; } else { bool boolInvalid = false; string strModel = dr[0].ToString().Trim(); string strPlatform = strModel.Substring(0, strModel.IndexOf("-")).Trim(); int intPlatform = GetPlatform(strPlatform); string strSerial = dr[1].ToString().Trim(); if (strModel.IndexOf("-") > -1) { strModel = strModel.Substring(strModel.IndexOf("-") + 1).Trim(); if (strModel.IndexOf("-") > -1) { string strType = strModel.Substring(0, strModel.IndexOf("-")).Trim(); int intType = GetType(strType, intPlatform); int intModel = 0; if (strModel.IndexOf("-") > -1) { strModel = strModel.Substring(strModel.IndexOf("-") + 1).Trim(); intModel = GetModel(strModel, intType); string strAsset = dr[2].ToString().Trim(); int intDepot = GetDepot(dr[3].ToString().Trim()); int intDepotRoom = GetDepotRoom(dr[4].ToString().Trim()); int intShelfNumber = GetShelf(dr[5].ToString().Trim()); string strProjectNumber = dr[6].ToString().Trim(); string strPONumber = dr[7].ToString().Trim(); string strReceivedOn = dr[8].ToString().Trim(); DateTime datReceived = DateTime.Now; if (strReceivedOn != "") { datReceived = DateTime.Parse(strReceivedOn); } DataSet dsExists = oAsset.Get(strSerial, intModel); int intAsset = 0; if (dsExists.Tables[0].Rows.Count > 0) { if (chkOverwrite.Checked == true) { intOverwrite++; intAsset = Int32.Parse(dsExists.Tables[0].Rows[0]["id"].ToString()); intSuccess++; oAsset.UpdateNetwork(intAsset, "", (int)AssetStatus.Available, intProfile, datReceived, intDepot, intDepotRoom, intShelfNumber, 0, 0, 0, 0, 0, 0, ""); sb.Append("<tr><td><img src=\""); sb.Append(oVariable.ImageURL()); sb.Append("/images/check.gif\" border=\"0\" align=\"absmiddle\"/></td><td>Asset "); sb.Append(strSerial); sb.Append(" ("); sb.Append(dr[0].ToString().Trim()); sb.Append(") already exists and was successfully overwritten</td></tr>"); } else { sb.Append("<tr><td><img src=\""); sb.Append(oVariable.ImageURL()); sb.Append("/images/alert.gif\" border=\"0\" align=\"absmiddle\"/></td><td>Asset "); sb.Append(strSerial); sb.Append(" ("); sb.Append(dr[0].ToString().Trim()); sb.Append(") already exists and was NOT overwritten</td></tr>"); } } else { intSuccess++; intAsset = oAsset.Add("", intModel, strSerial, strAsset, (int)AssetStatus.Arrived, intProfile, datReceived, 0, 1); oAsset.AddNetwork(intAsset, "", (int)AssetStatus.Available, intProfile, datReceived, intDepot, intDepotRoom, intShelfNumber, 0, 0, 0, 0, 0, 0, ""); sb.Append("<tr><td><img src=\""); sb.Append(oVariable.ImageURL()); sb.Append("/images/check.gif\" border=\"0\" align=\"absmiddle\"/></td><td>Asset "); sb.Append(strSerial); sb.Append(" ("); sb.Append(dr[0].ToString().Trim()); sb.Append(") was imported successfully</td></tr>"); } } else { boolInvalid = true; } } else { boolInvalid = true; } } else { boolInvalid = true; } if (boolInvalid == true) { intInvalid++; sb.Append("<tr><td><img src=\""); sb.Append(oVariable.ImageURL()); sb.Append("/images/error.gif\" border=\"0\" align=\"absmiddle\"/></td><td>There was a problem with the information provided for asset serial# "); sb.Append(strSerial); sb.Append(" ("); sb.Append(dr[0].ToString().Trim()); sb.Append(")</td></tr>"); } } } sb.Append("<tr><td colspan=\"2\"> </td></tr><tr><td colspan=\"2\"><b><img src=\""); sb.Append(oVariable.ImageURL()); sb.Append("/images/bigCheck.gif\" border=\"0\" align=\"absmiddle\"/> Successfully Imported "); sb.Append(intSuccess); sb.Append(" Assets, Error Importing "); sb.Append(intInvalid); sb.Append(" Assets, Overwrote "); sb.Append(intOverwrite); sb.Append(" Assets</b></td></tr>"); sb.Insert(0, "<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" style=\"" + oVariable.DefaultFontStyle() + "\">"); sb.Append("</table>"); Functions oFunction = new Functions(intProfile, dsn, intEnvironment); Users oUser = new Users(intProfile, dsn); strResults = sb.ToString(); string strEMailIdsBCC = oFunction.GetGetEmailAlertsEmailIds("EMAILGRP_INVENTORY_MANAGER"); oFunction.SendEmail("ClearView Asset Import", oUser.GetName(intProfile), "", strEMailIdsBCC, "ClearView Asset Import", "<p>" + strResults + "</p>", true, false); } Response.Redirect(oPage.GetFullLink(intPage) + "?pid=" + Request.QueryString["pid"] + "&import=true"); }
protected void btnAdd_Click(Object Sender, EventArgs e) { if (hdnZoneId.Value == "") { hdnZoneId.Value = "0"; } if (Request.Form[hdnId.UniqueID] == "0") { DataSet dsRack = oRacks.Gets(Int32.Parse(hdnZoneId.Value), txtName.Text.Trim()); if (dsRack.Tables[0].Rows.Count > 0) { Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "DuplicateRack", "<script type=\"text/javascript\">alert('Rack " + txtName.Text + " already exists for selected zone.');<" + "/" + "script>"); } else { int intAsset = 0; intAsset = oAsset.Add(0, 0, Int32.Parse(ddlModel.SelectedValue), txtAssetSerial.Text.Trim(), txtAssetTag.Text.Trim(), (int)AssetStatus.Available, intProfile, DateTime.Now, 0, 1, 0, ""); oRacks.Add(txtName.Text, intAsset, Int32.Parse(hdnZoneId.Value), txtDescription.Text.Trim(), (chkEnabled.Checked ? 1 : 0)); } } else { Boolean blDuplicate = false; DataSet dsRack = oRacks.Gets(Int32.Parse(hdnZoneId.Value), txtName.Text.Trim()); if (dsRack.Tables[0].Rows.Count > 0) { foreach (DataRow drRack in dsRack.Tables[0].Rows) { if (drRack["RackId"].ToString() != Request.Form[hdnId.UniqueID].ToString() && blDuplicate == false) { blDuplicate = true; Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "DuplicateRack", "<script type=\"text/javascript\">alert('Rack " + txtName.Text + " already exists for selected zone.');<" + "/" + "script>"); } } } if (blDuplicate == false) { if (hdnAssetId.Value == "" || hdnAssetId.Value == "0") { int intAsset = 0; intAsset = oAsset.Add(0, 0, Int32.Parse(ddlModel.SelectedValue), txtAssetSerial.Text.Trim(), txtAssetTag.Text.Trim(), (int)AssetStatus.Available, intProfile, DateTime.Now, 0, 1, 0, ""); } else { oAsset.Update(Int32.Parse(hdnAssetId.Value), Int32.Parse(ddlModel.SelectedValue), txtAssetSerial.Text.Trim(), txtAssetTag.Text.Trim(), 0); } oRacks.Update(Int32.Parse(Request.Form[hdnId.UniqueID]), txtName.Text.Trim(), Int32.Parse(hdnAssetId.Value), Int32.Parse(hdnZoneId.Value), txtDescription.Text.Trim(), (chkEnabled.Checked ? 1 : 0)); } } if (Request.Form[hdnOrder.UniqueID] != "") { string strOrder = Request.Form[hdnOrder.UniqueID]; int intCount = 0; while (strOrder != "") { intCount++; int intId = Int32.Parse(strOrder.Substring(0, strOrder.IndexOf("&"))); strOrder = strOrder.Substring(strOrder.IndexOf("&") + 1); //oRacks.UpdateOrder(intId, intCount); } } LoopRepeater(); //Response.Redirect(Request.Path); }
public void InsertComputer(string assetName, string groupName, string ipAddress, string macAddress) { LocationsDAO lwDataAccess = new LocationsDAO(); SettingsDAO lSettingsDao = new SettingsDAO(); // We need to get the root item as all of the domains need to be parented to this System.Data.DataTable table = lwDataAccess.GetGroups(new AssetGroup(AssetGroup.GROUPTYPE.domain)); AssetGroup rootGroup = new AssetGroup(table.Rows[0], AssetGroup.GROUPTYPE.domain); // Get the child domains - as domains are single level we do not need to recurse rootGroup.Populate(false, false, true); // We'll loop through the domains first and add then to the database recovering their ids so that // we only have to do this once. // Does this domain already exist? AssetGroup childGroup; lock (this) { childGroup = rootGroup.IsChildGroup(groupName); // No - add it as a new group both to the database and to the parent if (childGroup == null) { childGroup = new AssetGroup(AssetGroup.GROUPTYPE.domain); childGroup.Name = groupName; childGroup.ParentID = rootGroup.GroupID; childGroup.GroupID = lwDataAccess.GroupAdd(childGroup); rootGroup.Groups.Add(childGroup); } } string vendor = String.Empty; try { if (macAddress != String.Empty) { // // CMD IMPORTANT UNCOMMENT THESE LINES // using (System.IO.StreamReader sr = new System.IO.StreamReader(System.IO.Path.Combine(Application.StartupPath, "oui.txt"))) // { // string line; // while ((line = sr.ReadLine()) != null) // { // if (line.StartsWith(macAddress.Substring(0, 8))) // { // if (line.Substring(18).ToUpper().StartsWith("APPLE")) // { // vendor = line.Substring(18); // break; // } // } // } // } } } catch (FormatException) { } // Now that we have the ID of the group (even if we just added the group) we can now // add the asset to the database also. Asset newAsset = new Asset(); newAsset.Name = assetName; newAsset.MACAddress = macAddress.Replace('-', ':'); newAsset.Make = vendor; if (vendor.ToUpper().StartsWith("APPLE")) { // add as an Apple Device assetTypes.Populate(); AssetType parentAssetType = assetTypes.FindByName("Apple Devices"); if (parentAssetType == null) { // Now create a child of this asset type parentAssetType = new AssetType(); parentAssetType.Name = "Apple Devices"; parentAssetType.Auditable = false; parentAssetType.Icon = "apple.png"; parentAssetType.ParentID = 0; parentAssetType.Add(); // Update the internal list assetTypes.Add(parentAssetType); } assetTypes.Populate(); parentAssetType = assetTypes.FindByName("Apple Devices"); AssetType childAssetType = assetTypes.FindByName("Apple Device"); if (childAssetType == null) { // Now create a child of this asset type childAssetType = new AssetType(); childAssetType.Name = "Apple Device"; childAssetType.Auditable = false; childAssetType.Icon = parentAssetType.Icon; childAssetType.ParentID = parentAssetType.AssetTypeID; childAssetType.Add(); // Update the internal list assetTypes.Add(childAssetType); } assetTypes.Populate(); childAssetType = assetTypes.FindByName("Apple Device"); newAsset.AssetTypeID = childAssetType.AssetTypeID; } AssetList assetList = new AssetList(new AssetDAO().GetAssets(0, AssetGroup.GROUPTYPE.userlocation, false), true); bool bUpdateAsset = true; bool bSNMPAsset = false; bool bExistingAuditedAsset = false; foreach (Asset existingAsset in assetList) { if ((existingAsset.AgentVersion == "SNMP") && (existingAsset.IPAddress == ipAddress)) { bSNMPAsset = true; break; } if ((assetName == existingAsset.Name) && (groupName == existingAsset.Domain)) { // this asset already exists - only need to check if domain or IP have changed // if they have, send it away to be updated if (existingAsset.IPAddress != ipAddress || existingAsset.DomainID != childGroup.GroupID) { newAsset = existingAsset; newAsset.IPAddress = newAsset.IPAddress != ipAddress ? ipAddress : newAsset.IPAddress; newAsset.DomainID = newAsset.DomainID != childGroup.GroupID ? childGroup.GroupID : newAsset.DomainID; } else { // asset exists, nothing has changed so don't process bUpdateAsset = false; } break; } if (!bSNMPAsset && existingAsset.IPAddress == ipAddress && existingAsset.Domain != newAsset.Domain) { bExistingAuditedAsset = true; //check for any asset name change if so update asset with audittrail entry if (existingAsset.Name != assetName) { string strOldValue = existingAsset.Name; newAsset = existingAsset; newAsset.Name = assetName; newAsset.Update(); AuditTrailDAO objAuditTrailDAO = new AuditTrailDAO(); // Build a blank AuditTrailEntry AuditTrailEntry ate = CreateAteForAssetNameChange(newAsset); ate.Key = ate.Key + "|" + "Computer Name"; ate.OldValue = strOldValue; ate.NewValue = assetName; objAuditTrailDAO.AuditTrailAdd(ate); } } } if (bUpdateAsset && !bSNMPAsset && !bExistingAuditedAsset) { newAsset.Domain = childGroup.Name; newAsset.DomainID = childGroup.GroupID; newAsset.IPAddress = ipAddress; // Add the asset newAsset.Add(); if (lSettingsDao.GetSettingAsBoolean("AutoScanNetwork", false) && lSettingsDao.GetSettingAsBoolean("AutoScanDeployAgent", false)) { string scannerPath = System.IO.Path.Combine(Application.StartupPath, "scanners") + "\\auditagent\\default.xml"; System.IO.File.Copy(scannerPath, "AuditAgent\\AuditAgent.xml", true); Operation newOperation = new Operation(newAsset.AssetID, Operation.OPERATION.deployagent); newOperation.Add(); } } if (!bSNMPAsset) { Interlocked.Increment(ref _foundCounter); FireNetworkDiscoveryUpdate(new DiscoveryUpdateEventArgs(_foundCounter.ToString(), "Computer", _maximumCount, 0)); } }