예제 #1
0
        private void cboSheet_SelectionChangeCommitted(object sender, EventArgs e)
        {
            grvData.Columns.Clear();
            if (chkAutoCheck.Checked)
            {
                try
                {
                    var tablename = cboSheet.SelectedItem.ToString();

                    grdData.DataSource = ds;                     // dataset
                    grdData.DataMember = tablename;
                }
                catch (Exception ex)
                {
                    TextUtils.ShowError(ex);
                    grdData.DataSource = null;
                }
            }
            else
            {
                try
                {
                    DataTable dt = TextUtils.ExcelToDatatableNoHeader(btnBrowse.Text, cboSheet.SelectedValue.ToString());

                    grdData.DataSource = dt;
                    grvData.PopulateColumns();
                    grvData.BestFitColumns();
                    grdData.Focus();
                }
                catch (Exception ex)
                {
                    TextUtils.ShowError(ex);
                    grdData.DataSource = null;
                }
            }
        }
예제 #2
0
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (!grvData.IsDataRow(grvData.FocusedRowHandle))
            {
                return;
            }

            int strID = TextUtils.ToInt(grvData.GetFocusedRowCellValue("ID"));

            string strName = TextUtils.ToString(grvData.GetFocusedRowCellValue("ProductCode"));

            if (MessageBox.Show(String.Format("Bạn có chắc muốn xóa [{0}] không?", strName), TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    ProductionPlanBO.Instance.Delete(Convert.ToInt32(strID));
                    LoadInfoSearch();
                }
                catch
                {
                    MessageBox.Show("Có lỗi xảy ra khi thực hiện thao tác, xin vui lòng thử lại sau.");
                }
            }
        }
예제 #3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!grvData.IsDataRow(grvData.FocusedRowHandle))
            {
                return;
            }

            int ID = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colID));

            string strName = TextUtils.ToString(grvData.GetFocusedRowCellValue(colProductTypeCode));

            if (MessageBox.Show(String.Format("Bạn có chắc muốn xóa loại sản phẩm [{0}] không?", strName), TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    ConfigFormulaAllBO.Instance.Delete(ID);
                    grvData.DeleteRow(grvData.FocusedRowHandle);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Có lỗi xảy ra khi thực hiện thao tác, xin vui lòng thử lại sau.\n" + ex.ToString());
                }
            }
        }
예제 #4
0
        private bool checkValid()
        {
            if (txtCode.Text == "")
            {
                MessageBox.Show("Xin hãy điền mã của loại sản phẩm.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            else
            {
                DataTable dt;
                if (!_isAdd)
                {
                    int strID = TextUtils.ToInt(grvData.GetRowCellValue(grvData.FocusedRowHandle, "ID"));
                    dt = LibIE.Select("select top 1 1 from ProductType WITH(NOLOCK) where ProductTypeCode = '" + txtCode.Text.Trim() + "' and ID <> " + strID);
                }
                else
                {
                    dt = LibIE.Select("select top 1 1 from ProductType WITH(NOLOCK) where ProductTypeCode = '" + txtCode.Text.Trim() + "'");
                }
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        MessageBox.Show("Mã này đã tồn tại!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return(false);
                    }
                }
            }
            if (txtName.Text == "")
            {
                MessageBox.Show("Xin hãy điền tên của loại sản phẩm.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            return(true);
        }
예제 #5
0
        private void xóaFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (grvData.SelectedRows.Count == 0)
            {
                return;
            }
            int id = TextUtils.ToInt(grvData.SelectedRows[0].Cells[colID.Name].Value);

            if (id == 0)
            {
                return;
            }
            try
            {
                dtFile = dtFile.Select("ID <> '" + id + "'").CopyToDataTable();
            }
            catch (Exception)
            {
                dtFile.Rows.Clear();
            }
            grvData.AutoGenerateColumns = false;
            grvData.DataSource          = null;
            grvData.DataSource          = dtFile;
        }
예제 #6
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            int focus = TextUtils.ToInt(grvData.FocusedRowHandle);
            int id    = TextUtils.ToInt(treeData.FocusedNode.GetValue(colIDTree));
            int CDID  = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colID));

            if (id == 0 || CDID == 0)
            {
                return;
            }
            AssemblyStockModel model = (AssemblyStockModel)AssemblyStockBO.Instance.FindByPK(id);

            StockCDModel model1 = (StockCDModel)StockCDBO.Instance.FindByPK(CDID);
            frmCD        frm    = new frmCD();

            frm._Stock   = model;
            frm._StockCD = model1;
            if (frm.ShowDialog() == DialogResult.OK)
            {
                LoadInfoSearch();
                grvData.FocusedRowHandle = focus;
                //grvData.SelectRow(focus);
            }
        }
예제 #7
0
 private void btnEditGroup_Click(object sender, EventArgs e)
 {
     try
     {
         int id = TextUtils.ToInt(treeData.FocusedNode.GetValue(colIDTree));
         if (id == 0)
         {
             return;
         }
         PBDLStructureModel model = (PBDLStructureModel)PBDLStructureBO.Instance.FindByPK(id);
         frmPBDLStructure   frm   = new frmPBDLStructure();
         frm.Model        = model;
         frm.ParentID     = model.ParentID;
         frm.DepartmentID = TextUtils.ToInt(cboParent.SelectedValue);
         if (frm.ShowDialog() == DialogResult.OK)
         {
             _curentNode = frm.CurentNode;
             loadTree();
         }
     }
     catch (Exception)
     {
     }
 }
