标签:
/// <summary>
/// 根据运输证带出可用数量
/// </summary>
public bool Transportation(int Row)
{
bool IsSuccess = true;
int currentRow = Row;
tRANSFER_LINES2s.SetCurrentRow(currentRow);//获取当前页面的行
double b = 0.00;
if (TRANSFER_LINES2s.TransferLine != "")
{
int Listsheng = 0;
IList<IDictionary> records = null;
string sql = @"SELECT T1.U_TransportarNo ,T1.U_FromDate ,T1.U_ToDate
FROM [@TRANSFER_LINES1] T0 ,[@TRANSPORTAR] T1
WHERE T0.DocEntry=‘{0}‘ AND T0.LineId=‘{1}‘ AND T1.U_ItemCode=T0.U_ItemCode";
sql = string.Format(sql,DocEntry,tRANSFER_LINES2s.TransferLine);
records = Context.DiUtility.FindRecordsBySql(sql);
string sql1 = "SELECT COUNT(*) FROM [@TRANSFER_LINES2] WHERE U_TransportarId=‘{0}‘ AND U_LineStatus=‘C‘";
double convert1 = Convert.ToDouble(Context.DiUtility.ExecSql(string.Format(sql1, this.tRANSFER_LINES2s.TransportarId)));//运输证已使用过的次数
string sql2 = " SELECT T0.U_Counts FROM [@TRANSPORTAR] T0 WHERE T0.U_TransportarNo=‘{0}‘";
double convert2 = Convert.ToDouble(Context.DiUtility.ExecSql(string.Format(sql2, this.tRANSFER_LINES2s.TransportarId)));//运输证的有效次数
Matrix matrix = Parent.Items.Item("509").Specific as Matrix;
ComboBox LineStatus;
LineStatus = matrix.Columns.Item("5").Cells.Item(tRANSFER_LINES2s.Count).Specific as ComboBox;
for (int i = 1; i <= matrix.RowCount; i++)
{
if (Convert.ToString((matrix.Columns.Item("25").Cells.Item(i).Specific as EditText).Value)
== Convert.ToString((matrix.Columns.Item("25").Cells.Item(TRANSFER_LINES2s.Count).Specific as EditText).Value))//判断运输证是否相同
{
Listsheng++;
}
}
if (records.Count == 0)
{
throw new TransportationIsNoException();
}
else
{
if (LineStatus.Value == "C" || LineStatus.Value == "A")//当行状态为添加和未执行时判断运输证的剩余数量和剩余有效次数
{
if (convert2 - convert1 - Listsheng >= 0)
{
TRANSFER_LINES2s.CanUse = Convert.ToString(TransportationSum(b));//传递运输证的剩余数量
Context.Application.MessageBox(
Context.Message.GetMessage("该运输证的剩余可用次数为" + (convert2 - convert1 - Listsheng).ToString()), 2,
Context.Message.GetMessage("btnOk"), "");
}
else
{
Context.Application.MessageBox(
Context.Message.GetMessage("该运输证有效次数已用完,请重新选择!"), 2,
Context.Message.GetMessage("btnOk"), "");
IsSuccess = false;
return IsSuccess;
}
}
}
tRANSFER_LINES2s.UpdateRow();
}
return IsSuccess;
}
/// <summary>
/// 订购的数量不能大于运输证可用的数量
/// </summary>
public double TransportationSum(double b)
{
Matrix matrix;
Matrix matrix1;
matrix = Parent.Items.Item("505").Specific as Matrix;
matrix1 = Parent.Items.Item("509").Specific as Matrix;
ComboBox LineStatus;
LineStatus = matrix1.Columns.Item("5").Cells.Item(tRANSFER_LINES2s.Count).Specific as ComboBox;
string sql = " SELECT U_Quantity FROM [@TRANSPORTAR] WHERE U_TransportarNo=‘{0}‘";
double convert1 = Convert.ToDouble(Context.DiUtility.ExecSql(string.Format(sql, this.tRANSFER_LINES2s.TransportarId)));//运输证的数量
string sql1 = @"SELECT SUM(T1.U_Quantity)
FROM [@TRANSFER] T0,[@TRANSFER_LINES1] T1 ,[@TRANSFER_LINES2] T2
WHERE T2.U_TransportarId=‘{0}‘ AND
T0.DocEntry=T1.DocEntry AND T1.DocEntry=T2.DocEntry AND T2.U_LineStatus=‘C‘";//当为已完成状态时,才会添加到数据库里面
double convert2 = Convert.ToDouble(Context.DiUtility.ExecSql(string.Format(sql1, this.tRANSFER_LINES2s.TransportarId)));//运输证已经用掉的额度
double a = 0.00;
string id = "";
for (int i = 1; i <= matrix1.RowCount; i++)
{
if (LineStatus.Value == "C" || LineStatus.Value == "A")//当行状态为添加和未执行时判断
{
id = Convert.ToString((matrix1.Columns.Item("7").Cells.Item(i).Specific as EditText).Value);
if (Convert.ToString((matrix1.Columns.Item("25").Cells.Item(i).Specific as EditText).Value)
== Convert.ToString((matrix1.Columns.Item("25").Cells.Item(TRANSFER_LINES2s.Count).Specific as EditText).Value))
{
a += getid(matrix, id);
}
}
}
if (LineStatus.Value == "C" || LineStatus.Value == "A")//当行状态为添加和未执行时判断
{
b=convert1 - convert2 - a;
}
if (b < 0)
{
throw new TransportationConntMaxSum();
}
else
{
return b;
}
}
/// <summary>
/// 传递Matrix中的参数,获取行号
/// </summary>
/// <param name="matrix"></param>
/// <param name="id"></param>
/// <returns></returns>
private double getid(Matrix matrix, string id)
{
Matrix matrix2;
matrix2 = Parent.Items.Item("509").Specific as Matrix;
ComboBox LineStatus;
LineStatus = matrix2.Columns.Item("5").Cells.Item(tRANSFER_LINES2s.Count).Specific as ComboBox;
double list = 0;
for (int i = 1; i <= matrix.RowCount; i++)
{
if (Convert.ToString((matrix.Columns.Item("1").Cells.Item(i).Specific as EditText).Value) == id)
{
list += Convert.ToDouble((matrix.Columns.Item("29").Cells.Item(i).Specific as EditText).Value);//订购的数量
}
}
return list;
}
标签:
原文地址:http://www.cnblogs.com/fanna/p/4773614.html