using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
namespace SPC.Kiosk.Common
{
///
/// Double 값을 Percent에 따라 변환
///
public class DoublePercentValue : IValueConverter
{
///
/// Convert
///
///
///
///
///
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double result = double.NaN;
try
{
if (value is double getValue)
{
if (parameter != null && getValue > 0 )
{
result = getValue * double.Parse(parameter.ToString()) / 100;
}
else
{
result = getValue;
}
}
}
catch
{
result = double.NaN;
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// bool 값을 Visibility 값으로 변환
///
public class BoolToVisibility : IValueConverter
{
///
/// Convert
///
///
///
///
///
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Visibility result = Visibility.Collapsed;
try
{
if (value is bool getValue)
{
result = getValue ? Visibility.Visible : Visibility.Collapsed;
}
}
catch
{
result = Visibility.Collapsed;
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class BoolToUnvisibility : IValueConverter
{
///
/// Convert
///
///
///
///
///
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Visibility result = Visibility.Collapsed;
try
{
if (value is bool getValue)
{
result = getValue ? Visibility.Collapsed : Visibility.Visible;
}
}
catch
{
result = Visibility.Collapsed;
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// 숫자 을 문자열로
///
public class NumericToString : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string result = string.Empty;
try
{
if (value is double getValue)
{
if (parameter is string getFormetString)
{
result = getValue.ToString(getFormetString);
}
else
{
result = getValue.ToString();
}
}
else if (value is int getInt)
{
if (parameter is string getFormetString )
{
result = getInt.ToString(getFormetString);
}
else
{
result = getInt.ToString();
}
}
else if (value is long getlong)
{
if (parameter is string getFormetString)
{
result = getlong.ToString(getFormetString);
}
else
{
result = getlong.ToString();
}
}
}
catch
{
result = string.Empty;
}
return result;
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// Numeric To Visibility 값으로 변환
///
public class NumericExistToVisibility : IValueConverter
{
///
/// Convert
///
///
///
///
///
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Visibility result = Visibility.Collapsed;
try
{
double checkValue = 0d;
try
{
checkValue = double.Parse(value.ToString());
}
catch
{
checkValue = 0d;
}
bool setValue = false;
try
{
setValue = bool.Parse(parameter.ToString());
}
catch
{
setValue = true;
}
setValue = checkValue > 0d ? setValue : !setValue;
result = setValue ? Visibility.Visible : Visibility.Collapsed;
}
catch
{
result = Visibility.Collapsed;
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// Numeric To Bool 값으로 변환
///
public class NumericExistToBool : IValueConverter
{
///
/// Convert
///
///
///
///
///
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool result = false;
try
{
double checkValue = 0d;
try
{
checkValue = double.Parse(value.ToString());
}
catch
{
checkValue = 0d;
}
bool setValue = false;
try
{
setValue = bool.Parse(parameter.ToString());
}
catch
{
setValue = true;
}
result = checkValue > 0d ? setValue : !setValue;
}
catch
{
result = false;
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// Langeuage Code To Multi Language Data
///
public class CodeToMultiLanguage : IValueConverter
{
///
/// Convert
///
///
///
///
///
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
List result = null;
try
{
if (parameter is string _parameter)
{
if (_parameter.Equals(string.Empty))
{
result = null;
}
else
{
result = Languages.GetMessages(_parameter);
}
}
else
{
result = null;
}
}
catch
{
result = null;
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// Langeuage Code To Multi Language Data(자동계산 혹은 바코드계산)
///
public class CodeToMultiLanguageAutoOrBarcode : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
List result = null;
var opt810 = values[0];
var opt811 = values[1];
try
{
if (parameter is string _parameter)
{
// OPT810값이 0이고 OPT811값이 1인경우(바코드계산)
if (opt810.ToString() == "0"
&& opt811.ToString() == "1")
{
result = new List() { new M_Language { LanguageData = "바코드 계산", Type = SupportLanguageType.ko } };
}
else if (_parameter.Equals(string.Empty))
{
result = null;
}
else
{
result = Languages.GetMessages(_parameter);
}
}
else
{
result = null;
}
}
catch
{
result = null;
}
return result;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// Pos Option Value값에 따라 Barcode 하단 버튼 및 텍스트 Visible처리
///
public class PosOptionValuesBarcodeToVisibility : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var opt810 = values[0];
var opt811 = values[1];
if (parameter?.ToString() == "bottomButtonText")
{
if (opt810.ToString() == "0"
&& opt811.ToString() == "1")
{
return Visibility.Collapsed;
}
}
else if (parameter?.ToString() == "toggleGrid")
{
if (opt810.ToString() == "0"
&& opt811.ToString() == "0")
{
return Visibility.Collapsed;
}
}
return Visibility.Visible;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// Pos Option Value값에 따라 Barcode이미지 Margin처리
///
public class PosOptionValuesBarcodeToMargin : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var opt810 = values[0];
var opt811 = values[1];
if (parameter?.ToString() == "image")
{
if (opt810.ToString() == "0"
&& opt811.ToString() == "1")
{
// 센터정렬
return new Thickness(0, 71 + 50, 0, 0);
}
}
else if (parameter?.ToString() == "textBlock")
{
if (opt810.ToString() == "0"
&& opt811.ToString() == "1")
{
// 센터정렬
return new Thickness(57, 245 + 50, 0, 0);
}
}
return parameter?.ToString() == "image" ? new Thickness(0, 71, 0, 0) : new Thickness(57, 245, 0, 0);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// Point Saving Popup우측화면 Visible처리
///
public class PointSavingAndStoreAgreeViewToVisibility : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var pointSaving = values[0];
var storeAgreeView = values[1];
if (pointSaving?.ToString().ToLower() == "true")
{
return Visibility.Collapsed;
}
else if (pointSaving?.ToString().ToLower() == "false"
&& storeAgreeView?.ToString().ToLower() == "true")
{
return Visibility.Collapsed;
}
return Visibility.Visible;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
///
/// string 값을 Visibility 값으로 변환
///
public class StringToVisibility : IValueConverter
{
///
/// Convert
///
///
///
///
///
///
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
if (value?.ToString() == "0")
{
return Visibility.Collapsed;
}
}
catch
{
return Visibility.Collapsed;
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}