예제 #8
0
        private void btnDeleteVoucher_Click(object sender, EventArgs e)
        {
            if (Case.IsLocked)
            {
                MessageBox.Show("Không thể xóa chứng từ do vụ việc này đã được chốt.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            int voucherID = TextUtils.ToInt(grvDebt.GetFocusedRowCellValue(colDebtID));

            if (voucherID > 0)
            {
                if (MessageBox.Show("Bạn có chắc muốn xóa chứng từ này không?",
                                    TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                CaseVoucherDebtBO.Instance.Delete(voucherID);
            }
            else
            {
                grvDebt.DeleteSelectedRows();
            }
        }
예제 #9
0
        private void btnTongHopVanDe_Click(object sender, EventArgs e)
        {
            grvProject.FocusedRowHandle = -1;

            DataTable dtProject = (DataTable)grdProject.DataSource;

            DataRow[] drs = dtProject.Select("check = 1");

            if (drs.Length == 0)
            {
                return;
            }

            string listProject = "'";

            for (int i = 0; i < drs.Length; i++)
            {
                if (i == (drs.Length - 1))
                {
                    listProject += drs[i]["ProjectCode"] + "'";
                }
                else
                {
                    listProject += drs[i]["ProjectCode"] + ",";
                }
            }

            //string projectCode = TextUtils.ToString(grvProject.GetFocusedRowCellValue(colPProjectCode));

            string    sql = "exec spProjectProblemSummary ''," + listProject;
            DataTable dt  = LibQLSX.Select(sql);

            if (dt.Rows.Count == 0)
            {
                return;
            }

            string localPath        = "";
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                localPath = fbd.SelectedPath + "\\TongHopVanDe - " + DateTime.Now.ToString("dd-MM-yyyy") + ".xlsx";
            }
            else
            {
                return;
            }

            string filePath = Application.StartupPath + "\\Templates\\PhongDuAn\\TongHopVanDe.xlsx";

            try
            {
                File.Copy(filePath, localPath, true);
            }
            catch
            {
                MessageBox.Show("Lỗi: File excel đang được mở.");
                return;
            }

            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo biểu mẫu..."))
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
                Excel.Application app       = default(Excel.Application);
                Excel.Workbook    workBoook = default(Excel.Workbook);
                Excel.Worksheet   workSheet = default(Excel.Worksheet);
                try
                {
                    app = new Excel.Application();
                    app.Workbooks.Open(localPath);
                    workBoook = app.Workbooks[1];
                    workSheet = (Excel.Worksheet)workBoook.Worksheets[1];



                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string projectCode   = TextUtils.ToString(dt.Rows[i]["ProjectCode"]);
                        string nguoiPhuTrach = TextUtils.ToString(LibQLSX.ExcuteScalar("select top 1 UserName from vProject where ProjectCode = '" + projectCode + "'"));

                        workSheet.Cells[5, 1] = i + 1;
                        workSheet.Cells[5, 2] = projectCode;
                        workSheet.Cells[5, 3] = nguoiPhuTrach;

                        workSheet.Cells[5, 4] = TextUtils.ToInt(dt.Rows[i]["Total"]);
                        workSheet.Cells[5, 5] = TextUtils.ToInt(dt.Rows[i]["Total_CXL"]);

                        //workSheet.Cells[5, 6] = TextUtils.ToString(dt.Rows[i][""]);
                        //workSheet.Cells[5, 7] = TextUtils.ToString(dt.Rows[i][""]);

                        workSheet.Cells[5, 8] = TextUtils.ToInt(dt.Rows[i]["TotalTK"]);
                        workSheet.Cells[5, 9] = TextUtils.ToInt(dt.Rows[i]["TotalTK_CXL"]);

                        workSheet.Cells[5, 10] = TextUtils.ToInt(dt.Rows[i]["TotalVT"]);
                        workSheet.Cells[5, 11] = TextUtils.ToInt(dt.Rows[i]["TotalVT_CXL"]);

                        workSheet.Cells[5, 12] = TextUtils.ToInt(dt.Rows[i]["TotalSXLR"]);
                        workSheet.Cells[5, 13] = TextUtils.ToInt(dt.Rows[i]["TotalSXLR_CXL"]);

                        workSheet.Cells[5, 14] = TextUtils.ToInt(dt.Rows[i]["TotalSV"]);
                        workSheet.Cells[5, 15] = TextUtils.ToInt(dt.Rows[i]["TotalSV_CXL"]);

                        workSheet.Cells[5, 16] = TextUtils.ToInt(dt.Rows[i]["TotalCG"]);
                        workSheet.Cells[5, 17] = TextUtils.ToInt(dt.Rows[i]["TotalCG_CXL"]);

                        workSheet.Cells[5, 18] = TextUtils.ToString(dt.Rows[i]["TotalKhac"]);
                        workSheet.Cells[5, 19] = TextUtils.ToString(dt.Rows[i]["TotalKhac_CXL"]);

                        //workSheet.Cells[5, 20] = TextUtils.ToString(dt.Rows[i][""]);

                        ((Excel.Range)workSheet.Rows[5]).Insert();
                    }

                    ((Excel.Range)workSheet.Rows[4]).Delete();
                    ((Excel.Range)workSheet.Rows[4]).Delete();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (app != null)
                    {
                        app.ActiveWorkbook.Save();
                        app.Workbooks.Close();
                        app.Quit();
                    }
                }
            }

            Process.Start(localPath);
        }
예제 #10
0
        void addModule(string moduleCode, string moduleName, int ID, int parentID, int qty, string manageId, string moduleCodeHD)
        {
            string    typeID = "T0068";
            DataTable dt     = LibQLSX.Select("select TypeId from SourceCode with(nolock) where FolderCode = '" + moduleCode + "'");

            if (dt.Rows.Count > 0)
            {
                typeID = TextUtils.ToString(dt.Rows[0]["TypeId"]);
            }

            ProjectProductsModel projectProduct = new ProjectProductsModel();

            if (parentID == 0)
            {
                if (moduleCode.StartsWith("TPAD"))
                {
                    DataTable dtPP = LibQLSX.Select("select * from vGetProductOfProject with(nolock) where ManageId = '" + manageId + "' and PPCode = '" + moduleCodeHD + "'");
                    foreach (DataRow row in dtPP.Rows)
                    {
                        string id = TextUtils.ToString(row["PProductId"]);

                        #region Create ProjectModule
                        DataTable dtPMID = LibQLSX.Select(" SELECT top 1 ProjectModuleId FROM ProjectModule with(nolock) order by ProjectModuleId desc");
                        string    PMid   = TextUtils.ToString(dtPMID.Rows[0]["ProjectModuleId"]);
                        PMid = PMid.Substring(2, PMid.Length - 2);
                        PMid = "PM" + string.Format("{0:00000000}", TextUtils.ToInt(PMid) + 1);

                        ProjectModuleModel projectModule = new ProjectModuleModel();
                        projectModule.IsModuleStandard  = 0;
                        projectModule.Note              = "";
                        projectModule.ProjectModuleCode = moduleCode;
                        projectModule.ProjectModuleName = moduleName;
                        projectModule.Specifications    = "";

                        projectModule.ProjectModuleId = PMid;
                        ProjectModuleBO.Instance.InsertQLSX(projectModule);
                        #endregion

                        #region Update ProjectProducts
                        ArrayList listPP = ProjectProductsBO.Instance.FindByAttribute("PProductId", id);
                        projectProduct = (ProjectProductsModel)listPP[0];
                        projectProduct.ProjectModuleId = PMid;
                        projectProduct.TypeId          = typeID;
                        ProjectProductsBO.Instance.UpdateQLSX(projectProduct);
                        #endregion

                        #region Create ChildModule
                        DataRow[] drsChild = _dtModule.Select("ParentID = " + ID);
                        if (drsChild.Length > 0)
                        {
                            foreach (DataRow item in drsChild)
                            {
                                string moduleCode1 = TextUtils.ToString(item["F5"]);
                                string moduleName1 = TextUtils.ToString(item["F3"]);
                                int    ID1         = TextUtils.ToInt(item["ID"]);
                                int    parentID1   = TextUtils.ToInt(item["ParentID"]);
                                int    qty1        = TextUtils.ToInt(item["F7"]);
                                string manageId1   = projectProduct.PProductId;
                                addModule(moduleCode1, moduleName1, ID1, parentID1, qty1, manageId1, "");
                            }
                        }
                        #endregion
                    }
                }
                else //Nếu là vật tư phụ
                {
                    #region Create ProjectModule
                    DataTable dtPMID = LibQLSX.Select(" SELECT top 1 ProjectModuleId FROM ProjectModule with(nolock) order by ProjectModuleId desc");
                    string    PMid   = TextUtils.ToString(dtPMID.Rows[0]["ProjectModuleId"]);
                    PMid = PMid.Substring(2, PMid.Length - 2);
                    PMid = "PM" + string.Format("{0:00000000}", TextUtils.ToInt(PMid) + 1);

                    ProjectModuleModel projectModule = new ProjectModuleModel();
                    projectModule.IsModuleStandard  = 0;
                    projectModule.Note              = "";
                    projectModule.ProjectModuleCode = moduleCode;
                    projectModule.ProjectModuleName = moduleName;
                    projectModule.Specifications    = "";

                    projectModule.ProjectModuleId = PMid;
                    ProjectModuleBO.Instance.InsertQLSX(projectModule);
                    #endregion

                    #region Create ProjectProducts
                    DataTable dtPPID = LibQLSX.Select(" SELECT top 1 PProductId FROM ProjectProducts with(nolock) order by PProductId desc");
                    string    PPid   = TextUtils.ToString(dtPPID.Rows[0]["PProductId"]);
                    PPid = PPid.Substring(2, PPid.Length - 2);
                    PPid = "PP" + string.Format("{0:00000000}", TextUtils.ToInt(PPid) + 1);

                    projectProduct.DepartmentCreateId     = "D009";
                    projectProduct.DepartmentDesignId     = "D009";
                    projectProduct.ManageId               = manageId;
                    projectProduct.ManufacturerId         = "M000000001";
                    projectProduct.PProductInforId        = "";
                    projectProduct.ProjectId              = TextUtils.ToString(grvProject.GetFocusedRowCellValue(colProjectID));
                    projectProduct.ProjectModuleId        = projectModule.ProjectModuleId;
                    projectProduct.Status                 = 2;
                    projectProduct.StatusCheckDesignInfor = 1;
                    projectProduct.StatusConfirm          = 1;
                    projectProduct.Total  = qty;
                    projectProduct.TypeId = typeID;
                    projectProduct.Origin = "Việt Nam";

                    projectProduct.PProductId = PPid;
                    ProjectProductsBO.Instance.InsertQLSX(projectProduct);
                    #endregion
                }
            }
            else //nếu là module con
            {
                #region Create ProjectModule
                DataTable dtPMID = LibQLSX.Select(" SELECT top 1 ProjectModuleId FROM ProjectModule with(nolock) order by ProjectModuleId desc");
                string    PMid   = TextUtils.ToString(dtPMID.Rows[0]["ProjectModuleId"]);
                PMid = PMid.Substring(2, PMid.Length - 2);
                PMid = "PM" + string.Format("{0:00000000}", TextUtils.ToInt(PMid) + 1);

                ProjectModuleModel projectModule = new ProjectModuleModel();
                projectModule.IsModuleStandard  = 0;
                projectModule.Note              = "";
                projectModule.ProjectModuleCode = moduleCode;
                projectModule.ProjectModuleName = moduleName;
                projectModule.Specifications    = "";

                projectModule.ProjectModuleId = PMid;
                ProjectModuleBO.Instance.InsertQLSX(projectModule);
                #endregion

                #region Create ProjectProducts
                DataTable dtPPID = LibQLSX.Select(" SELECT top 1 PProductId FROM ProjectProducts with(nolock) order by PProductId desc");
                string    PPid   = TextUtils.ToString(dtPPID.Rows[0]["PProductId"]);
                PPid = PPid.Substring(2, PPid.Length - 2);
                PPid = "PP" + string.Format("{0:00000000}", TextUtils.ToInt(PPid) + 1);

                projectProduct.DepartmentCreateId     = "D009";
                projectProduct.DepartmentDesignId     = "D009";
                projectProduct.ManageId               = manageId;
                projectProduct.ManufacturerId         = "M000000001";
                projectProduct.PProductInforId        = "";
                projectProduct.ProjectId              = TextUtils.ToString(grvProject.GetFocusedRowCellValue(colProjectID));
                projectProduct.ProjectModuleId        = projectModule.ProjectModuleId;
                projectProduct.Status                 = 2;
                projectProduct.StatusCheckDesignInfor = 1;
                projectProduct.StatusConfirm          = 1;
                projectProduct.Total  = qty;
                projectProduct.TypeId = typeID;
                projectProduct.Origin = "Việt Nam";

                projectProduct.PProductId = PPid;
                ProjectProductsBO.Instance.InsertQLSX(projectProduct);
                #endregion

                #region Create ChildModule
                DataRow[] drsChild = _dtModule.Select("ParentID = " + ID);
                if (drsChild.Length > 0)
                {
                    foreach (DataRow item in drsChild)
                    {
                        string moduleCode1 = TextUtils.ToString(item["F5"]);
                        string moduleName1 = TextUtils.ToString(item["F3"]);
                        int    ID1         = TextUtils.ToInt(item["ID"]);
                        int    parentID1   = TextUtils.ToInt(item["ParentID"]);
                        int    qty1        = TextUtils.ToInt(item["F7"]);
                        string manageId1   = projectProduct.PProductId;
                        addModule(moduleCode1, moduleName1, ID1, parentID1, qty1, manageId1, "");
                    }
                }
                #endregion
            }
        }
예제 #11
0
 void loadHistory()
 {
     _dtHistory            = TextUtils.Select("select * from TheoDoiHistory with(nolock) where TheoDoiID = " + WorkDiary.ID);
     grdHistory.DataSource = _dtHistory;
 }
예제 #12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();

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

                Model.ProjectCode      = txtProjectCode.Text.Trim();
                Model.ProjectName      = txtProjectName.Text.Trim();
                Model.ContractCode     = txtContractCode.Text.Trim();
                Model.ContractName     = txtContractName.Text.Trim();
                Model.Curator          = txtCurator.Text.Trim();
                Model.Reception        = txtReception.Text.Trim();
                Model.Requirement      = txtRequirement.Text.Trim();
                Model.Status           = cboStatus.SelectedIndex;
                Model.CustomerName     = txtCustomerName.Text.Trim();
                Model.LastCustomerName = txtLastCustomerName.Text.Trim();
                Model.Priority         = txtPriority.Text.Trim();
                Model.Description      = txtDescription.Text.Trim();

                if (Model.ID == 0)
                {
                    Model.CreatedDate = TextUtils.GetSystemDate();
                    Model.CreatedBy   = Global.AppUserName;
                    Model.UpdatedDate = Model.CreatedDate;
                    Model.UpdatedBy   = Global.AppUserName;
                    Model.ID          = (int)pt.Insert(Model);
                }
                else
                {
                    Model.UpdatedDate = TextUtils.GetSystemDate();
                    Model.UpdatedBy   = Global.AppUserName;
                    pt.Update(Model);
                }

                if (_listProducts.Count > 0)
                {
                    foreach (ProductsModel item in _listProducts)
                    {
                        item.CreatedBy     = Global.AppUserName;
                        item.CreatedDate   = TextUtils.GetSystemDate();
                        item.UpdatedDate   = item.CreatedDate;
                        item.UpdatedBy     = Global.AppUserName;
                        item.ProjectInfoID = Model.ID;
                        pt.Insert(item);
                    }
                }
                //MessageBox.Show("Lưu trữ thành công!", "Thông báo");
                pt.CommitTransaction();
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                pt.CloseConnection();
            }
        }
