public static char[] setupPacket(String command, String pUsername, String sequence, char encFlag, String message) { String strMessage = command + pUsername.PadRight(32, '\0'); if (command == "BCST" || command == "BACK") { // do nothing, default strMessage } else if (command == "MESG") { strMessage += sequence.PadLeft(5, '0') + encFlag + message.PadRight(140, '\0'); } else if (command == "MACK") { strMessage += sequence.PadLeft(5, '0'); } char[] partialMessage = strMessage.ToCharArray(0, strMessage.Length); char[] fullMessage = new char[strMessage.Length + 1]; partialMessage.CopyTo(fullMessage, 0); fullMessage[strMessage.Length] = '\0'; /* Garbage Collection */ partialMessage = null; strMessage = null; return fullMessage; }
public void ShowAnswer(int page, int index, String answer, int points) { if (page == 0) { StringBuilder sb = new StringBuilder(); sb.Append(answer); if (sb.Length < 10) { for (int i = 10 - sb.Length; i > 0; i--) { sb.Append(' '); } } sb.Append(' '); sb.AppendFormat("{0:00} ", points); (answerStackA.Children[index] as Label).Content = sb.ToString(); } else { StringBuilder sb = new StringBuilder(); sb.AppendFormat(" {0:00} ", points); sb.Append(answer.PadLeft(10)); (answerStackB.Children[index] as Label).Content = sb.ToString(); } }
/// <summary> /// 根据IDOC编号从SAP系统里读取一个idoc /// </summary> /// <param name="idocNumber"></param> /// <returns></returns> public Idoc GetIodcFromSapDataBase(String idocNumber) { SAPINT.Utils.ReadTable idocReadItem = null; SAPINT.Utils.ReadTable idocReadHeader = null; DataTable dtIdocItem = new DataTable(); DataTable dtIdocHeder = new DataTable(); idocNumber = idocNumber.TrimStart('0'); String criteria = idocNumber.PadLeft(16, '0'); criteria = String.Format("DOCNUM = '{0}'", criteria); String readTableFunction = ConfigFileTool.SAPGlobalSettings.GetReadTableFunction(); idocReadItem = new Utils.ReadTable(SystemName); idocReadItem.TableName = "EDID4"; idocReadItem.SetCustomFunctionName(readTableFunction); idocReadItem.AddCriteria(criteria); idocReadItem.Run(); dtIdocItem = idocReadItem.Result; if (dtIdocItem.Rows.Count == 0) { idocReadItem = new Utils.ReadTable(SystemName); idocReadItem.TableName = "EDID2"; idocReadItem.SetCustomFunctionName(readTableFunction); idocReadItem.AddCriteria(criteria); idocReadItem.Run(); dtIdocItem = idocReadItem.Result; } if (dtIdocItem.Rows.Count == 0) { idocReadItem = new Utils.ReadTable(SystemName); idocReadItem.TableName = "EDIDD_OLD"; idocReadItem.SetCustomFunctionName(readTableFunction); idocReadItem.AddCriteria(criteria); idocReadItem.Run(); dtIdocItem = idocReadItem.Result; } if (dtIdocItem.Rows.Count == 0) { throw new SAPException(String.Format("无法找到IDOC{0}明细", idocNumber)); } //读取IDOC头 idocReadHeader = new Utils.ReadTable(SystemName); idocReadHeader.TableName = "EDIDC"; idocReadHeader.SetCustomFunctionName(readTableFunction); idocReadHeader.AddCriteria(criteria); idocReadHeader.Run(); dtIdocHeder = idocReadHeader.Result; if (dtIdocHeder.Rows.Count != 1) { throw new SAPException(String.Format("无法找到IDOC{0}抬头定义", idocNumber)); } Idoc idoc = ProcessSingleIdocFromDataTable(dtIdocHeder, dtIdocItem); return idoc; }
static void Main() { Console.OutputEncoding = Encoding.UTF8; char c = '\u00A9'; string line = String.Empty; int linesCount = 3; for (int i = 0; i < linesCount; i++) { line = new String(c, 2 * i + 1); Console.WriteLine(line.PadLeft(linesCount + i)); } }
/* Ham AddResult muc dich de cong 2 chuoi tham so nguoi dung nhap vao * su dung cau lenh CanAdd de kiem tra chuoi co hop le hay khong */ public String AddResult(String x, String y) { /*Dieu chinh lai sao cho 2 chuoi nhap vao co cung do dai * nham de thuc hien phep cong, chuoi nao co do dai nho hon * se duoc bo sung vao nhung con so 0 */ if (x.Length > y.Length) { y=y.PadLeft(x.Length, '0'); } else { x=x.PadLeft(y.Length, '0'); } bool remember = false;// Bien nho, neu bien nho la true thi phep cong truoc cho ra ket qua > 10 int ix, iy; // Bien int dung de cong, phai thuc hien thao tac chuyen doi tu kieu char sang int String result = string.Empty; for (int i = x.Length - 1; i >= 0; i--) { /* Chuyen doi sang kieu int: * Theo bang ma ASCII thi giua '0' (kieu char) va so 0 * chenh lech nhau 48 don vi, vi vay de chuyen tu kieu char * sang int ta lay kieu char tru di 48 don vi */ ix = x[i] - 48; iy = y[i] - 48; /*Cac thao tac cong nhu ta cong thu cong */ int value = ix + iy; if (remember) { value += 1; } if (value >= 10) { result = result.Insert(0, (value - 10).ToString()); remember = true; } else { result = result.Insert(0, value.ToString()); remember = false; } } if (remember) { result = result.Insert(0,"1"); } return result; }
public void generaCodigoMaquina(baseNumerica contlocFile,CODOP codop,String contLocLabel) { baseNumerica contEtiqueta = new baseNumerica(contLocLabel); baseNumerica contLocNext = new baseNumerica(System.Convert.ToString(contlocFile.getNumberDecimal() + codop.getBytesTotales())); baseNumerica contLocNew = new baseNumerica("0"); fueraRango = false; int valor = contEtiqueta.getNumberDecimal() - contLocNext.getNumberDecimal(); if (valor < 0) { char[] caracteres = { '-' }; String tmp = System.Convert.ToString(valor); tmp = tmp.TrimStart(caracteres); contLocNew = new baseNumerica(tmp,1); tmp = contLocNew.getNumberHexadecimal(); xb = ""; for (int i = (tmp.Length) - (2*codop.getBytesPorCalcular()); i<tmp.Length;i++ ) { xb += tmp[i]; } } else { contLocNew = new baseNumerica(System.Convert.ToString(contEtiqueta.getNumberDecimal() - contLocNext.getNumberDecimal())); xb = contLocNew.getNumberHexadecimal(); xb = xb.PadLeft(2 * codop.getBytesPorCalcular(), '0'); } if(codop.getBytesPorCalcular() == 1) { if (!(contLocNew.getNumberDecimal() >= -128 && contLocNew.getNumberDecimal() <= 127)) { fueraRango = true; } } else { if (!(contLocNew.getNumberDecimal() >= -32768 && contLocNew.getNumberDecimal() <= 32767)) { fueraRango = true; } } }
protected String PrepareString(String s) { if(s == null) { s = _emptyString; } else if(s.Length > _arrayLength) { Console.Error.WriteLine("Warning: String value too wide for column; truncating."); if(_trimLeft) { s = s.Substring(s.Length - _arrayLength, _arrayLength); } else { s = s.Substring(0, _arrayLength); } } else if(s.Length < _arrayLength) { if(_padLeft) { s = s.PadLeft(_arrayLength, _padChar); } else { s = s.PadRight(_arrayLength, _padChar); } } return s; }
public static string ValidarFormularioBloco(String bloco) { if (bloco.Length == 1) { bloco = bloco.PadLeft(2, '0'); return bloco; } else { return bloco; } }
/// <summary> /// 数字型字符串右对齐,左补零 /// </summary> /// <returns></returns> public static String FillSpecifyWith0(String number, UInt16 width) { if (String.IsNullOrEmpty(number)) { number = String.Empty; } if (number.Length > width) { return number.Substring(0, width); } else { return number.PadLeft(width, '0'); } }
/// <summary> /// 数字对齐补足 /// </summary> /// <param name="src"></param> /// <param name="width"></param> /// <returns></returns> public static String FillSpecifyWidthFigure(String src, UInt16 width) { if (String.IsNullOrEmpty(src)) { return SpaceString(width); } if (src.Length > width) { return src.Substring(0, width); } else { return src.PadLeft(width); } }
public Request Append(String data, Int32 exactLength, TextJustification justification) { if (data.Length > exactLength) data = data.Substring(0, exactLength); else { if (data.Length < exactLength) { switch (justification) { case TextJustification.Left: data = data.PadRight(exactLength); break; case TextJustification.Center: var spaces = new String(' ', (exactLength - data.Length) / 2); data = String.Concat(spaces, data, spaces); break; default: data = data.PadLeft(exactLength); break; } } } return Append(data); }
internal static Color ReadColor(XmlNode node, String prop, Color dval) { Color t = dval; if (node != null) { XmlAttribute attr = node.Attributes[prop]; if (attr != null) { prop = (attr.Value ?? "").ToLower(); if (Regex.IsMatch(prop, "^[#]?[0123456789abcdef]{6,8}$")) { if (prop[0] == '#') { prop = prop.Substring(1); } if (prop.Length < 8) { prop = prop.PadLeft(8, 'f'); } t = Color.FromArgb(Convert.ToInt32(prop, 16)); } } } return t; }
public void setLongitudCuerpo(String longitudCuerpo) { char pad = '0'; this.longitudCuerpo = longitudCuerpo.PadLeft(4, pad); }
private byte[] CreateRequest(String terminalNo, int messageType, Command cmd, byte[] data, int dataLen) { /* General Message for Request * XX Length * ASCII Terminal Serial * XX Message Type * BCD SequenceNum * BCD Date * BCD Time * [Detail] * XX LRC */ Encoding encode = Encoding.GetEncoding(1254); List<byte> reqPacket = new List<byte>(); List<byte> msgPacket = new List<byte>(); int allLen = dataLen; this.command = cmd; this.data = data; this.sequence = (MainForm.SequenceNumber++) % MAX_PRCSS_SEC_NUM; //SEQUNCE reqPacket.AddRange(MessageBuilder.HexToByteArray(GMPCommonTags.TAG_SEQUNCE)); reqPacket.Add((byte)GMPConstants.LEN_SEQUENCE); byte[] arrVal = MessageBuilder.ConvertIntToBCD(this.Sequence, GMPConstants.LEN_SEQUENCE); reqPacket.AddRange(arrVal); //DATE and TIME reqPacket.AddRange(MessageBuilder.GetDateTimeInBytes(DateTime.Now)); // Fiscal Command if (cmd != Command.NULL) { reqPacket.AddRange(MessageBuilder.HexToByteArray(FPUCommonTags.FPU_FISCAL_COMMAND)); reqPacket.Add((byte)GMPConstants.LEN_FISCAL_COMMAND); reqPacket.Add((byte)cmd); } if (dataLen > 0) { reqPacket.AddRange(data); } // Terminal ID msgPacket.AddRange(encode.GetBytes(terminalNo.PadLeft(12, ' '))); // Message TAG msgPacket.AddRange(MessageBuilder.HexToByteArray(messageType)); // Message length int msgLen = reqPacket.Count; msgPacket.AddRange(MessageBuilder.AddLength(msgLen)); // Message Data msgPacket.AddRange(reqPacket); // CRC short crc = MessageBuilder.CalculateCRC(msgPacket.ToArray(), 0, msgPacket.Count); msgPacket.Add((byte)(crc >> 8)); msgPacket.Add((byte)(crc)); // All Length allLen = msgPacket.Count; msgPacket.Insert(0, (byte)(allLen % 256)); msgPacket.Insert(0, (byte)(allLen / 256)); return msgPacket.ToArray(); }
/// <summary> /// Mutator for socialinsuranceNumber. /// </summary> /// <param name="socialInsNum">Value for socialInsuranceNumber</param> /// <returns>A boolean value indicating whether or not the parameter was valid.</returns> public bool SetSocialNumber(String socialInsNum) { if (CheckSinNumber(socialInsNum) == false) { logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'T', 'F', socialInsNum); return false; } else { socialInsNum = socialInsNum.PadLeft(9, '0'); this.socialInsuranceNumber = socialInsNum; logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'T', 'S', socialInsNum); } return true; }
/// <summary> /// Validates a SIN number. Uses method from http://www.ryerson.ca/JavaScript/lectures/forms/textValidation/sinProject.html /// </summary> /// <param name="sinNumber">The SIN number to be validated.</param> /// <returns>A boolean value indicating whether or not the SIN Number is valid.</returns> public virtual bool CheckSinNumber(String sinNumber) { int[] sinNumbers = new int[9]; int total = 0; int temp = 0; sinNumber = sinNumber.Replace(" ", ""); if (sinNumber.Length <= 9) { String tempString = sinNumber.PadLeft(9, '0'); for (int i = 0; i < tempString.Length; i++) { sinNumbers[i] = (int)Char.GetNumericValue(tempString[i]); } sinNumbers[1] = sinNumbers[1] * 2; sinNumbers[3] = sinNumbers[3] * 2; sinNumbers[5] = sinNumbers[5] * 2; sinNumbers[7] = sinNumbers[7] * 2; total += (sinNumbers[1] / 10); total += (sinNumbers[1] % 10); total += (sinNumbers[3] / 10); total += (sinNumbers[3] % 10); total += (sinNumbers[5] / 10); total += (sinNumbers[5] % 10); total += (sinNumbers[7] / 10); total += (sinNumbers[7] % 10); total += sinNumbers[0] + sinNumbers[2] + sinNumbers[4] + sinNumbers[6]; if (total % 10 == 0) { if (sinNumbers[8] == 0) { return true; } } else { temp = ((total / 10) + 1) * 10; total = temp - total; if (total == sinNumbers[8]) { return true; } } } return false; }
public void setValor(String valor) { char pad = '0'; this.valor = valor.PadLeft(15, pad); }
/* * Galvenā apstrāde */ private void processImages(String[] filenames, String relative_final_name) { int width = 0; int height = 0; int count = 0; string dir = ""; // Ielasam attēlu izmērus un skaitu foreach (String fn in filenames) { Image t = Image.FromFile(fn); width = t.Width; height = t.Height; dir = System.IO.Path.GetDirectoryName(fn); count++; t.Dispose(); } txtStatus.AppendText("\nProcessing...\n"); txtStatus.AppendText("Count: " + count + "\n"); txtStatus.AppendText("Size: " + width + "x" + height + "\n"); txtStatus.AppendText("Dir: " + dir + "\n"); // Sākam veidot masku Random rand = new Random(); int[,] mask = new int[width, height]; txtStatus.AppendText("Mask: " + width + "x" + height + "\n"); /* * x * y pikseļu bloki */ if (rdTypeBlock.Checked) { // Nosakam bloku skaitu int block_width = int.Parse(txtBlockWidth.Text); int block_height = int.Parse(txtBlockHeight.Text); int block_count_x = width / block_width; int block_count_y = height / block_height; if (block_count_x < 1) { block_count_x = 1; } if (block_count_y < 1) { block_count_y = 1; } txtStatus.AppendText("Blocks: " + block_count_x + " x " + block_count_y + "\n"); // Izveidojam masku blokiem int[,] blockmask = new int[block_count_x, block_count_y]; for (int y = 0; y < block_count_y; y++) { for (int x = 0; x < block_count_x; x++) { int rnd = rand.Next(0, count); blockmask[x, y] = rnd; } } // Pārnesam bloku masku uz pilno attēla masku for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int blockmask_x = x / block_width; int blockmask_y = y / block_height; // Likvidējam dalīšanas noapaļošanas iespējamās kļūdas if (blockmask_x >= block_count_x) { blockmask_x = block_count_x - 1; } if (blockmask_x < 0) { blockmask_x = 0; } if (blockmask_y >= block_count_y) { blockmask_y = block_count_y - 1; } if (blockmask_y < 0) { blockmask_y = 0; } // Ienesam attēla maskas pikselī atbilstošu bloka maskas pikseli int rnd = 0; try { rnd = blockmask[blockmask_x, blockmask_y]; } catch (System.IndexOutOfRangeException ex) { } finally { } mask[x, y] = rnd; } } } /* * Līnijas horizontāli */ if (rdTypeLinesHorizontal.Checked) { for (int y = 0; y < height; y++) { int rnd = rand.Next(0, count); for (int x = 0; x < width; x++) { mask[x, y] = rnd; } } } /* * Līnijas vertikāli */ if (rdTypeLinesVertical.Checked) { for (int x = 0; x < width; x++) { int rnd = rand.Next(0, count); for (int y = 0; y < height; y++) { mask[x, y] = rnd; } } } /* * Atsevišķi pikseļi */ if (rdTypePixel.Checked) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int rnd = rand.Next(0, count); mask[x, y] = rnd; } } } // Veidojam gala attēlu Bitmap fin = new Bitmap(width, height); int n = 0; progressSingle.Maximum = width * height; progressSingle.Value = 0; // Pēc kārtas lasam visus norādītos attēlus foreach (String fn in filenames) { Bitmap t = new Bitmap(fn); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { // Ierakstam gala attēlā šī attēla pikseļus, ja maskā tā norādīts /* * Šī ir tā vieta, kur jāveic pirmā optimizācija, kad nepieciešams, * jo izmantota ļoti neefektīva metode pikseļu kopēšanai */ if (mask[x, y] == n) { fin.SetPixel(x, y, t.GetPixel(x, y)); progressSingle.Value = progressSingle.Value + 1; Application.DoEvents(); } } } t.Dispose(); n++; } dir = dir + "\\processed"; // Lai nosaukumi būtu 0001, 0002, 0003, nevis 1, 2, 3 relative_final_name = relative_final_name.PadLeft(count.ToString().Length, '0'); txtStatus.AppendText("Save to: " + dir + "\\" + relative_final_name + ".png" + "\n"); if (!System.IO.Directory.Exists(dir)) { System.IO.Directory.CreateDirectory(dir); } fin.Save(dir + "\\" + relative_final_name + ".png", ImageFormat.Png); txtStatus.AppendText("... complete!\n"); }
private string addByteSpacing(String unspacedByteString) { int msgsize = unspacedByteString.Length; if (msgsize == 0) { return ""; } //makes sure it's even if (!(msgsize % 2 == 0)) { unspacedByteString = unspacedByteString.PadLeft(unspacedByteString.Length + 1, '0'); } StringBuilder addingSpacing = new StringBuilder(); Boolean complete = false; int indexChar = 0; while (!complete) { addingSpacing.Append(unspacedByteString[indexChar]); addingSpacing.Append(unspacedByteString[indexChar+1]); indexChar = indexChar + 2; if (indexChar >= (msgsize)) { complete = true; } else { addingSpacing.Append(" "); } } return addingSpacing.ToString().ToUpper(); }
public static String RSet(String Source, int Length) { if(Source == null) { return new String(' ', Length); } if(Source.Length >= Length) { return Source.Substring(0, Length); } else { return Source.PadLeft(Length); } }
public void setOriginador(String originador) { char pad = '0'; this.originador = originador.PadLeft(20, pad); }
private void MensajeCentrado( String elMensaje ) { var mitadIzquierda = ( Console.WindowWidth + elMensaje.Length ) / 2; Console.WriteLine(elMensaje.PadLeft( mitadIzquierda )); }
/// <summary> /// Converts a String to a byte Array. /// </summary> /// <param name="hex">The string to convert</param> /// <returns>A byte array corresponding to the string</returns> public static byte[] StringToByteArray(String hex) { if ((hex.Length % 2) == 1) //if odd { hex = hex.PadLeft(1, '0'); } int numberChars = hex.Length / 2; var bytes = new byte[numberChars]; using (var sr = new StringReader(hex)) { for (int i = 0; i < numberChars; i++) bytes[i] = Convert.ToByte(new string(new char[2] { (char)sr.Read(), (char)sr.Read() }), 16); } return bytes; }
public void setParameters() { this.opcodeString += instructionO + " "; #region type R algo if (opcodeType.Equals('R')) { try { //Console.WriteLine("0"); this.rsO = this.rs.TrimStart('R'); this.rtO = this.rt.TrimStart('R'); this.rdO = this.rd.TrimStart('R'); //Console.WriteLine("1"); this.rsDec = Int32.Parse(rsO); this.rtDec = Int32.Parse(rtO); this.rdDec = Int32.Parse(rdO); this.rsO = Convert.ToString(rsDec, 2); this.rtO = Convert.ToString(rtDec, 2); this.rdO = Convert.ToString(rdDec, 2); this.rsO = rsO.PadLeft(5, '0'); this.rtO = rtO.PadLeft(5, '0'); this.rdO = rdO.PadLeft(5, '0'); if (rsDec > 31 || rtDec > 31 || rdDec > 31) this.valid = false; else this.valid = true; } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } #endregion #region type I algo //BNEC nalang kulang... does not have offset if (opcodeType.Equals('I')) { #region BNEC and DADDIU if (this.instruction == "BNEC" || this.instruction == "DADDIU") { try { this.rsO = this.rs.TrimStart('R'); this.rtO = this.rt.TrimStart('R'); this.rsDec = Int32.Parse(rsO); this.rtDec = Int32.Parse(rtO); this.rsO = Convert.ToString(rsDec, 2); this.rtO = Convert.ToString(rtDec, 2); this.rsO = rsO.PadLeft(5, '0'); this.rtO = rtO.PadLeft(5, '0'); if (this.instruction == "BNEC") //this would need offset { //offset would be set through the program.cs } else if (this.instruction == "DADDIU") //this would need immediate { try { this.immediateO = this.immediate.TrimStart('#'); this.immediateDec = Int32.Parse(immediateO, System.Globalization.NumberStyles.HexNumber); this.immediateO = Convert.ToString(immediateDec, 2); if (immediateDec > 32768) { this.immediateO = immediateO.PadLeft(16, '1'); } else { this.immediateO = immediateO.PadLeft(16, '0'); } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } if (rsDec >= 0 || rtDec <= 31) //immediateDec should be added to the value inside Rt... { this.valid = true; } else this.valid = false; } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } #endregion #region LD and SD if (this.instruction == "LD" || this.instruction == "SD") { try { this.bseO = this.bse.TrimStart('R'); this.rtO = this.rt.TrimStart('R'); this.bseDec = Int32.Parse(bseO); this.rtDec = Int32.Parse(rtO); this.bseO = Convert.ToString(bseDec, 2); this.rtO = Convert.ToString(rtDec, 2); this.bseO = bseO.PadLeft(5, '0'); this.rtO = rtO.PadLeft(5, '0'); this.offsetDec = Int32.Parse(offset, System.Globalization.NumberStyles.HexNumber); Console.WriteLine("About to check if immediate is in range."); if (offsetDec >= 8192 && offsetDec <= 16376) //The value= base + immediate should not surpass memory locations: 2000h-3FFF { //16376 because max offset should be 3FF8-3FFF. if offset is >3FF8, this.valid=false Console.WriteLine("Immediate is in range."); this.offsetO = Convert.ToString(offsetDec, 2); this.offsetO = offsetO.PadLeft(16, '0'); this.valid = true; } /* if (offsetDec >= 8192 && offsetDec <= 16383) //The value= base + immediate should not surpass memory locations: 2000h-3FFF { this.offsetO = Convert.ToString(offsetDec, 2); this.offsetO = offsetO.PadLeft(16, '0'); this.valid = true; }*/ else { Console.WriteLine("Immediate is out range."); this.valid = false; } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } #endregion } #endregion #region type J algo if (opcodeType.Equals('J')) //wait mali to... we have to solve for offset pa... { try { /* this.offsetDec = Int32.Parse(offset, System.Globalization.NumberStyles.HexNumber); this.offsetO = Convert.ToString(offsetDec, 2); this.offsetO = offsetO.PadLeft(26, '0'); this.opcodeString += offsetO; */ this.valid = true; } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } #endregion setOpcodeString(); //this is just a test, this should be called in the program.cs printOpcodeBinary(); }
public static String BinaryStringToHexString(String binary) { StringBuilder result = new StringBuilder(binary.Length / 8 + 1); // TODO: check all 1's or 0's... Will throw otherwise int mod4Len = binary.Length % 8; if (mod4Len != 0) { // pad to length multiple of 8 binary = binary.PadLeft(((binary.Length / 8) + 1) * 8, '0'); } try { for (int i = 0; i < binary.Length; i += 8) { string eightBits = binary.Substring(i, 8); result.AppendFormat("{0:X2}", Convert.ToByte(eightBits, 2)); } } catch (Exception e) { Console.WriteLine("Caught error at Binary to Hex String."); } return result.ToString(); }
private String graphTimeDiff( String inValue, Decimal inBoatTime, Decimal inActualTime, DataTable inSummaryTable, DataTable inStatsTable, String inScore ) { String curReturnValue = ""; int curDiff, curPadLeft, curPadRight; if ( inBoatTime > 0M || inActualTime > 0M ) { curDiff = Convert.ToInt32( ( inBoatTime * 100 ) - ( inActualTime * 100 ) ); if ( curDiff < 0 ) { if ( ( curDiff * -1 ) > 10 ) { curReturnValue = " " + inValue + "| | | "; } else if ( ( curDiff * -1 ) == 10 ) { curReturnValue = " " + inValue + " | | "; } else if ( ( curDiff * -1 ) == 9 ) { curReturnValue = " |" + inValue + " | | "; } else { curPadLeft = 10 - ( curDiff * -1 ); curPadRight = ( curDiff * -1 ) - 1; curReturnValue = " |" + inValue.PadLeft( curPadLeft, ' ' ) + "".PadRight( curPadRight, ' ' ) + "| | "; } } else if ( curDiff > 0 ) { if ( curDiff > 10 ) { curReturnValue = " | | |" + inValue; } else if ( curDiff == 10 ) { curReturnValue = " | | " + inValue + " "; } else if ( curDiff == 9 ) { curPadLeft = curDiff; curReturnValue = " | |" + inValue.PadLeft( curPadLeft, ' ' ) + "| "; } else { curPadRight = 10 - curDiff - 1; curPadLeft = curDiff; curReturnValue = " | |" + inValue.PadLeft( curPadLeft, ' ' ); curReturnValue += "".PadRight( curPadRight, ' ' ) + "| "; } } else { curReturnValue = " | " + inValue + " | "; } //Update summary data per segment DataRow curRow; DataRow[] curRowList; if ( inScore == null ) { curRowList = inSummaryTable.Select( "Type = '" + inValue + "' AND Diff = '" + curDiff + "'" ); } else { if ( inScore.Length > 0 ) { curRowList = inSummaryTable.Select( "Type = '" + inValue + "' AND Diff = '" + curDiff + "' AND Score = " + inScore ); } else { curRowList = inSummaryTable.Select( "Type = '" + inValue + "' AND Diff = '" + curDiff + "' AND Score = 0 " ); } } if ( curRowList.Length > 0 ) { curRow = curRowList[0]; Int16 curCount = (Int16)curRow["Count"]; curCount++; curRow["Count"] = curCount; } else { DataRowView newRow = inSummaryTable.DefaultView.AddNew(); newRow["Type"] = inValue; newRow["Diff"] = curDiff; newRow["Count"] = 1; if ( inScore != null ) { try { newRow["Score"] = Convert.ToInt16( inScore ); } catch { newRow["Score"] = Convert.ToInt16( "0" ); } } newRow.EndEdit(); } //Update Summary statistics if ( inScore == null ) { curRowList = inStatsTable.Select( "Type = '" + inValue + "'" ); } else { if ( inScore.Length > 0 ) { curRowList = inStatsTable.Select( "Type = '" + inValue + "' AND Score = " + inScore ); } else { curRowList = inStatsTable.Select( "Type = '" + inValue + "' AND Score = 0 " ); } } if ( curRowList.Length > 0 ) { curRow = curRowList[0]; Int16 curValue = (Int16)curRow["DiffSum"]; curRow["DiffSum"] = Convert.ToInt16( curDiff + curValue ); if ( curDiff == 0 ) { curValue = (Int16)curRow["ZeroCount"]; curValue++; curRow["ZeroCount"] = curValue; } else { curValue = (Int16)curRow["MaxDiff"]; if ( curValue < curDiff ) { curRow["MaxDiff"] = Convert.ToInt16( curDiff ); } curValue = (Int16)curRow["MinDiff"]; if ( curValue > curDiff ) { curRow["MinDiff"] = Convert.ToInt16( curDiff ); } } Int16 curCount = (Int16)curRow["Count"]; curCount++; curRow["Count"] = curCount; } else { Int16 curValue; DataRowView newRow = inStatsTable.DefaultView.AddNew(); newRow["Type"] = inValue; newRow["Count"] = 1; try { newRow["DiffSum"] = Convert.ToInt16( curDiff ); newRow["MaxDiff"] = Convert.ToInt16( curDiff ); newRow["MinDiff"] = Convert.ToInt16( curDiff ); } catch { newRow["DiffSum"] = Convert.ToInt16( "0" ); newRow["MaxDiff"] = Convert.ToInt16( "0" ); newRow["MinDiff"] = Convert.ToInt16( "0" ); } if ( curDiff == 0 ) { curValue = 1; } else { curValue = 0; } newRow["ZeroCount"] = curValue; if ( inScore != null ) { try { newRow["Score"] = Convert.ToInt16( inScore ); } catch { newRow["Score"] = Convert.ToInt16( "0" ); } } newRow.EndEdit(); } } return curReturnValue; }
//Docdb根据公开号获得xml文件的路径 public static String getXmlPathByPublicNo_Docdb(String publicno) { String xmlpath = Common.DocDB_File_Root; String xmlpath_16 = publicno.PadLeft(16, '0'); xmlpath = xmlpath + publicno.Substring(0, 2) + "//" + xmlpath_16.Substring(0, 4) + "//" + xmlpath_16.Substring(4, 4) + "//" + xmlpath_16.Substring(8, 4) + "//" + xmlpath_16.Substring(12, 4) + "//" + publicno + ".xml"; return xmlpath; }
public static String ValidarFormularioApartamento(String Apartamento) { if (Apartamento.Length == 1) { Apartamento = Apartamento.PadLeft(3, '0'); return Apartamento; } if (Apartamento.Length == 2) { Apartamento = "0" + Apartamento; return Apartamento; } else { return Apartamento; } }
public void setValor(String valor) { this.valor = valor.PadLeft(10); }
/// <summary> /// 根据IDOC编号把IDOC复制到本地。 /// </summary> /// <param name="idocNumber">IDOC编号</param> /// <param name="SystemName">远程SAP系统名称</param> public void CopyIdocFromSAP(String idocNumber, String SystemName) { try { SAPINT.Utils.ReadTable idocReadItem = null; SAPINT.Utils.ReadTable idocReadHeader = null; SAPINT.Utils.ReadTable idocReadStatus = null; //DataTable dtIdocItem = new DataTable(); //DataTable dtIdocHeder = new DataTable(); //DataTable dtIdocStatus = new DataTable(); idocNumber = idocNumber.TrimStart('0'); String criteria = idocNumber.PadLeft(16, '0'); criteria = String.Format("DOCNUM = '{0}'", criteria); String readTableFunction = ConfigFileTool.SAPGlobalSettings.GetReadTableFunction(); idocReadItem = new SAPINT.Utils.ReadTable(SystemName); idocReadItem.TableName = "EDID4"; idocReadItem.SetCustomFunctionName(readTableFunction); idocReadItem.AddCriteria(criteria); idocReadItem.Run(); idocItem = idocReadItem.Result; if (idocItem.Rows.Count == 0) { idocReadItem = new SAPINT.Utils.ReadTable(SystemName); idocReadItem.TableName = "EDID2"; idocReadItem.SetCustomFunctionName(readTableFunction); idocReadItem.AddCriteria(criteria); idocReadItem.Run(); idocItem = idocReadItem.Result; } if (idocItem.Rows.Count == 0) { idocReadItem = new SAPINT.Utils.ReadTable(SystemName); idocReadItem.TableName = "EDIDD_OLD"; idocReadItem.SetCustomFunctionName(readTableFunction); idocReadItem.AddCriteria(criteria); idocReadItem.Run(); idocItem = idocReadItem.Result; } if (idocItem.Rows.Count == 0) { throw new Exception(String.Format("无法找到IDOC{0}明细", idocNumber)); } //读取IDOC头 idocReadHeader = new SAPINT.Utils.ReadTable(SystemName); idocReadHeader.TableName = "EDIDC"; idocReadHeader.SetCustomFunctionName(readTableFunction); idocReadHeader.AddCriteria(criteria); idocReadHeader.Run(); idocHeader = idocReadHeader.Result; //if (idocHeader.Rows.Count != 1) //{ // throw new Exception(String.Format("无法找到IDOC{0}抬头定义", idocNumber)); //} //读取IDOC状态 idocReadStatus = new SAPINT.Utils.ReadTable(SystemName); idocReadStatus.TableName = "EDIDS"; idocReadStatus.SetCustomFunctionName(readTableFunction); idocReadStatus.AddCriteria(criteria); idocReadStatus.Run(); idocStatus = idocReadStatus.Result; SapTable idocTable = null; if (idocHeader.Rows.Count > 0) { idocTable = new SapTable(SystemName, "EDIDC"); idocTable.DbConnectionString = this.ConnectionName; idocTable.AppendToDb = AppendTodb; idocTable.SaveDataTable(idocHeader); } if (idocItem.Rows.Count > 0) { idocTable = new SapTable(SystemName, "EDID4", "EDID4"); idocTable.DbConnectionString = this.ConnectionName; idocTable.AppendToDb = AppendTodb; idocTable.SaveDataTable(idocItem); } if (idocStatus.Rows.Count > 0) { idocTable = new SapTable(SystemName, "EDIDS"); idocTable.DbConnectionString = this.ConnectionName; idocTable.AppendToDb = AppendTodb; idocTable.SaveDataTable(idocStatus); } } catch (Exception) { throw; } }