Дипломная работа: Автоматизация рабочего места менеджера отдела продаж для АО "АЭИ "ПРАЙМ"

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
95
dtpInDate.Value = Convert.ToDateTime(row["InDate"]);
tbDescription.Text = row["Description"].ToString();
lblImgFile.Text = row["ImgFile"].ToString();
currentConstID = (int)row["ConstID"];
}//обновление связанных с текущей строкой конролов
public static bool SaveChanges(DateTime Date, DateTime InDate,
int ConstID = 0,
int InDocTypeID = 0,
string Num ="",
int DeptID = 0,
string Description = "",
string ImgFile ="",
byte[] Img = null,
int rowStatus = 0)
{
SqlConnection cn = new
SqlConnection(SessionProperties.currentConnectionString);
SqlCommand cmd = new SqlCommand("dbo.EditInDocs", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
cmd.Parameters.Add("@ConstID", SqlDbType.Int);
cmd.Parameters["@ConstID"].Value = ConstID;
cmd.Parameters.Add("@InDocTypesID", SqlDbType.Int);
cmd.Parameters["@InDocTypesID"].Value = InDocTypeID;
cmd.Parameters.Add("@Num", SqlDbType.NVarChar, 20);
cmd.Parameters["@Num"].Value = Num;
cmd.Parameters.Add("@Date", SqlDbType.DateTime);
cmd.Parameters["@Date"].Value = Date;
cmd.Parameters.Add("@DeptID", SqlDbType.Int);
cmd.Parameters["@DeptID"].Value = DeptID;
cmd.Parameters.Add("@InDate", SqlDbType.DateTime);
cmd.Parameters["@InDate"].Value = InDate;
cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 254);
cmd.Parameters["@Description"].Value = Description;
cmd.Parameters.Add("@ImgFile", SqlDbType.NVarChar, 254);
cmd.Parameters["@ImgFile"].Value = ImgFile;
cmd.Parameters.Add("@Img", SqlDbType.Image);
cmd.Parameters["@Img"].Value = Img;
cmd.Parameters.Add("@SessionsID", SqlDbType.Int);
cmd.Parameters["@SessionsID"].Value = SessionProperties.sessionID;
cmd.Parameters.Add("@RowStatus", SqlDbType.Int);
cmd.Parameters["@RowStatus"].Value = rowStatus;
cmd.Parameters.Add("@Msg", SqlDbType.NVarChar, 400);
cmd.Parameters["@Msg"].Value = "";
96
cmd.Parameters["@Msg"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@Res", SqlDbType.Int);
cmd.Parameters["@Res"].Value = 0;
cmd.Parameters["@Res"].Direction = ParameterDirection.Output;
SessionProperties.lastError = "";
try
{
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
int result = (int)cmd.Parameters["@Res"].Value;
if (result >= 0)
{
return true; // успех
}
else
{
MessageBox.Show((string)cmd.Parameters["@Msg"].Value, "Ошибка!!!",
MessageBoxButtons.OK, MessageBoxIcon.Stop);
return false; //Ошибка хранимой процедуры
}
}
catch (Exception ex)
{
SessionProperties.lastError = ex.Message;
MessageBox.Show(SessionProperties.lastError, "Ошибка!!!",
MessageBoxButtons.OK, MessageBoxIcon.Stop);
return false; // Ошибка SQL
}
}//сохранение изменений
private void DataChanged(object sender, EventArgs e)
{
if (checkChanges)
{
if (this.Text.IndexOf('*') == -1)
{
this.Text += "*";
}
btnOk.Enabled = true;
}
}
//вывод заявок в грид за определенный период
private void DgvInDocsFill()
{
SqlCommand cmd = new SqlCommand("SELECT * FROM PCOrders WHERE Date BETWEEN
@begDate AND @endDate ORDER BY Description", new
SqlConnection(SessionProperties.currentConnectionString));
cmd.Parameters.Add("@begDate",SqlDbType.DateTime);
cmd.Parameters.Add("@endDate",SqlDbType.DateTime);
cmd.Parameters["@begDate"].Value = SessionProperties.begDate;
cmd.Parameters["@endDate"].Value = SessionProperties.endDate;
try
97
{
cmd.Connection.Open();
tblInDocs.Clear();
tblInDocs.Load(cmd.ExecuteReader());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "DgvInDocsFill()",MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
cmd.Connection.Close();
}
}
//изменение заголовка
private void UpdateHeaderText()
{
this.Text = "Заявки на комплектующие для ПК за период с " +
SessionProperties.begDate.ToShortDateString() + " по " +
SessionProperties.endDate.ToShortDateString();
}
// удаление заявки
private void DocDelete()
{
var result = MessageBox.Show("Удалить документ?", "Внимание???",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
if (SaveChanges(Date: dtpDate.Value, InDate: dtpInDate.Value, ConstID:
currentConstID, rowStatus: 2))
{
DgvInDocsFill();
RestoreRowIndexPosition();
}
}
}
//выход
private void btnExit_Click(object sender, EventArgs e)
{
if (exitCancel)
{
Close();
}
else
{
btnExit.Text = "Esc - Выход";
SwitchMode(2);
}
}
//сохранение новой заявки
private void btnOk_Click(object sender, EventArgs e)
{
98
if (rowStatus == 0)
{
DataTable dt = SearchSimilarDoc((int)cboDept.SelectedValue,
(int)cboInDocType.SelectedValue,tbNum.Text);
if (dt.Rows.Count > 0)
{
frmEditInDocsChoosingReplaceDoc _frmEditInDocsChoosingReplaceDoc =
new frmEditInDocsChoosingReplaceDoc(dt);
DialogResult dResult =
_frmEditInDocsChoosingReplaceDoc.ShowDialog();
if (DialogResult.Yes == dResult)
{
rowStatus = 1;
currentConstID = SessionProperties.retInt;
}
if (DialogResult.Cancel == dResult)
{
return;
}
}
if (lblImgFile.Text == "" && doc == null)
{
MessageBox.Show("Нет документа!!!", "Внимание!!!",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
if (SaveChanges(dtpDate.Value,dtpInDate.Value, InDocTypeID :
(int)cboInDocType.SelectedValue,ConstID: currentConstID,
Num : tbNum.Text, DeptID : (int)cboDept.SelectedValue, Description :
tbDescription.Text,
ImgFile: lblImgFile.Text, Img: doc, rowStatus: rowStatus))
{
DefaultDate = dtpDate.Value;
DefaultInDate = dtpInDate.Value;
DefaultInDocType = (int)cboInDocType.SelectedValue;
DgvInDocsFill();
RestoreRowIndexPosition();
doc = null;
SwitchMode(2);
}
}
//поиск заявки
private DataTable SearchSimilarDoc(int DeptID,int InDocTypesID,string DocNum)
{
DataTable resTable = new DataTable();
SqlCommand cmd = new SqlCommand("SELECT * FROM PCOrders WHERE DeptID =
@DeptID AND InDocTypesID = @InDocTypesID AND Num = @DocNum ORDER BY Description", new
SqlConnection(SessionProperties.currentConnectionString));
cmd.Parameters.Add("@DeptID", SqlDbType.Int).Value = DeptID;
cmd.Parameters.Add("@InDocTypesID", SqlDbType.Int).Value = InDocTypesID;
cmd.Parameters.Add("@DocNum", SqlDbType.NVarChar).Value = DocNum;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(resTable);
return resTable;
99
}
private void RestoreRowIndexPosition()
{
try
{
if (dgvInDocs.Rows.Count > 0)
{
DataRow[] searchedRows =
((DataTable)dgvInDocs.DataSource).Select("ConstID = " + currentConstID.ToString());
int rowIndex;
if (searchedRows.Length > 0)
{
rowIndex = tblInDocs.Rows.IndexOf(searchedRows[0]);
}
else
{
rowIndex = (dgvRowIndex >= dgvInDocs.Rows.Count) ?
dgvInDocs.Rows.Count - 1 : dgvRowIndex;
}
if (rowIndex > dgvInDocs.Rows.Count - 1)
{
dgvInDocs.CurrentCell = dgvInDocs[0, 0];
}
else
dgvInDocs.CurrentCell = dgvInDocs[0, rowIndex];
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,
"RestoreRowIndexPosition()",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void dgvInDocs_CellMouseDoubleClick(object sender,
DataGridViewCellMouseEventArgs e)
{
if (rowStatus == -1)//режим выбора
{
DataRow row =
((DataRowView)dgvInDocs.Rows[e.RowIndex].DataBoundItem).Row;//строка из привязанной
таблицы
SessionProperties.retInt = (int)row["ConstID"];//возврат
(сохранение в статическом объекте) значения из формы
SessionProperties.retString = (string)row["FullName"];
EventHandler<EventArgs> handler = RaiseInDocSelected;
if (handler != null)
{
//оператор для вызова события.
handler(this, e);
}
Close();
Источник: https://baza.diplomsite.ru/previewfile/2176