예제 #13
0
        private void cboSheet_SelectionChangeCommitted(object sender, EventArgs e)
        {
            grvData.Columns.Clear();
            if (chkAutoCheck.Checked)
            {
                try
                {
                    DataTable dtt = ds.Tables[cboSheet.SelectedIndex];

                    dtt.Columns.Add("DATEF2", typeof(DateTime));
                    for (int i = 0; i < dtt.Rows.Count; i++)
                    {
                        if (i < 1
                            )
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(Lib.ToString(dtt.Rows[i]["F1"])))
                        {
                            continue;
                        }
                        if (Lib.ToString(dtt.Rows[i]["F2"]).Trim() != "")
                        {
                            dtt.Rows[i]["DATEF2"] = DateTime.FromOADate(TextUtils.ToDouble(dtt.Rows[i]["F2"]));
                        }
                    }

                    dtt.Columns.Add("DATEF3", typeof(DateTime));
                    for (int i = 0; i < dtt.Rows.Count; i++)
                    {
                        if (i < 1
                            )
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(Lib.ToString(dtt.Rows[i]["F1"])))
                        {
                            continue;
                        }
                        if (Lib.ToString(dtt.Rows[i]["F3"]).Trim() != "")
                        {
                            dtt.Rows[i]["DATEF3"] = DateTime.FromOADate(TextUtils.ToDouble(dtt.Rows[i]["F3"]));
                        }
                    }
                    grdData.DataSource = dtt;
                    grvData.PopulateColumns();
                    grvData.BestFitColumns();
                    grdData.Focus();
                }
                catch (Exception ex)
                {
                    TextUtils.ShowError(ex);
                    grdData.DataSource = null;
                }
            }
            else
            {
                try
                {
                    DataTable dt = TextUtils.ExcelToDatatableNoHeader(btnBrowse.Text, cboSheet.SelectedValue.ToString());
                    // thêm 1 cột date mới
                    dt.Columns.Add("DATEF2", typeof(DateTime));
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (i < 1
                            )
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(Lib.ToString(dt.Rows[i]["F1"])))
                        {
                            continue;
                        }
                        if (Lib.ToString(dt.Rows[i]["F2"]).Trim() != "")
                        {
                            dt.Rows[i]["DATEF2"] = DateTime.FromOADate(TextUtils.ToDouble(dt.Rows[i]["F2"]));
                        }
                    }

                    dt.Columns.Add("DATEF3", typeof(DateTime));
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        if (i < 1
                            )
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(Lib.ToString(dt.Rows[i]["F1"])))
                        {
                            continue;
                        }
                        if (Lib.ToString(dt.Rows[i]["F3"]).Trim() != "")
                        {
                            dt.Rows[i]["DATEF3"] = DateTime.FromOADate(TextUtils.ToDouble(dt.Rows[i]["F3"]));
                        }
                    }



                    grdData.DataSource = dt;
                    grvData.PopulateColumns();
                    grvData.BestFitColumns();
                    grdData.Focus();

                    //grvData.Columns[3].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                    //grvData.Columns[3].DisplayFormat.FormatString = "dd/MM/yyyy";
                }
                catch (Exception ex)
                {
                    TextUtils.ShowError(ex);
                    grdData.DataSource = null;
                }
            }
        }
