Exemplo n.º 1
0

        
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang lưu trữ dữ liệu..."))
            {
                ProcessTransaction pt = new ProcessTransaction();
                pt.OpenConnection();
                pt.BeginTransaction();

                try
                {
                    //if (!ValidateForm())
                    //    return;

                    #region FCM
                    //fcm.FK_DTCP = TextUtils.ToInt(LibIE.ExcuteScalar("SELECT TOP 1 [PK_ID] FROM [T_DM_DTCP] where C_MA = '" + txtProjectCode.Text.Trim() + "'"));
                    //fcm.C_CODE = txtProjectCode.Text.Trim();
                    FCM.C_MONTH = cboMonth.SelectedIndex;
                    FCM.C_YEAR  = TextUtils.ToInt(cboYear.SelectedItem);
                    //fcm.C_SOHOADON = txtHopDong.Text.Trim();
                    //fcm.C_TYPE = chkIsGiaoDucFCM.Checked ? 1 : 2;
                    //fcm.C_TYPE = TextUtils.ToInt(cboPhongBan.SelectedValue) == 40 ? 1 : 2;
                    //fcm.TotalBX = TextUtils.ToDecimal(txtTotalBX.EditValue);
                    //fcm.TotalTrienKhai = TextUtils.ToDecimal(txtTotalTrienKhai.EditValue);
                    //fcm.TotalHD = TextUtils.ToDecimal(txtTotalHD.EditValue);
                    //fcm.TotalNC = TextUtils.ToDecimal(txtTotalNC.EditValue);
                    //fcm.TotalPB = TextUtils.ToDecimal(txtTotalPB.EditValue);
                    //fcm.TotalProfit = TextUtils.ToDecimal(txtTotalProfit.EditValue);
                    //fcm.TotalReal = TextUtils.ToDecimal(txtTotalReal.EditValue);
                    //fcm.TotalTPA = TextUtils.ToDecimal(txtTotalTPA.EditValue);
                    //fcm.TotalVAT = TextUtils.ToDecimal(txtTotalVAT.EditValue);
                    //fcm.TotalBanHang = TextUtils.ToDecimal(txtTotalBanHang.EditValue);

                    pt.Update(FCM);
                    #endregion

                    #region Detail
                    grvData.FocusedRowHandle = -1;
                    for (int i = 0; i < grvData.RowCount; i++)
                    {
                        T_DM_FCM_DETAILModel detail = (T_DM_FCM_DETAILModel)T_DM_FCM_DETAILBO.Instance.FindByPK(TextUtils.ToInt(grvData.GetRowCellValue(i, colID)));
                        detail.FK_FCM       = FCM.ID;
                        detail.FK_PHANXUONG = TextUtils.ToInt(grvData.GetRowCellValue(i, colDepartmentID));
                        detail.FK_KMP       = TextUtils.ToInt(grvData.GetRowCellValue(i, colFK_KMP));
                        detail.C_PRICE      = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colValue));
                        pt.Update(detail);
                    }
                    #endregion

                    pt.CommitTransaction();

                    if (this.LoadDataChange != null)
                    {
                        this.LoadDataChange(null, null);
                    }

                    MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    pt.CloseConnection();
                }
            }
        }
Exemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang lưu trữ dữ liệu..."))
            {
                ProcessTransaction pt = new ProcessTransaction();
                pt.OpenConnection();
                pt.BeginTransaction();

                try
                {
                    if (!ValidateForm())
                    {
                        return;
                    }

                    #region FCM
                    fcm.FK_DTCP    = TextUtils.ToInt(LibIE.ExcuteScalar("SELECT TOP 1 [PK_ID] FROM [T_DM_DTCP] where C_MA = '" + txtProjectCode.Text.Trim() + "'"));
                    fcm.C_CODE     = txtProjectCode.Text.Trim();
                    fcm.C_MONTH    = cboMonth.SelectedIndex;
                    fcm.C_YEAR     = TextUtils.ToInt(cboYear.SelectedItem);
                    fcm.C_SOHOADON = txtHopDong.Text.Trim();
                    //fcm.C_TYPE = chkIsGiaoDucFCM.Checked ? 1 : 2;
                    fcm.C_TYPE         = TextUtils.ToInt(cboPhongBan.SelectedValue) == 40 ? 1 : 2;
                    fcm.TotalBX        = TextUtils.ToDecimal(txtTotalBX.EditValue);
                    fcm.TotalTrienKhai = TextUtils.ToDecimal(txtTotalTrienKhai.EditValue);
                    fcm.TotalHD        = TextUtils.ToDecimal(txtTotalHD.EditValue);
                    fcm.TotalNC        = TextUtils.ToDecimal(txtTotalNC.EditValue);
                    fcm.TotalPB        = TextUtils.ToDecimal(txtTotalPB.EditValue);
                    fcm.TotalProfit    = TextUtils.ToDecimal(txtTotalProfit.EditValue);
                    fcm.TotalReal      = TextUtils.ToDecimal(txtTotalReal.EditValue);
                    fcm.TotalTPA       = TextUtils.ToDecimal(txtTotalTPA.EditValue);
                    fcm.TotalVAT       = TextUtils.ToDecimal(txtTotalVAT.EditValue);
                    fcm.TotalBanHang   = TextUtils.ToDecimal(txtTotalBanHang.EditValue);
                    fcm.TotalVT        = TextUtils.ToDecimal(txtTotalVT.EditValue);

                    fcm.ID = (int)pt.Insert(fcm);
                    #endregion

                    #region Detail
                    grvData.FocusedRowHandle = -1;
                    for (int i = 0; i < grvData.RowCount; i++)
                    {
                        decimal c_Price = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colValue));
                        //if (c_Price == 0) continue;
                        string kmpCode      = TextUtils.ToString(grvData.GetRowCellValue(i, colCode));
                        int    departmentID = TextUtils.ToInt(grvData.GetRowCellValue(i, colDepartmentID));
                        int    pk_KMP       = TextUtils.ToInt(LibIE.ExcuteScalar("select top 1 PK_ID from T_DM_KMP where C_MA = '" + kmpCode + "'"));
                        if (pk_KMP == 0)
                        {
                            continue;
                        }

                        if (departmentID == 81)
                        {
                            DataTable dtLink = LibIE.Select("SELECT [ID],[PK_PHANXUONG],[PK_KMP],[TYLE],[C_MA],[C_MOTA] FROM " +
                                                            "[V_DM_PHANXUONG_KMP] where PK_KMP = " + pk_KMP + " and TYLE > 0");
                            if (dtLink.Rows.Count > 0)
                            {
                                foreach (DataRow row in dtLink.Rows)
                                {
                                    T_DM_FCM_DETAILModel detail = new T_DM_FCM_DETAILModel();
                                    detail.FK_FCM       = fcm.ID;
                                    detail.FK_PHANXUONG = TextUtils.ToInt(row["PK_PHANXUONG"]);
                                    detail.FK_KMP       = pk_KMP;
                                    detail.C_PRICE      = TextUtils.ToDecimal(row["TYLE"]) * c_Price / 100;
                                    pt.Insert(detail);
                                }
                            }
                        }
                        else
                        {
                            T_DM_FCM_DETAILModel detail = new T_DM_FCM_DETAILModel();
                            detail.FK_FCM       = fcm.ID;
                            detail.FK_PHANXUONG = TextUtils.ToInt(grvData.GetRowCellValue(i, colDepartmentID));
                            detail.FK_KMP       = pk_KMP;
                            detail.C_PRICE      = c_Price;
                            pt.Insert(detail);
                        }
                    }
                    #endregion

                    pt.CommitTransaction();
                    if (this.LoadDataChange != null)
                    {
                        this.LoadDataChange(null, null);
                    }
                    MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    pt.CloseConnection();
                }
            }
        }