예제 #14
0
        private void btnBaoGia_Click(object sender, EventArgs e)
        {
            frmBaoGia frm = new frmBaoGia();

            TextUtils.OpenForm(frm);
        }
예제 #15
0
        private bool ValidateForm()
        {
            if (txtCode.Text.Trim() == "")
            {
                MessageBox.Show("Xin hãy điền Mã nhân viên.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            else
            {
                DataTable dt;
                if (Model.ID > 0)
                {
                    dt = TextUtils.Select("select Code from Users where Code = '" + txtCode.Text.Trim() + "' and ID <> " + Model.ID);
                }
                else
                {
                    dt = TextUtils.Select("select Code from Users where Code = '" + txtCode.Text.Trim() + "'");
                }
                if (dt != null)
                {
                    if (dt.Rows.Count > 0)
                    {
                        MessageBox.Show("Mã nhân viên này đã được sử dụng!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return(false);
                    }
                }
            }
            if (txtFullName.Text.Trim() == "")
            {
                MessageBox.Show("Xin hãy điền Tên nhân viên.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            if (chkHasUser.Checked)
            {
                if (txtPasswordHash.Text.Trim() == "")
                {
                    MessageBox.Show("Xin hãy điền Mật khẩu.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return(false);
                }
                if (txtLoginName.Text.Trim() == "")
                {
                    MessageBox.Show("Xin hãy điền Tên đăng nhập.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return(false);
                }
                else
                {
                    DataTable dt;
                    if (Model.ID > 0)
                    {
                        dt = TextUtils.Select("select LoginName from Users where LoginName = '" + txtLoginName.Text.Trim() + "' and ID <> " + Model.ID);
                    }
                    else
                    {
                        dt = TextUtils.Select("select LoginName from Users where LoginName = '" + txtLoginName.Text.Trim() + "'");
                    }
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            MessageBox.Show("Tên đăng nhập này đã được sử dụng!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            return(false);
                        }
                    }
                }
            }

            if (TextUtils.ToInt(cboDepartment.SelectedValue) <= 0)
            {
                MessageBox.Show("Làm ơn nhập phòng ban!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            if (dtpStartWorking.EditValue == null)
            {
                MessageBox.Show("Làm ơn nhập Ngày vào công ty!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            if (dtpBirthOfDate.EditValue == null)
            {
                MessageBox.Show("Làm ơn nhập Ngày sinh nhân viên!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            if (txtQualifications.Text.Trim() == "")
            {
                MessageBox.Show("Làm ơn nhập Trình độ học vấn!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            if (txtCMTND.Text.Trim() == "")
            {
                MessageBox.Show("Làm ơn nhập Số CMTND!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }

            if (cboStatus.SelectedIndex < 0)
            {
                MessageBox.Show("Bạn phải chọn một trạng thái!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            return(true);
        }
예제 #16
0
        void KiemTraVatTu()
        {
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang kiem tra..."))
            {
                string[] listFilePath = Directory.GetFiles("D:/ListDMVT");
                foreach (string filePath in listFilePath)
                {
                    try
                    {
                        string    moduleCode = Path.GetFileName(filePath).Substring(3, 10);
                        DataTable dtDMVT     = TextUtils.ExcelToDatatableNoHeader(filePath, "DMVT");
                        var       results    = from myRow in dtDMVT.AsEnumerable()
                                               where TextUtils.ToDecimal(myRow.Field <string>("F1")) > 0 &&
                                               !(myRow.Field <string>("F4")).StartsWith("TPAD") &&
                                               !(myRow.Field <string>("F4")).StartsWith("PCB")
                                               select myRow;
                        if (results.Count() == 0)
                        {
                            continue;
                        }

                        dtDMVT = results.CopyToDataTable();

                        for (int i = 0; i <= dtDMVT.Rows.Count - 1; i++)
                        {
                            string nameDMVT = dtDMVT.Rows[i][3].ToString();
                            if (nameDMVT == "")
                            {
                                continue;
                            }
                            string hang = dtDMVT.Rows[i][9].ToString();

                            List <string> errorString = new List <string>();

                            #region Kiem tra hang co hop le
                            DataTable dtGroup = TextUtils.Select("select CustomerCode from vMaterialCustomer a where replace(a.Code,' ','') ='" + nameDMVT.Replace(" ", "").Replace("(", "/") + "'");
                            if (dtGroup.Rows.Count > 0)
                            {
                                DataRow[] drsCustomer = dtGroup.Select("CustomerCode = '" + hang + "'");
                                if (drsCustomer.Count() == 0)
                                {
                                    errorString.Add("Hãng không được sử dụng");
                                }
                            }
                            #endregion

                            #region Vật tư ngừng sử dụng

                            DataTable dtViewMaterial = TextUtils.Select("SELECT MaterialGroupCode FROM [vMaterial] with (nolock) where replace(Code,' ','') = '" + nameDMVT.Replace(" ", "").Replace(")", "/") + "'");
                            if (dtViewMaterial.Rows.Count > 0)
                            {
                                string materialGroupCode = dtViewMaterial.Rows[0][0].ToString();
                                if (materialGroupCode == "TPAVT.Z01")
                                {
                                    errorString.Add("Vật tư ngừng sử dụng");
                                }
                            }
                            #endregion

                            #region Vật tư tạm dừng sử dụng
                            DataTable dtMaterialCSDL = TextUtils.Select("SELECT * FROM [Material] with (nolock) where [StopStatus] = 1 and replace(Code,' ','') = '" + nameDMVT.Replace(" ", "").Replace(")", "/") + "'");
                            if (dtMaterialCSDL.Rows.Count > 0)
                            {
                                errorString.Add("Vật tư tạm dừng sử dụng");
                            }
                            #endregion

                            #region Kiểm tra trên quản lý sản xuất
                            //Kiem tra xem vat tu co trong kho chua
                            DataTable dtMaterialQLSX = LibQLSX.Select("SELECT top 1 p.PartsCode,m.ManufacturerCode"
                                                                      + " FROM Manufacturer m RIGHT OUTER JOIN"
                                                                      + " PartsManufacturer pm ON m.ManufacturerId = pm.ManufacturerId RIGHT OUTER JOIN"
                                                                      + " Parts p ON pm.PartsId = p.PartsId"
                                                                      + " where p.PartsCode = '" + nameDMVT.Replace(" ", "").Replace("(", "/") + "'");
                            if (dtMaterialQLSX.Rows.Count == 0)
                            {
                                errorString.Add("Vật tư không tồn tại");
                            }
                            else
                            {
                                if (dtMaterialQLSX.Rows[0]["ManufacturerCode"].ToString().ToUpper() != hang.ToUpper())
                                {
                                    errorString.Add("Hãng khác với hãng trên QLSX (" + hang + " - " + dtMaterialQLSX.Rows[0]["ManufacturerCode"].ToString() + ")");
                                }
                            }
                            #endregion

                            if (errorString.Count > 0)
                            {
                                TestModel model = new TestModel();
                                model.ModuleCode   = moduleCode;
                                model.MaterialCode = nameDMVT;
                                model.MaterialName = dtDMVT.Rows[i]["F2"].ToString();
                                model.Hang         = hang;
                                model.Error        = string.Join(", ", errorString.ToArray());
                                TestBO.Instance.Insert(model);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            MessageBox.Show("ok");
        }
예제 #17
0
        void KiemTraVatTu_VatLieu()
        {
            DataTable dtError = new DataTable();

            dtError.Columns.Add("ModuleCode");
            dtError.Columns.Add("STT");
            dtError.Columns.Add("MaterialCode");
            dtError.Columns.Add("MaterialName");
            dtError.Columns.Add("MaVatLieu");
            dtError.Columns.Add("VatLieu");
            dtError.Columns.Add("Error");

            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang kiem tra..."))
            {
                string[] listFilePath = Directory.GetFiles("D:/ListDMVT");
                foreach (string filePath in listFilePath)
                {
                    try
                    {
                        string    moduleCode = Path.GetFileName(filePath).Substring(3, 10);
                        DataTable dtDMVT     = TextUtils.ExcelToDatatableNoHeader(filePath, "DMVT");

                        var results = from myRow in dtDMVT.AsEnumerable()
                                      where TextUtils.ToDecimal(myRow.Field <string>("F1") != "" && myRow.Field <string>("F1") != null
                                      ? myRow.Field <string>("F1").Substring(0, 1) : "") > 0
                                      select myRow;

                        if (results == null)
                        {
                            continue;
                        }
                        if (results.Count() == 0)
                        {
                            continue;
                        }
                        if (results.Count() > 0)
                        {
                            dtDMVT = results.CopyToDataTable();
                        }

                        for (int i = 0; i <= dtDMVT.Rows.Count - 1; i++)
                        {
                            string nameDMVT = dtDMVT.Rows[i]["F4"].ToString();
                            if (nameDMVT == "")
                            {
                                continue;
                            }
                            //string hang = dtDMVT.Rows[i][9].ToString();
                            string MaVatLieu = TextUtils.ToString(dtDMVT.Rows[i]["F5"]).Trim();
                            string VatLieu   = TextUtils.ToString(dtDMVT.Rows[i]["F8"]).Trim();
                            string stt       = TextUtils.ToString(dtDMVT.Rows[i]["F1"]).Trim();

                            List <string> errorString = new List <string>();

                            if (MaVatLieu != "")
                            {
                                DataTable dtMaVatLieu = LibQLSX.Select("SELECT top 1 PartsCode from Parts with(nolock)"
                                                                       + " where PartsCode = N'" + MaVatLieu.Replace(" ", "").Replace("(", "/") + "'");
                                if (dtMaVatLieu.Rows.Count == 0)
                                {
                                    errorString.Add("Mã vật liệu không tồn tại trên QLSX");
                                }
                            }

                            if (VatLieu != "" && VatLieu != "-")
                            {
                                DataTable dtVatLieu = LibQLSX.Select("SELECT top 1 MaterialsId from MaterialsModel with(nolock)"
                                                                     + " where MaterialsId = N'" + VatLieu + "'");
                                if (dtVatLieu.Rows.Count == 0)
                                {
                                    errorString.Add("Vật tư không tồn tại trên QLSX");
                                }
                            }

                            if (MaVatLieu != "" && (VatLieu == "" || VatLieu == "-"))
                            {
                                errorString.Add("Vật tư không có vật liệu");
                            }

                            if (errorString.Count > 0)
                            {
                                DataRow dr = dtError.NewRow();
                                dr["ModuleCode"]   = moduleCode;
                                dr["STT"]          = stt;
                                dr["MaterialCode"] = nameDMVT;
                                dr["MaterialName"] = TextUtils.ToString(dtDMVT.Rows[i]["F2"]);
                                dr["MaVatLieu"]    = MaVatLieu;
                                dr["VatLieu"]      = VatLieu;
                                dr["Error"]        = string.Join(", ", errorString.ToArray());
                                dtError.Rows.Add(dr);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            gridControl1.DataSource = dtError;
            MessageBox.Show("ok");
        }
예제 #18
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();
            try
            {
                if (!ValidateForm())
                {
                    return;
                }

                Model.BankAccount = txtBankAccount.Text.Trim();
                Model.BHXH        = txtBHXH.Text.Trim();
                Model.BHYT        = txtBHYT.Text.Trim();
                try
                {
                    Model.BirthOfDate = TextUtils.ToDate3(dtpBirthOfDate.EditValue);
                }
                catch
                {
                    Model.BirthOfDate = DateTime.Now;
                }

                Model.CMTND          = txtCMTND.Text.Trim();
                Model.Code           = txtCode.Text.Trim();
                Model.DepartmentID   = TextUtils.ToInt(cboDepartment.SelectedValue);
                Model.Email          = txtEmail.Text.Trim();
                Model.EmailCom       = txtEmailCom.Text.Trim();
                Model.FullName       = txtFullName.Text;
                Model.HandPhone      = txtTelephone.Text;
                Model.HomeAddress    = txtHomeAddress.Text;
                Model.JobDescription = txtJobDescription.Text.Trim();
                Model.MST            = txtMST.Text.Trim();
                Model.Position       = txtPosition.Text;
                Model.Qualifications = txtQualifications.Text.Trim();
                Model.Sex            = cboSex.SelectedIndex;
                Model.UserGroupID    = TextUtils.ToInt(lookUpEdit1.EditValue);
                Model.UserGroupSXID  = TextUtils.ToInt(cboGroup.EditValue);

                try
                {
                    Model.StartWorking = TextUtils.ToDate3(dtpStartWorking.EditValue);
                }
                catch
                {
                    Model.StartWorking = DateTime.Now;
                }

                Model.ImagePath = pictureBox1.ImageLocation;
                Model.Status    = cboStatus.SelectedIndex;

                if (chkHasUser.Checked)
                {
                    Model.LoginName    = txtLoginName.Text.Trim();
                    Model.PasswordHash = MD5.EncryptPassword(txtPasswordHash.Text.Trim());
                }
                else
                {
                    Model.LoginName    = "";
                    Model.PasswordHash = "";
                }

                Model.UpdatedDate = Model.CreatedDate;
                Model.UpdatedBy   = Global.AppUserName;

                if (Model.ID == 0)
                {
                    Model.CreatedDate = TextUtils.GetSystemDate();
                    Model.CreatedBy   = Global.AppUserName;

                    Model.ID = (int)pt.Insert(Model);
                }
                else
                {
                    pt.Update(Model);
                }
                pt.CommitTransaction();

                //Update mã nhân viên cho bên QLSX
                if (Model.LoginName != "")
                {
                    string pId = TextUtils.ToString(TextUtils.ExcuteScalar("select top 1 PId from [Department] with(nolock) where ID = " + TextUtils.ToInt(cboDepartment.SelectedValue)));
                    LibQLSX.ExcuteSQL("update Users set Code = '" + Model.Code + "', UserGroup1ID = " + Model.UserGroupSXID + ", [DepartmentId1]= '" + pId + "' where Account = '" + Model.LoginName + "'");
                }

                MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (this.LoadDataChange != null)
                {
                    this.LoadDataChange(null, null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                pt.CloseConnection();
            }
        }
예제 #19
0
        void loadGrid()
        {
            DataTable dt = TextUtils.Select("select * from Test");

            gridControl1.DataSource = dt;
        }
예제 #20
0
 private void btnExecl_Click(object sender, EventArgs e)
 {
     TextUtils.ExportExcel(grvData);
 }
예제 #21
0
        private void btnBrowse_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            grvData.Columns.Clear();
            OpenFileDialog ofd = new OpenFileDialog();

            if (chkAutoCheck.Checked)
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                var            result          = openFileDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    btnBrowse.Text = openFileDialog1.FileName;
                }
                else if (result == DialogResult.Cancel)
                {
                    return;
                }

                try
                {
                    var stream = new FileStream(btnBrowse.Text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

                    var sw = new Stopwatch();
                    sw.Start();

                    IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream);

                    var openTiming = sw.ElapsedMilliseconds;

                    ds = reader.AsDataSet(new ExcelDataSetConfiguration()
                    {
                        UseColumnDataType  = false,
                        ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
                        {
                            UseHeaderRow = false
                        }
                    });
                    //toolStripStatusLabel1.Text = "Elapsed: " + sw.ElapsedMilliseconds.ToString() + " ms (" + openTiming.ToString() + " ms to open)";

                    var tablenames = GetTablenames(ds.Tables);

                    cboSheet.DataSource = tablenames;

                    if (tablenames.Count > 0)
                    {
                        cboSheet.SelectedIndex = 0;
                    }
                    btnSave.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    btnBrowse.Text      = ofd.FileName;
                    cboSheet.DataSource = null;
                    cboSheet.DataSource = TextUtils.ListSheetInExcel(ofd.FileName);
                    btnSave.Enabled     = true;
                }
            }
        }
예제 #22
0
        private void btnReloadData_Click(object sender, EventArgs e)
        {
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang load dữ liệu..."))
            {
                string dCode = TextUtils.ToString(cboPhongBan.EditValue);
                int    dID   = TextUtils.ToInt(grvCboPhongBan.GetFocusedRowCellValue(colPhanXuongID));
                int    year  = TextUtils.ToInt(cboYear.SelectedItem);

                DataTable dtData = new DataTable();

                if (dCode.ToUpper() == "P21")
                {
                    string sql = "exec spReportChiPhi_BanGiamDoc " + year;
                    dtData = LibIE.Select(sql);
                }
                else
                {
                    string sql = "exec spReportChiPhi " + year + ", '" + dCode + "'";
                    dtData = LibIE.Select(sql);
                }

                DataRow[] drs = dtData.Select("C_MA = 'C17'");

                if (dCode.ToUpper() == "P21" || dCode.ToUpper() == "P13" || dCode.ToUpper() == "P14") // Ban giam doc, kinh doanh cn, kinh doanh day nghe
                {
                    string    sql      = "SELECT Sum(ISNULL(C_PSNO,0)) XangXe,C_Month FROM [V_XNTC_REPORT] where (C_KMP_MA = 'C17') and C_Year = " + year + " Group by C_Month";
                    DataTable dtXangXe = LibIE.Select(sql);
                    decimal   tyle     = TextUtils.ToDecimal(LibIE.ExcuteScalar("select top 1 TYLE from T_DM_PHANXUONG_KMP where PK_KMP = 41 and PK_PHANXUONG = " + dID));

                    decimal total = 0;
                    for (int i = 1; i <= 12; i++)
                    {
                        try
                        {
                            decimal value    = TextUtils.ToDecimal(dtXangXe.Rows[i - 1]["XangXe"]);
                            decimal giaTriPB = tyle * value / 100;
                            drs[0]["T" + i + "_PB"] = giaTriPB;
                            drs[0]["T" + i]         = giaTriPB;
                            drs[0]["T" + i + "_TT"] = 0;

                            total += giaTriPB;
                        }
                        catch (Exception)
                        {
                        }
                    }

                    drs[0]["Total_PB"] = total;
                    drs[0]["Total_TT"] = 0;
                    drs[0]["Total"]    = total;
                }
                else if (dCode != "")
                {
                    for (int i = 1; i <= 12; i++)
                    {
                        drs[0]["T" + i + "_PB"] = 0;
                        drs[0]["T" + i]         = 0;
                        drs[0]["T" + i + "_TT"] = 0;
                    }

                    drs[0]["Total_PB"] = 0;
                    drs[0]["Total_TT"] = 0;
                    drs[0]["Total"]    = 0;
                }
                else
                {
                    for (int i = 1; i <= 12; i++)
                    {
                        drs[0]["T" + i + "_PB"] = TextUtils.ToDecimal(drs[0]["T" + i + "_TT"]);
                        drs[0]["T" + i]         = TextUtils.ToDecimal(drs[0]["T" + i + "_TT"]);
                        drs[0]["T" + i + "_TT"] = 0;
                    }
                    drs[0]["Total_PB"] = TextUtils.ToDecimal(drs[0]["Total_TT"]);
                    drs[0]["Total_TT"] = 0;
                    drs[0]["Total"]    = TextUtils.ToDecimal(drs[0]["Total_PB"]);
                }

                grdData.DataSource = dtData;
            }
        }
예제 #23
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();
            try
            {
                if (!ValidateForm())
                {
                    return;
                }

                WorkDiary.EndDateDK   = dtpEndDateDK.Value;
                WorkDiary.GhiChu      = txtNote.Text.Trim();
                WorkDiary.ModuleCode  = txtModuleCode.Text.Trim();
                WorkDiary.Name        = txtName.Text.Trim();
                WorkDiary.ProjectCode = txtProjectCode.Text.Trim();
                WorkDiary.StartDate   = dtpStartDate.Value;
                WorkDiary.Status      = cboStatus.SelectedIndex;
                //WorkDiary.ThoiGianDuKien = TextUtils.ToInt(txtTime.EditValue);
                WorkDiary.UserID = TextUtils.ToInt(cboUser.EditValue);

                if (cboStatus.SelectedIndex == 1)
                {
                    WorkDiary.EndDate = DateTime.Now;
                }
                else
                {
                    WorkDiary.EndDate = null;
                }

                if (WorkDiary.ID == 0)
                {
                    WorkDiary.ID = (int)pt.Insert(WorkDiary);

                    TheoDoiHistoryModel history = new TheoDoiHistoryModel();
                    history.EndDateDK = WorkDiary.EndDateDK;
                    history.TheoDoiID = WorkDiary.ID;
                    history.Reason    = "Thêm mới";
                    pt.Insert(history);
                }
                else
                {
                    pt.Update(WorkDiary);

                    if (_oldEndDateDK.Date != dtpEndDateDK.Value)
                    {
                        TheoDoiHistoryModel history = new TheoDoiHistoryModel();
                        history.EndDateDK = WorkDiary.EndDateDK;
                        history.TheoDoiID = WorkDiary.ID;
                        history.Reason    = txtReason.Text.Trim();
                        pt.Insert(history);
                    }
                }

                pt.CommitTransaction();
                loadHistory();
                _isSaved = true;
                MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lưu trữ không thành công!" + Environment.NewLine + ex.Message, TextUtils.Caption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                pt.CloseConnection();
            }

            if (_isSaved && this.LoadDataChange != null)
            {
                this.LoadDataChange(null, null);
            }
        }
예제 #24
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();

            decimal tm = 0;
            decimal ck = 0;

            PaymentTableModel PaymentTable = new PaymentTableModel();

            PaymentTable.IsDeleted = false;
            PaymentTable.Note      = "";
            PaymentTable.Number    = loadNumber();
            //PaymentTable.TotalTM = TextUtils.ToDecimal(colTM.SummaryItem.SummaryValue);
            //PaymentTable.TotalCK = TextUtils.ToDecimal(colCK.SummaryItem.SummaryValue);
            PaymentTable.UpdatedBy   = Global.AppUserName;
            PaymentTable.UpdatedDate = DateTime.Now;
            PaymentTable.CreatedBy   = Global.AppUserName;
            PaymentTable.CreatedDate = DateTime.Now;

            PaymentTable.ID = (long)pt.Insert(PaymentTable);

            grvData.FocusedRowHandle = -1;
            for (int i = 0; i < grvData.RowCount; i++)
            {
                if (i < 0)
                {
                    continue;
                }
                bool check = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colCheck));
                if (!check)
                {
                    continue;
                }

                long iD = TextUtils.ToInt64(grvData.GetRowCellValue(i, colID));
                PaymentTableItemModel model = (PaymentTableItemModel)PaymentTableItemBO.Instance.FindByPK(iD);

                PaymentTableModel pay = (PaymentTableModel)PaymentTableBO.Instance.FindByPK(model.PaymentTableID);
                pay.TotalTM -= model.TotalCash;
                pay.TotalCK -= model.TotalCK;
                pt.Update(pay);

                model.PaymentTableID = PaymentTable.ID;
                pt.Update(model);

                tm += model.TotalCash;
                ck += model.TotalCK;
            }

            pt.CommitTransaction();

            PaymentTable.TotalTM = tm;
            PaymentTable.TotalCK = ck;

            PaymentTableItemBO.Instance.Update(PaymentTable);

            loadItems();
        }
예제 #25
0
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang load danh sách module..."))
                {
                    _count    = 0;
                    _dtModule = TextUtils.ExcelToDatatableNoHeader(ofd.FileName, "3");
                    if (_dtModule.Rows.Count == 0)
                    {
                        return;
                    }
                    DataRow[] drs    = _dtModule.Select("F5 like 'TPAD%' and len(F5) = 10 and F12 <> 'VTP'");
                    DataRow[] drsVTP = _dtModule.Select("F4 like 'TB.%'");
                    if (drs.Length > 0)
                    {
                        _dtModule = drs.CopyToDataTable();
                        _dtModule.Columns.Add("ID", typeof(int));
                        _dtModule.Columns.Add("ParentID", typeof(int));
                        _dtModule.Columns.Add("TypeId");
                        int rowCount = _dtModule.Rows.Count;
                        for (int i = 0; i < rowCount; i++)
                        {
                            string moduleCode = TextUtils.ToString(_dtModule.Rows[i]["F5"]);
                            if (i == 0)
                            {
                                _count = 1;
                            }
                            else
                            {
                                _count++;
                            }
                            _dtModule.Rows[i]["ID"]       = _count;
                            _dtModule.Rows[i]["ParentID"] = 0;
                            loadChildModule(moduleCode, _count);
                        }
                        if (drsVTP.Length > 0)
                        {
                            DataRow r = _dtModule.NewRow();
                            r["F3"] = TextUtils.ToString(drsVTP[0]["F3"]);
                            r["F4"] = TextUtils.ToString(drsVTP[0]["F4"]);
                            r["F5"] = TextUtils.ToString(drsVTP[0]["F4"]);
                            r["F7"] = 1.ToString();
                            _count++;
                            r["ID"] = _count;
                            if (rowCount == 1)
                            {
                                r["ParentID"] = TextUtils.ToString(_dtModule.Rows[0]["ID"]);
                            }
                            else
                            {
                                r["ParentID"] = 0;
                            }
                            _dtModule.Rows.Add(r);
                        }
                        grvModule.DataSource          = null;
                        grvModule.AutoGenerateColumns = false;
                        grvModule.DataSource          = _dtModule;
                    }
                }
            }
        }
예제 #26
0
        private void btnTestGridBackground_Click(object sender, EventArgs e)
        {
            frmBackgroundGrid frm = new frmBackgroundGrid();

            TextUtils.OpenForm(frm);
        }
예제 #27
0
        void loadChildModule(string moduleCode, int parentID)
        {
            DocUtils.InitFTPQLSX();
            string _serverPathCK = string.Format("Thietke.Ck/{0}/{1}.Ck/VT.{1}.xlsm", moduleCode.Substring(0, 6), moduleCode);
            string localPath     = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            if (DocUtils.CheckExits(_serverPathCK))
            {
                DocUtils.DownloadFile(localPath, "VT." + moduleCode + ".xlsm", _serverPathCK);
            }
            else
            {
                return;
            }
            DataTable dtDMVT = TextUtils.ExcelToDatatable(localPath + "/VT." + moduleCode + ".xlsm", "DMVT");

            if (File.Exists(localPath + "/VT." + moduleCode + ".xlsm"))
            {
                File.Delete(localPath + "/VT." + moduleCode + ".xlsm");
            }
            DataRow[] drs = dtDMVT.Select("F4 like 'TPAD%' and len(F4) = 10");
            if (drs.Length > 0)
            {
                for (int i = 0; i < drs.Length; i++)
                {
                    string  stt = TextUtils.ToString(drs[i]["F1"]);
                    decimal qty = TextUtils.ToDecimal(drs[i]["F7"]);

                    if (stt.Contains("."))
                    {
                        string[]  arr       = stt.Split('.');
                        string    parentSTT = arr[0];
                        DataRow[] drs0      = dtDMVT.Select("F1 ='" + parentSTT + "'");
                        if (drs0.Length > 0)
                        {
                            qty *= TextUtils.ToDecimal(drs0[0]["F7"]);
                        }
                        for (int j = 1; j < arr.Length - 1; j++)
                        {
                            parentSTT += "." + TextUtils.ToString(arr[i]);
                            DataRow[] drsC = dtDMVT.Select("F1 ='" + parentSTT + "'");
                            if (drsC.Length > 0)
                            {
                                qty *= TextUtils.ToDecimal(drsC[0]["F7"]);
                            }
                        }
                    }

                    string code = TextUtils.ToString(drs[i]["F4"]);
                    string name = "";

                    DataTable dt = LibQLSX.Select("select FolderName from SourceCode with(nolock) where FolderCode = '" + code + "'");
                    if (dt.Rows.Count > 0)
                    {
                        name = TextUtils.ToString(dt.Rows[0]["FolderName"]);
                    }
                    else
                    {
                        name = TextUtils.ToString(drs[i]["F2"]);
                    }
                    _count++;
                    DataRow dr = _dtModule.NewRow();
                    dr["F3"]       = name;
                    dr["F5"]       = code;
                    dr["F7"]       = qty;
                    dr["ID"]       = _count;
                    dr["ParentID"] = parentID;

                    _dtModule.Rows.Add(dr);
                    loadChildModule(code, _count);
                }
            }
        }
예제 #28
0
        private void btnErrorExcel_Click(object sender, EventArgs e)
        {
            frmErrorExcel frm = new frmErrorExcel();

            TextUtils.OpenForm(frm);
        }
예제 #29
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (grvData.RowCount == 0)
            {
                return;
            }
            string localPath = "";

            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                localPath = fbd.SelectedPath + "\\BaoCaoDuAn.xlsx";
            }
            else
            {
                return;
            }

            string filePath = Application.StartupPath + "\\Templates\\PhongDuAn\\BAO CAO DU AN.xlsx";

            try
            {
                File.Copy(filePath, localPath, true);
            }
            catch
            {
                MessageBox.Show("Lỗi: File excel đang được mở.");
                return;
            }

            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo biểu mẫu..."))
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
                Excel.Application app       = default(Excel.Application);
                Excel.Workbook    workBoook = default(Excel.Workbook);
                Excel.Worksheet   workSheet = default(Excel.Worksheet);
                try
                {
                    app = new Excel.Application();
                    app.Workbooks.Open(localPath);
                    workBoook = app.Workbooks[1];
                    workSheet = (Excel.Worksheet)workBoook.Worksheets[1];

                    for (int i = grvData.RowCount - 1; i >= 0; i--)
                    {
                        workSheet.Cells[4, 1] = i + 1;
                        workSheet.Cells[4, 2] = TextUtils.ToString(grvData.GetRowCellValue(i, colProjectCode));
                        workSheet.Cells[4, 3] = TextUtils.ToString(grvData.GetRowCellValue(i, colNguoiPhuTrach));
                        workSheet.Cells[4, 4] = TextUtils.ToString(grvData.GetRowCellValue(i, colTonDong));
                        workSheet.Cells[4, 5] = TextUtils.ToString(grvData.GetRowCellValue(i, colTinhTrang));
                        workSheet.Cells[4, 6] = "";
                        workSheet.Cells[4, 6] = "";

                        ((Excel.Range)workSheet.Rows[4]).Insert();
                    }

                    ((Excel.Range)workSheet.Rows[3]).Delete();
                    ((Excel.Range)workSheet.Rows[3]).Delete();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (app != null)
                    {
                        app.ActiveWorkbook.Save();
                        app.Workbooks.Close();
                        app.Quit();
                    }
                }
            }

            Process.Start(localPath);
        }
예제 #30
0
        private void btnForm1_Click(object sender, EventArgs e)
        {
            Form1 frm = new Form1();

            TextUtils.OpenForm(frm);
        }